Unity Spline Editor
An editor tool to create splines in Unity
Public Member Functions | Public Attributes | Properties | List of all members
Spline Class Reference

This class contains the list of points that make up the spline. Lets you create, get and move those points. More...

Public Member Functions

 Spline (Vector3 anchorPtPosition, Transform t=null)
 Initializes the point list with two points in a horizontal line. More...
 
Vector3 GetPointAt (int index, PointType type, Transform parentTransform=null)
 Gets the position of an anchor or control point at a certain index. If a transform is passed, it converts the position into the local space of that transform More...
 
CurvePoint GetPointsAt (int index)
 
void AddPoint (Vector3 anchorPtPosition)
 Add points matching previous anchor point's right handle direction. If we're adding the first point, add control points in a vertial line. More...
 
void RemovePoint (int pointindex)
 Removes anchor point at certain index from list with its control points More...
 
void AddPointToEnd ()
 Add a point to the end of the spline based on the previous point's right handle position. More...
 
void InsertPoint (int index)
 Inserts a point after the active point. Grabs the right control point of the previous point and the left one from the next point and puts the new anchor in the middle, with the control points pointing at these. More...
 
void SetPointPosition (int pointIndex, PointType pointType, Vector3 newPositiion)
 Change position of a certain point.When moving points, it makes sure that control points move with the anchor point and that they always form a tangent More...
 
Vector3 GetPositionForTime (float time, Transform parentTransform)
 Calculate the segment we're at and the position for the provided time. More...
 
Vector3 GetFirstDerivative (Vector3 firstAnchor, Vector3 rightControl, Vector3 leftControl, Vector3 secondAnchor, float t)
 Get first derivative of the points of a segment to get tangent at a certain point in time More...
 
Vector3 GetVelocityForTime (float time, Transform parentTransform)
 Calculate segment we're at and get tangent for the provided time More...
 
Vector3 GetDirectionForTime (float time, Transform parentTransform)
 Normalize the velocity vector to get a direction More...
 

Public Attributes

bool isLooping = false
 

Properties

int TotalSegments [get]
 
int TotalPoints [get]
 

Detailed Description

This class contains the list of points that make up the spline. Lets you create, get and move those points.

Constructor & Destructor Documentation

◆ Spline()

Spline.Spline ( Vector3  anchorPtPosition,
Transform  t = null 
)

Initializes the point list with two points in a horizontal line.

Parameters
anchorPtPositionThe position to create the first point in.

Member Function Documentation

◆ AddPoint()

void Spline.AddPoint ( Vector3  anchorPtPosition)

Add points matching previous anchor point's right handle direction. If we're adding the first point, add control points in a vertial line.

Parameters
anchorPtPositionPosition where the anchor point will be added

◆ AddPointToEnd()

void Spline.AddPointToEnd ( )

Add a point to the end of the spline based on the previous point's right handle position.

◆ GetDirectionForTime()

Vector3 Spline.GetDirectionForTime ( float  time,
Transform  parentTransform 
)

Normalize the velocity vector to get a direction

Parameters
timeTime for which to get the direction
parentTransformConvert to this transform's local space
Returns

◆ GetFirstDerivative()

Vector3 Spline.GetFirstDerivative ( Vector3  firstAnchor,
Vector3  rightControl,
Vector3  leftControl,
Vector3  secondAnchor,
float  t 
)

Get first derivative of the points of a segment to get tangent at a certain point in time

Parameters
firstAnchorFirst anchor of segment
rightControlRight Control Point of First Anchor
leftControlLeft Control Point of Second Anchor
secondAnchorSecond anchor of segment
t
Returns

◆ GetPointAt()

Vector3 Spline.GetPointAt ( int  index,
PointType  type,
Transform  parentTransform = null 
)

Gets the position of an anchor or control point at a certain index. If a transform is passed, it converts the position into the local space of that transform

Parameters
indexIndex of the point to fetch
typeWether it is an anchor, left control point or right control point
Returns

◆ GetPositionForTime()

Vector3 Spline.GetPositionForTime ( float  time,
Transform  parentTransform 
)

Calculate the segment we're at and the position for the provided time.

Parameters
timePoint in time we want to get the position at [0-1]
parentTransformConvert to this transform's local space
Returns

◆ GetVelocityForTime()

Vector3 Spline.GetVelocityForTime ( float  time,
Transform  parentTransform 
)

Calculate segment we're at and get tangent for the provided time

Parameters
timeTime for which to get the velocity [0-1]
parentTransformConvert to this transform's local space
Returns

◆ InsertPoint()

void Spline.InsertPoint ( int  index)

Inserts a point after the active point. Grabs the right control point of the previous point and the left one from the next point and puts the new anchor in the middle, with the control points pointing at these.

Parameters
indexIndex where to insert the new point after

◆ RemovePoint()

void Spline.RemovePoint ( int  pointindex)

Removes anchor point at certain index from list with its control points

Parameters
pointindexIndex of point to remove.

◆ SetPointPosition()

void Spline.SetPointPosition ( int  pointIndex,
PointType  pointType,
Vector3  newPositiion 
)

Change position of a certain point.When moving points, it makes sure that control points move with the anchor point and that they always form a tangent

  • Anchor Point: Move control points with it
  • Control Points: Move the other control point in the same direction as the one you're moving while keeping the distance.
Parameters
pointIndexIndex of the point to move.
pointTypeAnchor, Control Left or Control Right.
newPositiionTarget Position of the point.

The documentation for this class was generated from the following file: