Skip to main content

BezierSpline

A class in Root.Township, Alta.Bezier.

A cubic Bezier spline component: control points in groups of three per curve, with free, aligned or mirrored handles and optional looping. Used by spline displays, terrain splines, forest spline instructions and some effects.

Constructors​

MemberWhat it is
BezierSpline()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
SplineChangedHandler ChangedCalled whenever the spline changes.
3 private and internal fields
MemberWhat it is
private bool isLoopingBacking field for IsLooping.
private BezierControlPointMode[] modesHandle mode per curve joint (free, aligned, mirrored), one more entry than there are curves.
private Vector3[] pointsLocal-space control points: each curve uses four, sharing its end point with the next curve.

Properties​

MemberWhat it is
int ControlPointCount { get; }Number of control points.
int CurveCount { get; }Number of curves (control points minus one, over three).
bool IsLooping { get; set; }Whether the spline closes on itself. Turning it on joins the last point to the first.

Methods​

MemberWhat it is
void AddCurve()Adds one more curve to the end, one unit apart along X, and keeps the loop closed if looping.
void AddDisplay(GameObject display)Instantiates a display prefab under the spline and generates every SplineDisplay in it.
static BezierSpline Create(params Vector3[] points)Creates a game object with a spline from the given points. Handle modes aren't set, so editing may fail until Reset (probably).
Vector3 GetControlPoint(int index)A control point in local space.
BezierControlPointMode GetControlPointMode(int index)Handle mode for the control point's joint; free if unset.
Vector3 GetDirection(float t)Normalized world-space direction at t (0 to 1 along the whole spline).
Vector3 GetPoint(float t)World-space point at t (0 to 1 along the whole spline).
Vector3 GetPointLocal(int curve, float t)Local-space point at t along the whole spline, or at t on one curve.
Vector3 GetPointLocal(float t)Local-space point at t along the whole spline, or at t on one curve.
Vector3 GetVelocity(float t)World-space derivative at t along the whole spline.
void Insert(int index)Inserts a new curve at a joint index.
void Refresh()Raises Changed.
void Reset()Resets to one straight curve along X.
void SetControlPoint(int index, Vector3 point)Moves a control point; moving a joint also moves its handles, and the handle mode is enforced.
void SetControlPointMode(int index, BezierControlPointMode mode)Sets the handle mode of a joint and enforces it.
3 private and internal methods
MemberWhat it is
private void EnforceMode(int index)Moves the opposite handle of a control point so it matches the point's mode (mirrored or aligned). Free points are left alone.
private void OnChanged()Raises Changed. Called after any edit to points, modes or looping.
private void Alta.Static.IInstructionResult.Undo()Explicit IInstructionResult implementation: destroys the spline's GameObject.

Used in​

Members of other types that take, return or hold a BezierSpline: