From 0861de5f5db3dbe18815675ce01cc8bd18f2f5e2 Mon Sep 17 00:00:00 2001 From: Sebastian Lague Date: Fri, 1 Feb 2019 18:22:03 +0200 Subject: [PATCH] Fixed normals angle of inserted point --- PathCreator/Core/Scripts/Objects/BezierPath.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/PathCreator/Core/Scripts/Objects/BezierPath.cs b/PathCreator/Core/Scripts/Objects/BezierPath.cs index 67f62ce..76dc21c 100644 --- a/PathCreator/Core/Scripts/Objects/BezierPath.cs +++ b/PathCreator/Core/Scripts/Objects/BezierPath.cs @@ -358,7 +358,7 @@ public void AddSegmentToStart(Vector3 anchorPos) /// Insert new anchor point at given position. Automatically place control points around it so as to keep shape of curve the same public void SplitSegment(Vector3 anchorPos, int segmentIndex, float splitTime) { - + splitTime = Mathf.Clamp01(splitTime); anchorPos -= localPosition; if (controlMode == ControlMode.Automatic) @@ -388,9 +388,11 @@ public void SplitSegment(Vector3 anchorPos, int segmentIndex, float splitTime) // Insert angle for new anchor (value should be set inbetween neighbour anchor angles) int newAnchorAngleIndex = segmentIndex + 1; int numAngles = perAnchorNormalsAngle.Count; - float anglePrev = (newAnchorAngleIndex > 0 || isClosed) ? perAnchorNormalsAngle[(newAnchorAngleIndex - 1 + numAngles) % numAngles] : 0; - float angleNext = (newAnchorAngleIndex < numAngles || isClosed) ? perAnchorNormalsAngle[(newAnchorAngleIndex + 1) % numAngles] : 0; - perAnchorNormalsAngle.Insert(newAnchorAngleIndex, (anglePrev + angleNext) / 2f); + + float anglePrev = perAnchorNormalsAngle[(newAnchorAngleIndex - 1)]; + float angleNext = perAnchorNormalsAngle[newAnchorAngleIndex]; + float splitAngle = Mathf.LerpAngle(anglePrev,angleNext,splitTime); + perAnchorNormalsAngle.Insert(newAnchorAngleIndex, splitAngle); NotifyPathModified(); }