Class SplineUtility
A collection of methods for extracting information about Spline types.
Namespace: UnityEngine.Splines
Syntax
public static class SplineUtility : object
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 = null
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 = null
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 = null
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 = null
Field Value
Type | Description |
---|---|
Int32 |
Methods
CalculateLength<T>(T, float4x4)
Calculate the length of a spline when transformed by a matrix.
Declaration
public static float CalculateLength<T>(this T spline, float4x4 transform)
where T : ISpline
Parameters
Type | Name | Description |
---|---|---|
T | spline | |
float4x4 | transform |
Returns
Type | Description |
---|---|
Single |
Type Parameters
Name | Description |
---|---|
T | A type implementing ISpline. |
ConvertIndexUnit<T>(T, Single, PathIndexUnit)
Given a normalized interpolation ratio, calculate the associated interpolation value in another targetPathUnit regarding a specific spline.
Declaration
public static float ConvertIndexUnit<T>(this T spline, float t, 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 | t | Normalized interpolation ratio (0 to 1). |
PathIndexUnit | targetPathUnit | The PathIndexUnit to which 't' should be converted. |
Returns
Type | Description |
---|---|
Single | The interpolation value converted to targetPathUnit. |
Type Parameters
Name | Description |
---|---|
T | A type implementing ISpline. |
ConvertIndexUnit<T>(T, Single, PathIndexUnit, PathIndexUnit)
Given an interpolation value using a certain PathIndexUnit type, calculate the associated interpolation value in another targetPathUnit regarding a specific spline.
Declaration
public static float ConvertIndexUnit<T>(this T spline, float t, PathIndexUnit fromPathUnit, 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 | t | Interpolation in the original PathIndexUnit. |
PathIndexUnit | fromPathUnit | The PathIndexUnit for the original interpolation value. |
PathIndexUnit | targetPathUnit | The PathIndexUnit to which 't' should be converted. |
Returns
Type | Description |
---|---|
Single | The interpolation value converted to targetPathUnit. |
Type Parameters
Name | Description |
---|---|
T | A type implementing ISpline. |
CurveToSplineT<T>(T, Single)
Given an interpolation value for a curve, calculate the relative normalized spline interpolation.
Declaration
public static float CurveToSplineT<T>(this 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 | A type implementing ISpline. |
See Also
Evaluate<T>(T, Single, out float3, out float3, out float3)
Compute interpolated position, direction and upDirection at ratio t. Calling this method to get the 3 vectors is faster than calling independently EvaluatePosition, EvaluateDirection and EvaluateUpVector for the same time t as it reduces some redundant computation.
Declaration
public static bool Evaluate<T>(this T spline, float t, out float3 position, out float3 tangent, out float3 upVector)
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. |
float3 | position | Output variable for the float3 position at t. |
float3 | tangent | Output variable for the float3 tangent at t. |
float3 | upVector | Output variable for the float3 up direction at t. |
Returns
Type | Description |
---|---|
Boolean | Boolean value, true if a valid set of output variables as been computed. |
Type Parameters
Name | Description |
---|---|
T | A type implementing ISpline. |
EvaluateAcceleration<T>(T, Single)
Return an interpolated acceleration at ratio t.
Declaration
public static float3 EvaluateAcceleration<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 | An acceleration on the spline. |
Type Parameters
Name | Description |
---|---|
T | A type implementing ISpline. |
EvaluateCurvature<T>(T, Single)
Return an interpolated curvature at ratio t.
Declaration
public static float EvaluateCurvature<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 |
---|---|
Single | A curvature on the spline. |
Type Parameters
Name | Description |
---|---|
T | A type implementing ISpline. |
EvaluateCurvatureCenter<T>(T, Single)
Return the curvature center at ratio t. The curvature center represents the center of the circle that is tangent to the curve at t. This circle is in the plane defined by the curve velocity (tangent) and the curve acceleration at that point.
Declaration
public static float3 EvaluateCurvatureCenter<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 point representing the curvature center associated to the position at t on the spline. |
Type Parameters
Name | Description |
---|---|
T | A type implementing ISpline. |
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 | A type implementing ISpline. |
EvaluateTangent<T>(T, Single)
Return an interpolated direction at ratio t.
Declaration
public static float3 EvaluateTangent<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 | A type implementing ISpline. |
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 | A type implementing ISpline. |
GetBounds<T>(T)
Calculate the bounding box of a Spline.
Declaration
public static Bounds GetBounds<T>(this 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. |
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 t, int resolution = null, 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 | t | The normalized interpolation ratio corresponding 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 | A type implementing ISpline. |
GetNearestPoint<T>(T, Ray, out float3, out Single, Int32, Int32)
Calculate the point on a spline nearest to a ray.
Declaration
public static float GetNearestPoint<T>(T spline, Ray ray, out float3 nearest, out float t, int resolution = null, int iterations = 2)
where T : ISpline
Parameters
Type | Name | Description |
---|---|---|
T | 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 | t | 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. |
Type Parameters
Name | Description |
---|---|
T | A type implementing ISpline. |
GetNormalizedInterpolation<T>(T, Single, PathIndexUnit)
Given an interpolation value in any PathIndexUnit type, calculate the normalized interpolation ratio value relative to a Spline.
Declaration
public static float GetNormalizedInterpolation<T>(T spline, float t, PathIndexUnit originalPathUnit)
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 | t | The 't' value to normalize in the original PathIndexUnit. |
PathIndexUnit | originalPathUnit | The PathIndexUnit from the original 't'. |
Returns
Type | Description |
---|---|
Single | The normalized interpolation ratio (0 to 1). |
Type Parameters
Name | Description |
---|---|
T | A type implementing ISpline. |
GetPointAtLinearDistance<T>(T, Single, Single, out Single)
Given a Spline and interpolation ratio, calculate the 3d point at a linear distance from point at spline.EvaluatePosition(t). Returns the corresponding time associated to this 3d position on the Spline.
Declaration
public static float3 GetPointAtLinearDistance<T>(this T spline, float fromT, float relativeDistance, out float resultPointT)
where T : ISpline
Parameters
Type | Name | Description |
---|---|---|
T | spline | The Spline on which to compute the point. |
Single | fromT | The Spline interpolation ratio 't' (normalized) from which the next position need to be computed. |
Single | relativeDistance | The relative distance at which the new point should be placed. A negative value will compute a point at a 'resultPointTime' previous to 'fromT' (backward search). |
Single | resultPointT | The normalized interpolation ratio of the resulting point. |
Returns
Type | Description |
---|---|
float3 | The 3d point from the spline located at a linear distance from the point at t. |
Type Parameters
Name | Description |
---|---|
T | A type implementing ISpline. |
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 |
SplineToCurveT<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 SplineToCurveT<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 | A type implementing ISpline. |