You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/README.md
+32-8Lines changed: 32 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ There are 5 ways to install this plugin:
28
28
29
29
## CREATING & EDITING A NEW SPLINE IN EDITOR
30
30
31
-
To create a new spline in the editor, follow "GameObject - Bezier Spline".
31
+
To create a new spline in the editor, click **GameObject - Bezier Spline**.
32
32
33
33
Now you can select the end points of the spline in the Scene view and translate/rotate/scale or delete/duplicate them as you wish (each end point has 2 control points, which can also be translated):
34
34
@@ -42,10 +42,20 @@ The user interface for the spline editor should be pretty self-explanatory. Howe
42
42
43
43
**Draw Runtime Gizmos:** draws the spline during gameplay
44
44
45
+
**Show Control Points:** sets whether or not the control points of the end points will be drawn in Scene window
46
+
47
+
**Show Normals:** sets whether or not the end points' normals will be drawn in Scene window
48
+
49
+
**Auto Calculated Normals Angle:** when *Auto Calculate Normals* button is clicked, all normals will be rotated around their Z axis by the specified amount (each end point's rotation angle can further be customized from the end point's Inspector)
50
+
45
51
**Construct Linear Path:** constructs a completely linear path between the end points by using *Free* handle mode and adjusting the control points of end points (see *Convert spline to a linear path* section below). Enabling the **Always** option will apply this technique to the spline whenever its end points change (Editor-only)
46
52
47
53
**Auto Construct Spline:** auto adjusts the control points of end points to form a smooth spline that goes through the end points you set. There are 2 different implementations for it, with each giving a slightly different output (see *Auto construct the spline* section below)
48
54
55
+
**Auto Calculate Normals:** attempts to automatically calculate the end points' normal vectors
56
+
57
+
**Insert Point At Cursor:** quickly inserts new end points to the clicked sections of the spline
58
+
49
59
**Handle Mode:** control points of end points are handled in one of 3 ways: Free mode allows moving control points independently, Mirrored mode places the control points opposite to each other and Aligned mode ensures that both control points are aligned on a line that passes through the end point (unlike Mirrored mode, their distance to end point may differ)
50
60
51
61
**Extra Data:** end points can store additional data that can hold 4 floats. You can interpolate between points' extra data by code (see *UTILITY FUNCTIONS* section below). This extra data is especially useful for moving a camera on a bezier spline while setting different camera rotations at each end point (the BezierWalker components can read that data). You can click the **C** button to store the Scene camera's current rotation in this extra data. Then, you can visualize this data by clicking the **V** button
@@ -71,15 +81,15 @@ spline.Initialize( 2 );
71
81
72
82
`void SwapPointsAt( int index1, int index2 )`: swaps indices of two end points
73
83
74
-
`void MovePoint( int previousIndex, int newIndex )`: changes an end point's index
84
+
`void ChangePointIndex( int previousIndex, int newIndex )`: changes an end point's index
75
85
76
86
`int IndexOf( BezierPoint point )`: returns the index of an end point
77
87
78
88
-**Shape the spline**
79
89
80
-
You can change the position, rotationand scale values of end points and the positions of their control points to reshape the spline.
90
+
You can change the position, rotation, scale and normal values of the end points, as well as the positions of their control points to reshape the spline.
81
91
82
-
End points have the following properties to store their transformational data: `position`, `localPosition`, `rotation`, `localRotation`, `eulerAngles`, `localEulerAngles`and `localScale`.
92
+
End points have the following properties to store their transformational data: `position`, `localPosition`, `rotation`, `localRotation`, `eulerAngles`, `localEulerAngles`, `localScale`, `normal`and `autoCalculatedNormalAngleOffset`.
83
93
84
94
Positions of control points can be tweaked using the following properties in BezierPoint: `precedingControlPointPosition`, `precedingControlPointLocalPosition`, `followingControlPointPosition` and `followingControlPointLocalPosition`. The local positions are relative to their corresponding end points.
If you don't want to position all the control points manually, but rather generate a nice-looking "continuous" spline that goes through the end points you have created, you can call either **AutoConstructSpline()** or **AutoConstructSpline2()**. These methods are implementations of some algorithms found on the internet (and credited in the source code). There is a third algorithm (*AutoConstructSpline3()*) which is not implemented, but feel free to implement it yourself!
113
+
If you don't want to position all the control points manually, but rather generate a nice-looking "continuous" spline that goes through the end points you have created, you can call either **AutoConstructSpline()** or **AutoConstructSpline2()**. These methods are implementations of some algorithms found on the internet (and credited in the source code).
104
114
105
115

106
116
@@ -110,6 +120,12 @@ If you want to create a linear path between the end points of the spline, you ca
110
120
111
121

