Class SplineUtility
A collection of methods for extracting information about Spline types.
Namespace: UnityEngine.Splines
Syntax
public static class SplineUtility
Fields
DrawResolutionDefault
The default resolution used when unrolling a curve to draw a preview in the Scene View.
Pick resolution is used when determining how many segments are required to unroll a curve. Unrolling is the process of calculating a series of line segments to approximate a curve. Some functions in SplineUtility allow you to specify a resolution. Lower resolution means fewer segments, while higher resolutions result in more segments. Use lower resolutions where performance is critical and accuracy is not paramount. Use higher resolution where a fine degree of accuracy is necessary and performance is less important.
Declaration
public const int DrawResolutionDefault = 10
Field Value
| Type | Description |
|---|---|
| Int32 |
PickResolutionDefault
The default resolution used when unrolling a curve to hit test while picking (selecting a spline with a cursor).
Pick resolution is used when determining how many segments are required to unroll a curve. Unrolling is the process of calculating a series of line segments to approximate a curve. Some functions in SplineUtility allow you to specify a resolution. Lower resolution means fewer segments, while higher resolutions result in more segments. Use lower resolutions where performance is critical and accuracy is not paramount. Use higher resolution where a fine degree of accuracy is necessary and performance is less important.
Declaration
public const int PickResolutionDefault = 4
Field Value
| Type | Description |
|---|---|
| Int32 |
PickResolutionMax
The maximum resolution allowed when unrolling a curve to hit test while picking (selecting a spline with a cursor).
Pick resolution is used when determining how many segments are required to unroll a curve. Unrolling is the process of calculating a series of line segments to approximate a curve. Some functions in SplineUtility allow you to specify a resolution. Lower resolution means fewer segments, while higher resolutions result in more segments. Use lower resolutions where performance is critical and accuracy is not paramount. Use higher resolution where a fine degree of accuracy is necessary and performance is less important.
Declaration
public const int PickResolutionMax = 64
Field Value
| Type | Description |
|---|---|
| Int32 |
PickResolutionMin
The minimum resolution allowable when unrolling a curve to hit test while picking (selecting a spline with a cursor).
Pick resolution is used when determining how many segments are required to unroll a curve. Unrolling is the process of calculating a series of line segments to approximate a curve. Some functions in SplineUtility allow you to specify a resolution. Lower resolution means fewer segments, while higher resolutions result in more segments. Use lower resolutions where performance is critical and accuracy is not paramount. Use higher resolution where a fine degree of accuracy is necessary and performance is less important.
Declaration
public const int PickResolutionMin = 2
Field Value
| Type | Description |
|---|---|
| Int32 |
Methods
CalculateLength(Spline, float4x4)
Calculate the length of a spline when transformed by a matrix.
Declaration
public static float CalculateLength(Spline spline, float4x4 transform)
Parameters
| Type | Name | Description |
|---|---|---|
| Spline | spline | |
| float4x4 | transform |
Returns
| Type | Description |
|---|---|
| Single |
CurveToSplineInterpolation<T>(T, Single)
Given an interpolation value for a curve, calculate the relative normalized spline interpolation.
Declaration
public static float CurveToSplineInterpolation<T>(T spline, float curve)
where T : ISpline
Parameters
| Type | Name | Description |
|---|---|---|
| T | spline | The target spline. |
| Single | curve | A curve index and normalized interpolation. The curve index is represented by the integer part of the float, and interpolation is the fractional part. This is the format used by Knot. |
Returns
| Type | Description |
|---|---|
| Single | An interpolation value relative to normalized Spline length (0 to 1). |
Type Parameters
| Name | Description |
|---|---|
| T |
See Also
EvaluateDirection<T>(T, Single)
Return an interpolated direction at ratio t.
Declaration
public static float3 EvaluateDirection<T>(this T spline, float t)
where T : ISpline
Parameters
| Type | Name | Description |
|---|---|---|
| T | spline | The spline to interpolate. |
| Single | t | A value between 0 and 1 representing the ratio along the curve. |
Returns
| Type | Description |
|---|---|
| float3 | A direction on the spline. |
Type Parameters
| Name | Description |
|---|---|
| T |
EvaluatePosition<T>(T, Single)
Return an interpolated position at ratio t.
Declaration
public static float3 EvaluatePosition<T>(this T spline, float t)
where T : ISpline
Parameters
| Type | Name | Description |
|---|---|---|
| T | spline | The spline to interpolate. |
| Single | t | A value between 0 and 1 representing the ratio along the curve. |
Returns
| Type | Description |
|---|---|
| float3 | A position on the spline. |
Type Parameters
| Name | Description |
|---|---|
| T |
EvaluateUpVector<T>(T, Single)
Evaluate an up vector of a spline at a specific t
Declaration
public static float3 EvaluateUpVector<T>(this T spline, float t)
where T : ISpline
Parameters
| Type | Name | Description |
|---|---|---|
| T | spline | The NativeSpline to evaluate. |
| Single | t | A value between 0 and 1 representing a percentage of the curve. |
Returns
| Type | Description |
|---|---|
| float3 | An up vector |
Type Parameters
| Name | Description |
|---|---|
| T |
GetBounds<T>(T)
Calculate the bounding box of a Spline.
Declaration
public static Bounds GetBounds<T>(T spline)
where T : ISpline
Parameters
| Type | Name | Description |
|---|---|---|
| T | spline | The spline for which to calculate bounds. |
Returns
| Type | Description |
|---|---|
| Bounds | The bounds of a spline. |
Type Parameters
| Name | Description |
|---|---|
| T | A type implementing ISpline. |
GetConvertedTime<T>(T, Single, PathIndexUnit, PathIndexUnit)
Given a time value using a certain PathIndexUnit type, calculate the associated time value in another targetPathUnit regarding a specific spline.
Declaration
public static float GetConvertedTime<T>(T spline, float time, PathIndexUnit originalTimeUnit, PathIndexUnit targetPathUnit)
where T : ISpline
Parameters
| Type | Name | Description |
|---|---|---|
| T | spline | The Spline to use for the conversion, this is necessary to compute Normalized and Distance PathIndexUnits. |
| Single | time | The splineData time in the original PathIndexUnit. |
| PathIndexUnit | originalTimeUnit | The PathIndexUnit from the original time. |
| PathIndexUnit | targetPathUnit | The PathIndexUnit in which time should be converted. |
Returns
| Type | Description |
|---|---|
| Single | The time converted in the targetPathUnit. |
Type Parameters
| Name | Description |
|---|---|
| T |
GetNearestPoint(NativeSpline, Ray, out float3, out Single, Int32, Int32)
Calculate the point on a spline nearest to a ray.
Declaration
public static float GetNearestPoint(NativeSpline spline, Ray ray, out float3 nearest, out float time, int resolution = 4, int iterations = 2)
Parameters
| Type | Name | Description |
|---|---|---|
| NativeSpline | spline | The input spline to search for nearest point. |
| Ray | ray | The input ray to search against. |
| float3 | nearest | The point on a spline nearest to the input ray. The accuracy of this value is
affected by the |
| Single | time | The normalized time value to the nearest point. |
| Int32 | resolution | Affects how many segments to split a spline into when calculating the nearest point.
Higher values mean smaller and more segments, which increases accuracy at the cost of processing time.
The minimum resolution is defined by PickResolutionMin, and the maximum is defined by
PickResolutionMax.
In most cases, the default resolution is appropriate. Use with |
| Int32 | iterations | The nearest point is calculated by finding the nearest point on the entire length
of the spline using |
Returns
| Type | Description |
|---|---|
| Single | The distance from ray to nearest point. |
GetNearestPoint<T>(T, float3, out float3, out Single, Int32, Int32)
Calculate the point on a spline nearest to a point.
Declaration
public static float GetNearestPoint<T>(T spline, float3 point, out float3 nearest, out float time, int resolution = 4, int iterations = 2)
where T : ISpline
Parameters
| Type | Name | Description |
|---|---|---|
| T | spline | The input spline to search for nearest point. |
| float3 | point | The input point to compare. |
| float3 | nearest | The point on a spline nearest to the input point. The accuracy of this value is
affected by the |
| Single | time | The normalized time value to the nearest point. |
| Int32 | resolution | Affects how many segments to split a spline into when calculating the nearest point.
Higher values mean smaller and more segments, which increases accuracy at the cost of processing time.
The minimum resolution is defined by PickResolutionMin, and the maximum is defined by
PickResolutionMax.
In most cases, the default resolution is appropriate. Use with |
| Int32 | iterations | The nearest point is calculated by finding the nearest point on the entire length
of the spline using |
Returns
| Type | Description |
|---|---|
| Single | The distance from input point to nearest point on spline. |
Type Parameters
| Name | Description |
|---|---|
| T |
GetNormalizedTime<T>(T, Single, PathIndexUnit)
Given a time value using a certain PathIndexUnit type, calculate the normalized time value regarding a specific spline.
Declaration
public static float GetNormalizedTime<T>(T spline, float time, PathIndexUnit originalTimeUnit)
where T : ISpline
Parameters
| Type | Name | Description |
|---|---|---|
| T | spline | The Spline to use for the conversion, this is necessary to compute Normalized and Distance PathIndexUnits. |
| Single | time | The time to normalize in the original PathIndexUnit. |
| PathIndexUnit | originalTimeUnit | The PathIndexUnit from the original time. |
Returns
| Type | Description |
|---|---|
| Single | The normalized time. |
Type Parameters
| Name | Description |
|---|---|
| T |
GetSegmentCount(Single, Int32)
Use this function to calculate the number of segments for a given spline length and resolution.
Declaration
public static int GetSegmentCount(float length, int resolution)
Parameters
| Type | Name | Description |
|---|---|---|
| Single | length | A distance value in PathIndexUnit. |
| Int32 | resolution | A value used to calculate the number of segments for a length. This is calculated as max(MIN_SEGMENTS, min(MAX_SEGMENTS, sqrt(length) * resolution)). |
Returns
| Type | Description |
|---|---|
| Int32 | The number of segments as calculated for given length and resolution. |
SetPivot(SplineContainer, Vector3)
Reset a transform position to a position while keeping knot positions in the same place. This modifies both knot positions and transform position.
Declaration
public static void SetPivot(SplineContainer container, Vector3 position)
Parameters
| Type | Name | Description |
|---|---|---|
| SplineContainer | container | The target spline. |
| Vector3 | position | The |
SplineToCurveInterpolation<T>(T, Single, out Single)
Given a normalized interpolation (t) for a spline, calculate the curve index and curve-relative normalized interpolation.
Declaration
public static int SplineToCurveInterpolation<T>(this T spline, float splineT, out float curveT)
where T : ISpline
Parameters
| Type | Name | Description |
|---|---|---|
| T | spline | The target spline. |
| Single | splineT | A normalized spline interpolation value to be converted into curve space. |
| Single | curveT | A normalized curve interpolation value. |
Returns
| Type | Description |
|---|---|
| Int32 | The curve index. |
Type Parameters
| Name | Description |
|---|---|
| T |