Struct NativeSpline
A read-only representation of Spline that is optimized for efficient access and queries. NativeSpline can be constructed with a spline and Transform. If a transform is applied, all values will be relative to the transformed knot positions.
Implements
Inherited Members
Namespace: UnityEngine.Splines
Assembly: Unity.Splines.dll
Syntax
public struct NativeSpline : ISpline, IReadOnlyList<BezierKnot>, IReadOnlyCollection<BezierKnot>, IEnumerable<BezierKnot>, IEnumerable, IDisposable
Remarks
NativeSpline is compatible with the job system.
Constructors
NativeSpline(IReadOnlyList<BezierKnot>, bool, float4x4, bool, Allocator)
Create a new NativeSpline from a set of BezierKnot.
Declaration
public NativeSpline(IReadOnlyList<BezierKnot> knots, bool closed, float4x4 transform, bool cacheUpVectors, Allocator allocator = Allocator.Temp)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<BezierKnot> | knots | A collection of sequential BezierKnot forming the spline path. |
bool | closed | Whether the spline is open (has a start and end point) or closed (forms an unbroken loop). |
float4x4 | transform | Apply a transformation matrix to the control Knots. |
bool | cacheUpVectors | Whether to cache the values of the Up vectors along the entire spline to reduce the time it takes to access those Up vectors. If you set this to true, the creation of native splines might be less performant because all the Up vectors along the spline are computed. Consider how often you need to access the values of Up vectors along the spline before you cache them. |
Allocator | allocator | The memory allocation method to use when reserving space for native arrays. |
NativeSpline(IReadOnlyList<BezierKnot>, bool, float4x4, Allocator)
Create a new NativeSpline from a set of BezierKnot.
Declaration
public NativeSpline(IReadOnlyList<BezierKnot> knots, bool closed, float4x4 transform, Allocator allocator = Allocator.Temp)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<BezierKnot> | knots | A collection of sequential BezierKnot forming the spline path. |
bool | closed | Whether the spline is open (has a start and end point) or closed (forms an unbroken loop). |
float4x4 | transform | Apply a transformation matrix to the control Knots. |
Allocator | allocator | The memory allocation method to use when reserving space for native arrays. |
NativeSpline(IReadOnlyList<BezierKnot>, IReadOnlyList<int>, bool, float4x4, bool, Allocator)
Create a new NativeSpline from a set of BezierKnot.
Declaration
public NativeSpline(IReadOnlyList<BezierKnot> knots, IReadOnlyList<int> splits, bool closed, float4x4 transform, bool cacheUpVectors, Allocator allocator = Allocator.Temp)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<BezierKnot> | knots | A collection of sequential BezierKnot forming the spline path. |
IReadOnlyList<int> | splits | A collection of knot indices that should be considered degenerate curves for the purpose of creating a non-interpolated gap between curves. |
bool | closed | Whether the spline is open (has a start and end point) or closed (forms an unbroken loop). |
float4x4 | transform | Apply a transformation matrix to the control Knots. |
bool | cacheUpVectors | Whether to cache the values of the Up vectors along the entire spline to reduce the time it takes to access those Up vectors. If you set this to true, the creation of native splines might be less performant because all the Up vectors along the spline are computed. Consider how often you need to access the values of Up vectors along the spline before you cache them. |
Allocator | allocator | The memory allocation method to use when reserving space for native arrays. |
NativeSpline(IReadOnlyList<BezierKnot>, IReadOnlyList<int>, bool, float4x4, Allocator)
Create a new NativeSpline from a set of BezierKnot.
Declaration
public NativeSpline(IReadOnlyList<BezierKnot> knots, IReadOnlyList<int> splits, bool closed, float4x4 transform, Allocator allocator = Allocator.Temp)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<BezierKnot> | knots | A collection of sequential BezierKnot forming the spline path. |
IReadOnlyList<int> | splits | A collection of knot indices that should be considered degenerate curves for the purpose of creating a non-interpolated gap between curves. |
bool | closed | Whether the spline is open (has a start and end point) or closed (forms an unbroken loop). |
float4x4 | transform | Apply a transformation matrix to the control Knots. |
Allocator | allocator | The memory allocation method to use when reserving space for native arrays. |
NativeSpline(ISpline, bool, Allocator)
Create a new NativeSpline from a set of BezierKnot.
Declaration
public NativeSpline(ISpline spline, bool cacheUpVectors, Allocator allocator = Allocator.Temp)
Parameters
Type | Name | Description |
---|---|---|
ISpline | spline | The ISpline object to convert to a NativeSpline. |
bool | cacheUpVectors | Whether to cache the values of the Up vectors along the entire spline to reduce the time it takes to access those Up vectors. If you set this to true, the creation of native splines might be less performant because all the Up vectors along the spline are computed. Consider how often you need to access the values of Up vectors along the spline before you cache them. |
Allocator | allocator | The memory allocation method to use when reserving space for native arrays. |
NativeSpline(ISpline, Allocator)
Create a new NativeSpline from a set of BezierKnot.
Declaration
public NativeSpline(ISpline spline, Allocator allocator = Allocator.Temp)
Parameters
Type | Name | Description |
---|---|---|
ISpline | spline | The ISpline object to convert to a NativeSpline. |
Allocator | allocator | The memory allocation method to use when reserving space for native arrays. |
NativeSpline(ISpline, float4x4, bool, Allocator)
Create a new NativeSpline from a set of BezierKnot.
Declaration
public NativeSpline(ISpline spline, float4x4 transform, bool cacheUpVectors, Allocator allocator = Allocator.Temp)
Parameters
Type | Name | Description |
---|---|---|
ISpline | spline | The ISpline object to convert to a NativeSpline. |
float4x4 | transform | A transform matrix to be applied to the spline knots and tangents. |
bool | cacheUpVectors | Whether to cache the values of the Up vectors along the entire spline to reduce the time it takes to access those Up vectors. If you set this to true, the creation of native splines might be less performant because all the Up vectors along the spline are computed. Consider how often you need to access the values of Up vectors along the spline before you cache them. |
Allocator | allocator | The memory allocation method to use when reserving space for native arrays. |
NativeSpline(ISpline, float4x4, Allocator)
Create a new NativeSpline from a set of BezierKnot.
Declaration
public NativeSpline(ISpline spline, float4x4 transform, Allocator allocator = Allocator.Temp)
Parameters
Type | Name | Description |
---|---|---|
ISpline | spline | The ISpline object to convert to a NativeSpline. |
float4x4 | transform | A transform matrix to be applied to the spline knots and tangents. |
Allocator | allocator | The memory allocation method to use when reserving space for native arrays. |
Properties
Closed
Whether the spline is open (has a start and end point) or closed (forms an unbroken loop).
Declaration
public bool Closed { get; }
Property Value
Type | Description |
---|---|
bool |
Count
Return the number of knots.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
Curves
A NativeArray of BezierCurve that form this Spline.
Declaration
public NativeArray<BezierCurve> Curves { get; }
Property Value
Type | Description |
---|---|
NativeArray<BezierCurve> | Returns a reference to the curves array. |
this[int]
Get the knot at index
.
Declaration
public BezierKnot this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
int | index | The zero-based index of the knot. |
Property Value
Type | Description |
---|---|
BezierKnot |
Knots
A NativeArray of BezierKnot that form this Spline.
Declaration
public NativeArray<BezierKnot> Knots { get; }
Property Value
Type | Description |
---|---|
NativeArray<BezierKnot> | Returns a reference to the knots array. |
Methods
Dispose()
Release allocated resources.
Declaration
public void Dispose()
GetCurve(int)
Get a BezierCurve from a knot index.
Declaration
public BezierCurve GetCurve(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The knot index that serves as the first control point for this curve. |
Returns
Type | Description |
---|---|
BezierCurve | A BezierCurve formed by the knot at index and the next knot. |
GetCurveInterpolation(int, float)
Return the normalized interpolation (t) corresponding to a distance on a BezierCurve.
Declaration
public float GetCurveInterpolation(int curveIndex, float curveDistance)
Parameters
Type | Name | Description |
---|---|---|
int | curveIndex | The zero-based index of the curve. |
float | curveDistance | The curve-relative distance to convert to an interpolation ratio (also referred to as 't'). |
Returns
Type | Description |
---|---|
float | The normalized interpolation ratio associated to distance on the designated curve. |
GetCurveLength(int)
Get the length of a BezierCurve.
Declaration
public float GetCurveLength(int curveIndex)
Parameters
Type | Name | Description |
---|---|---|
int | curveIndex | The 0 based index of the curve to find length for. |
Returns
Type | Description |
---|---|
float | The length of the bezier curve at index. |
GetCurveUpVector(int, float)
Return the up vector for a t ratio on the curve.
Declaration
public float3 GetCurveUpVector(int index, float t)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the curve for which the length needs to be retrieved. |
float | t | A value between 0 and 1 representing the ratio along the spline. |
Returns
Type | Description |
---|---|
float3 | Returns the up vector at the t ratio of the curve of index 'index'. |
GetEnumerator()
Get an enumerator that iterates through the BezierKnot collection.
Declaration
public IEnumerator<BezierKnot> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<BezierKnot> | An IEnumerator that is used to iterate the BezierKnot collection. |
GetLength()
Return the sum of all curve lengths, accounting for Closed state. Note that this value is affected by the transform used to create this NativeSpline.
Declaration
public float GetLength()
Returns
Type | Description |
---|---|
float | Returns the sum length of all curves composing this spline, accounting for closed state. |