Skip to content

Commit

Permalink
Fixed normals angle of inserted point
Browse files Browse the repository at this point in the history
  • Loading branch information
SebLague committed Feb 1, 2019
1 parent 5bcac95 commit 0861de5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions PathCreator/Core/Scripts/Objects/BezierPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 0861de5

Please sign in to comment.