112
122
123
+
-**Auto calculate the normals**
124
+
125
+
If you want to calculate the spline's normal vectors automatically, you can call the **AutoCalculateNormals( float normalAngle = 0f, int smoothness = 10 )** function. All resulting normal vectors will be rotated around their Z axis by "normalAngle" degrees. Additionally, each end point's normal vector will be rotated by that end point's "autoCalculatedNormalAngleOffset" degrees. "smoothness" determines how many intermediate steps are taken between each consecutive end point to calculate those end points' normal vectors. More intermediate steps is better but also slower to calculate.
126
+
127
+
If auto calculated normals don't look quite right despite modifying the "normalAngle" (*Auto Calculated Normals Angle* in the Inspector) and "autoCalculatedNormalAngleOffset" (*Normal Angle* in the Inspector) variables, you can either consider inserting new end points to the sections of the spline that normals don't behave correctly, or setting the normals manually.
128
+
113
129
## UTILITY FUNCTIONS
114
130
115
131
The framework comes with some utility functions. These functions are not necessarily perfect but most of the time, they get the job done. Though, if you want, you can use this framework to just create splines and then apply your own logic to them.
@@ -122,6 +138,10 @@ A spline is essentially a mathematical formula with a \[0,1\] clamped input (usu
122
138
123
139
Tangent is calculated using the first derivative of the spline formula and gives the direction of the movement at a given point on the spline. Can be used to determine which direction an object on the spline should look at at a given point.
124
140
141
+
-`Vector3 GetNormal( float normalizedT )`
142
+
143
+
Interpolates between the end points' normal vectors. Note that this plugin doesn't store any intermediate data between end point pairs, so if two consecutive end points have almost the opposite tangents, then their interpolated normal vector may not be correct at some parts of the spline. Inserting a new end point between these two end points could resolve this issue. By default, all normal vectors have value (0,1,0).
Interpolates between the extra data provided at each end point. This data has 4 float components and can implicitly be converted to Vector2, Vector3, Vector4, Quaternion, Rect, Vector2Int, Vector3Int and RectInt.
@@ -138,25 +158,29 @@ Calculates the approximate length of a segment of the spline. To calculate the l
Returns the indices of the two end points that are closest to *normalizedT*. The *PointIndexTuple* struct also holds a *t* value in range \[0,1\], which can be used to interpolate between the properties of the two end points at these indices.
161
+
Returns the indices of the two end points that are closest to *normalizedT*. The *PointIndexTuple* struct also holds a *localT* value in range \[0,1\], which can be used to interpolate between the properties of the two end points at these indices. You can also call the `GetPoint()`, `GetTangent()`, `GetNormal()` and `GetExtraData()` functions of this struct and the returned values will be calculated as if the spline consisted of only these two end points.
Finds the nearest point on the spline to any given point in 3D space. The normalizedT parameter is optional and it returns the parameter *t* corresponding to the resulting point. To find the nearest point, the spline is divided into "accuracy" points and the nearest point is selected. Thus, the result will not be 100% accurate but will be good enough for casual use-cases.
146
166
167
+
-`Vector3 FindNearestPointToLine( Vector3 lineStart, Vector3 lineEnd, out Vector3 pointOnLine, out float normalizedT, float accuracy = 100f )`
168
+
169
+
Finds the nearest point on the spline to the given line in 3D space. The pointOnLine and normalizedT parameters are optional.
Moves a point (normalizedT) on the spline deltaMovement units ahead and returns the resulting point. The normalizedT parameter is passed by reference to keep track of the new *t* parameter.
150
174
151
175
## OTHER COMPONENTS
152
176
153
-
Framework comes with 3 additional components that may help you move objects or particles along splines. These components are located in the Utilities folder.
177
+
Framework comes with 4 additional components that may help you move objects or particles along splines. These components are located in the Utilities folder.
154
178
155
179
-**BezierWalkerWithSpeed**
156
180
157
181

158
182
159
-
Moves an object along a spline with constant speed. There are 3 travel modes: Once, Ping Pong and Loop. If *Look At* is Forward, the object will always face forwards. If it is SplineExtraData, the extra data stored in the spline's end points is used to determine the rotation. You can modify this extra data from the points' Inspector. The smoothness of the rotation can be adjusted via *Rotation Lerp Modifier*. *Normalized T* determines the starting point. Each time the object completes a lap, its *On Path Completed ()* event is invoked. To see this component in action without entering Play mode, click the *Simulate In Editor* button.
183
+
Moves an object along a spline with constant speed. There are 3 travel modes: Once, Ping Pong and Loop. If *Look At* is Forward, the object will always face forwards (end points' normal vectors will be used as up vectors). If it is SplineExtraData, the extra data stored in the spline's end points is used to determine the rotation. You can modify this extra data from the points' Inspector. The smoothness of the rotation can be adjusted via *Rotation Lerp Modifier*. *Normalized T* determines the starting point. Each time the object completes a lap, its *On Path Completed ()* event is invoked. To see this component in action without entering Play mode, click the *Simulate In Editor* button.
0 commit comments