Assets/SplineTool/Scripts/CorgiSpline/Spline.cs
/// <summary>
/// Inserts a new point into the spline, between the two points found from projecting the world positon on the sl
/// </summary>
/// <param name="placingPoint"></param>
Inserts a new point into the spline, between the two points found from projecting the world positon on the sl
Inserts a new point into the spline between the two points found from projecting the world positon on the sl
public void InsertPoint(SplinePoint placingPoint)
        {
            var t = ProjectOnSpline_t(placingPoint.position); 
            var pointIndex = GetPointIndexFromTime(t);
            var newPoint = GetPoint(t);
            var forward = GetForward(t);
            if (SplineSpace == Space.Self)
            {
                newPoint = InverseTransformSplinePoint(newPoint);
                forward = transform.InverseTransformDirection(forward);
            }
            if (t > 0f && t < 1f)
            {
                var pointList = Points.ToList();
                if (Mode == SplineMode.Linear)
                {
                    pointList.Insert(pointIndex + 1, newPoint);
                }
                else if (Mode == SplineMode.Bezier)
                {
                    var point_start = pointList[pointIndex + 0];
                    var point_end = pointList[pointIndex + 3];
                    var distance0 = Vector3.Distance(point_start.position, newPoint.position);
                    var distance1 = Vector3.Distance(point_end.position, newPoint.position);
                    var point_distance = Mathf.Min(distance0, distance1);
                    var handle0 = newPoint;
                    var handle1 = newPoint;
                    handle0.position -= forward * point_distance * 0.25f;
                    handle1.position += forward * point_distance * 0.25f;
                    pointList.Insert(pointIndex + 2 + 0, handle0);
                    pointList.Insert(pointIndex + 2 + 1, newPoint);
                    pointList.Insert(pointIndex + 2 + 2, handle1);
                }
                else if (Mode == SplineMode.BSpline)
                {
                    pointList.Insert(pointIndex + 1, newPoint);
                }
                else
                {
                }
                Points = pointList.ToArray();
            }
        }
public void InsertPoint ( SplinePoint placingPoint ) { var t = ProjectOnSpline_t ( placingPoint . position ) ; var pointIndex = GetPointIndexFromTime ( t ) ; var newPoint = GetPoint ( t ) ; var forward = GetForward ( t ) ; if ( SplineSpace == Space . Self ) { newPoint = InverseTransformSplinePoint ( newPoint ) ; forward = transform . InverseTransformDirection ( forward ) ; } if ( t > 0f && t < 1f ) { var pointList = Points . ToList ( ) ; if ( Mode == SplineMode . Linear ) { pointList . Insert ( pointIndex + 1 , newPoint ) ; } else if ( Mode == SplineMode . Bezier ) { var point_start = pointList [ pointIndex + 0 ] ; var point_end = pointList [ pointIndex + 3 ] ; var distance0 = Vector3 . Distance ( point_start . position , newPoint . position ) ; var distance1 = Vector3 . Distance ( point_end . position , newPoint . position ) ; var point_distance = Mathf . Min ( distance0 , distance1 ) ; var handle0 = newPoint ; var handle1 = newPoint ; handle0 . position -= forward * point_distance * 0.25f ; handle1 . position += forward * point_distance * 0.25f ; pointList . Insert ( pointIndex + 2 + 0 , handle0 ) ; pointList . Insert ( pointIndex + 2 + 1 , newPoint ) ; pointList . Insert ( pointIndex + 2 + 2 , handle1 ) ; } else if ( Mode == SplineMode . BSpline ) { pointList . Insert ( pointIndex + 1 , newPoint ) ; } else { } Points = pointList . ToArray ( ) ; } }
Inserts a new point into the spline, between the two points found from projecting the world positon on the sl
Inserts a new point into the spline between the two points found from projecting the world positon on the sl
// resolves space internally  // don't insert point before or after the spline (MUST be a true insert)  // inserts after a single handle, so we can slot a point with two surrounding handles  // not implemented?  // update original array with list 
placingPoint
SplinePoint
None