Assets/SplineTool/Scripts/CorgiSpline/Spline.cs
/// <summary>
/// Adds a point to the Points array given this information. Input data is expected to be world space.
/// If the spline is a Bezier type, it will actually add 4 points internally, and handle the Handles placement for you.
/// </summary>
/// <param name="position"></param>
/// <param name="rotation"></param>
/// <param name="scale"></param>
Adds a point to the Points array given this information. Input data is expected to be world space.
If the spline is a Bezier type, it will actually add 4 points internally, and handle the Handles placement for you.
Adds a point to the Points array given this information . Input data is expected to be world space . If the spline is a Bezier type it will actually add 4 points internally and handle the Handles placement for you .
public void AppendPoint(Vector3 position, Quaternion rotation, Vector3 scale)
        {
            if (SplineSpace == Space.Self)
            {
                var worldToLocalMatrix = transform.worldToLocalMatrix;
                position = worldToLocalMatrix.MultiplyPoint(position);
                rotation = worldToLocalMatrix.rotation * rotation;
                scale = worldToLocalMatrix.MultiplyVector(scale);
            }
            switch(Mode)
            {
                case SplineMode.Linear:
                case SplineMode.BSpline:
                    ResizePointArray(Points.Length + 1);
                    var last_index = Points.Length - 1;
                    Points[last_index] = new SplinePoint(position, rotation, scale);
                    break;
                case SplineMode.Bezier:
                    if (Points.Length == 0)
                    {
                        ResizePointArray(Points.Length + 1);
                        Points[0] = new SplinePoint(position + Vector3.forward * 0, rotation, scale);
                    }
                    else if (Points.Length == 1)
                    {
                        ResizePointArray(Points.Length + 3);
                        var firstPointPos = Points[0].position;
                        var fromFirstPointPos = position - firstPointPos;
                        var distanceScale = 0.25f;
                        Points[1] = new SplinePoint(firstPointPos + fromFirstPointPos * distanceScale, rotation, scale);    
                        Points[2] = new SplinePoint(position - fromFirstPointPos * distanceScale, rotation, scale);         
                        Points[3] = new SplinePoint(position, rotation, scale);                                             
                    }
                    else
                    {
                        ResizePointArray(Points.Length + 3);
                        var index_prev_handle = Points.Length - 5;
                        var index_prev_point = Points.Length - 4;
                        var prev_handle = Points[index_prev_handle];
                        var prev_point = Points[index_prev_point];
                        var new_to_prev = position - prev_point.position;
                        var distanceScale = 0.25f;
                        prev_handle.position = prev_point.position - new_to_prev * distanceScale;
                        Points[index_prev_handle] = prev_handle;
                        Points[Points.Length - 3] = new SplinePoint(prev_point.position + new_to_prev * distanceScale, rotation, scale);    
                        Points[Points.Length - 2] = new SplinePoint(position - new_to_prev * distanceScale, rotation, scale);                
                        Points[Points.Length - 1] = new SplinePoint(position, rotation, scale);                                             
                    }
                    break; 
            }
        }
public void AppendPoint ( Vector3 position , Quaternion rotation , Vector3 scale ) { if ( SplineSpace == Space . Self ) { var worldToLocalMatrix = transform . worldToLocalMatrix ; position = worldToLocalMatrix . MultiplyPoint ( position ) ; rotation = worldToLocalMatrix . rotation * rotation ; scale = worldToLocalMatrix . MultiplyVector ( scale ) ; } switch ( Mode ) { case SplineMode . Linear : case SplineMode . BSpline : ResizePointArray ( Points . Length + 1 ) ; var last_index = Points . Length - 1 ; Points [ last_index ] = new SplinePoint ( position , rotation , scale ) ; break ; case SplineMode . Bezier : if ( Points . Length == 0 ) { ResizePointArray ( Points . Length + 1 ) ; Points [ 0 ] = new SplinePoint ( position + Vector3 . forward * 0 , rotation , scale ) ; } else if ( Points . Length == 1 ) { ResizePointArray ( Points . Length + 3 ) ; var firstPointPos = Points [ 0 ] . position ; var fromFirstPointPos = position - firstPointPos ; var distanceScale = 0.25f ; Points [ 1 ] = new SplinePoint ( firstPointPos + fromFirstPointPos * distanceScale , rotation , scale ) ; Points [ 2 ] = new SplinePoint ( position - fromFirstPointPos * distanceScale , rotation , scale ) ; Points [ 3 ] = new SplinePoint ( position , rotation , scale ) ; } else { ResizePointArray ( Points . Length + 3 ) ; var index_prev_handle = Points . Length - 5 ; var index_prev_point = Points . Length - 4 ; var prev_handle = Points [ index_prev_handle ] ; var prev_point = Points [ index_prev_point ] ; var new_to_prev = position - prev_point . position ; var distanceScale = 0.25f ; prev_handle . position = prev_point . position - new_to_prev * distanceScale ; Points [ index_prev_handle ] = prev_handle ; Points [ Points . Length - 3 ] = new SplinePoint ( prev_point . position + new_to_prev * distanceScale , rotation , scale ) ; Points [ Points . Length - 2 ] = new SplinePoint ( position - new_to_prev * distanceScale , rotation , scale ) ; Points [ Points . Length - 1 ] = new SplinePoint ( position , rotation , scale ) ; } break ; } }
Adds a point to the Points array given this information.
Adds a point to the Points array given this information .
// handle 1 // handle 2 // point  2 // update previous handle to mirror new handle // handle 1 // handle 2  // point 
position
Vector3
None
rotation
Quaternion
None
scale
Vector3
None