Class CurvySplineSegment
- Namespace
- FluffyUnderware.Curvy
Class covering a Curvy Spline Segment / ControlPoint
[ExecuteAlways]
public class CurvySplineSegment : DTVersionedMonoBehaviour
- Inheritance
-
ObjectComponentBehaviourMonoBehaviourDTVersionedMonoBehaviourCurvySplineSegment
Fields
GizmoTangentColor
The color used in Gizmos to draw a segment's tangents
public static readonly Color GizmoTangentColor
Field Value
- Color
Properties
AutoBakeOrientation
If set, Control Point's rotation will be set to the calculated Up-Vector3
public bool AutoBakeOrientation { get; set; }
Property Value
Remarks
This is particularly useful when connecting splines
AutoHandleDistance
public float AutoHandleDistance { get; set; }
Property Value
AutoHandles
Gets or Sets Auto Handles. When setting it the value of connected control points is also updated
public bool AutoHandles { get; set; }
Property Value
Bounds
Gets this segment's bounds in world space
public Bounds Bounds { get; }
Property Value
- Bounds
CacheSize
Gets the number of individual cache points of this segment
public int CacheSize { get; }
Property Value
Remarks
The actual approximations arrays' size is CacheSize + 1
Connection
Gets/Sets the connection handler this Control Point is using (if any)
[CanBeNull]
public CurvyConnection Connection { get; }
Property Value
Remarks
If set to null, FollowUp wil be set to null to
ConnectionSyncPosition
When part of a CurvyConnection, this defines whether the connection's position is applied to this Control Point The synchronization process is applied by CurvyConnection at each frame in its update methods. So if you modify the value of this property, and want the synchronization to happen right away, you will have to call the connection's SetSynchronisationPositionAndRotation(Vector3, Quaternion) with the connection's position and rotation as parameters
public bool ConnectionSyncPosition { get; set; }
Property Value
ConnectionSyncRotation
When part of a CurvyConnection, this defines whether the connection's rotation is applied to this Control Point The synchronization process is applied by CurvyConnection at each frame in its update methods. So if you modify the value of this property, and want the synchronization to happen right away, you will have to call the connection's SetSynchronisationPositionAndRotation(Vector3, Quaternion) with the connection's position and rotation as parameters
public bool ConnectionSyncRotation { get; set; }
Property Value
Distance
Gets the distance from spline start to the start of this segment (localF=0)
public float Distance { get; }
Property Value
DistancesApproximation
List of distances approximating the segments's length Approximations are a set of precomputed properties of points sampled along the spline. Approximations are computed and stored for fast access to an approximation of the spline. The fidelity of the approximation depends on the spline's CacheDensity and MaxPointsPerUnit properties. Approximations are computed when the spline is refreshed. Spline refreshing is done automatically when needed (see UpdateIn), but you can also force it by calling Refresh().
public SubArray<float> DistancesApproximation { get; }
Property Value
- See Also
EffectiveTcbParameters
Returns the actual TcbParameters for this segment, considering global and local settings.
public TcbParameters EffectiveTcbParameters { get; }
Property Value
- See Also
EndBias
Local Bias at segment end. Is used only if OverrideGlobalBias is true
public float EndBias { get; set; }
Property Value
Remarks
This only applies to splines using TCB
EndContinuity
Local Continuity at segment end. Is used only if OverrideGlobalContinuity is true
public float EndContinuity { get; set; }
Property Value
Remarks
This only applies to splines using TCB
EndTension
Local Tension at segment end. Is used only if OverrideGlobalTension is true
public float EndTension { get; set; }
Property Value
Remarks
This only applies to splines using TCB
FollowUp
Gets the connected Control Point that is set as "Head To"
[CanBeNull]
public CurvySplineSegment FollowUp { get; }
Property Value
FollowUpHeading
Gets or sets the heading toward the "Head To" segment
public ConnectionHeadingEnum FollowUpHeading { get; set; }
Property Value
HandleIn
Bézier spline left handle in spline's local coordinates
public Vector3 HandleIn { get; set; }
Property Value
- Vector3
HandleInPosition
Bézier spline left handle in world coordinates
public Vector3 HandleInPosition { get; set; }
Property Value
- Vector3
HandleOut
Bézier spline right handle in spline's local coordinates
public Vector3 HandleOut { get; set; }
Property Value
- Vector3
HandleOutPosition
Bézier spline right handle in world coordinates
public Vector3 HandleOutPosition { get; set; }
Property Value
- Vector3
HasUnprocessedLocalOrientation
Returns true if the local orientation is different than the last one used in the segment approximations cache computation
public bool HasUnprocessedLocalOrientation { get; }
Property Value
HasUnprocessedLocalPosition
Returns true if the local position is different than the last one used in the segment approximations cache computation
public bool HasUnprocessedLocalPosition { get; }
Property Value
IsFirstControlPoint
Gets whether this Control Point is the first IGNORING closed splines
public bool IsFirstControlPoint { get; }
Property Value
IsLastControlPoint
Gets whether this Control Point is the last IGNORING closed splines
public bool IsLastControlPoint { get; }
Property Value
Length
Gets the length of this spline segment
public float Length { get; }
Property Value
Metadata
The Metadata components added to this GameObject
public HashSet<CurvyMetadataBase> Metadata { get; }
Property Value
OrientationInfluencesSpline
Returns wheter the orientation of this Control Point influences the orientation of its containing spline's approximation points. Returns false if control point is not part of a spline
public bool OrientationInfluencesSpline { get; }
Property Value
OverrideGlobalBias
public bool OverrideGlobalBias { get; set; }
Property Value
Remarks
This only applies to splines using TCB
OverrideGlobalContinuity
Whether local StartContinuity and EndContinuity should be used. Otherwise the global values are used. See Continuity
public bool OverrideGlobalContinuity { get; set; }
Property Value
Remarks
This only applies to splines using TCB
OverrideGlobalTension
Whether local StartTension and EndTension should be used. Otherwise the global values are used. See Tension
public bool OverrideGlobalTension { get; set; }
Property Value
Remarks
This only applies to splines using TCB
PositionsApproximation
List of points approximating the segments's shape. Approximations are a set of precomputed properties of points sampled along the spline. Approximations are computed and stored for fast access to an approximation of the spline. The fidelity of the approximation depends on the spline's CacheDensity and MaxPointsPerUnit properties. Approximations are computed when the spline is refreshed. Spline refreshing is done automatically when needed (see UpdateIn), but you can also force it by calling Refresh().
public SubArray<Vector3> PositionsApproximation { get; }
Property Value
- SubArray<Vector3>
- See Also
SerializedOrientationAnchor
The serialized value of OrientationAnchor. This value is ignored in some cases (invisible control points, first and last visible control points). Use IsControlPointAnOrientationAnchor(CurvySplineSegment) to get the correct value.
public bool SerializedOrientationAnchor { get; set; }
Property Value
Spline
Gets the parent spline
[CanBeNull]
public CurvySpline Spline { get; }
Property Value
StartBias
Local Bias at segment start. Is used only if OverrideGlobalBias is true
public float StartBias { get; set; }
Property Value
Remarks
This only applies to splines using TCB
StartContinuity
Local Continuity at segment start. Is used only if OverrideGlobalContinuity is true
public float StartContinuity { get; set; }
Property Value
Remarks
This only applies to splines using TCB
StartTension
Local Tension at segment start. Is used only if OverrideGlobalTension is true
public float StartTension { get; set; }
Property Value
Remarks
This only applies to splines using TCB
Swirl
Swirling Mode
public CurvyOrientationSwirl Swirl { get; set; }
Property Value
SwirlTurns
Turns to swirl
public float SwirlTurns { get; set; }
Property Value
SynchronizeTCB
Keep Start/End-TCB synchronized
public bool SynchronizeTCB { get; set; }
Property Value
Remarks
Applies only to TCB Interpolation
TF
Gets the TF of this Control Point TF stands for Total Fragment. It's a value ranging from 0 to 1 inclusive. 0 means the spline's start and 1 means the spline's end. This is the "time" parameter used in the splines' formulas. A point's TF is not proportional to its distance from the spline's start. Depending on the spline, a value of 0.5 does not always mean the middle, distance wise, of the spline
public float TF { get; }
Property Value
Remarks
This yields the same result as LocalFToTF(0)
TangentsApproximation
List of tangents approximating the segments's shape Approximations are a set of precomputed properties of points sampled along the spline. Approximations are computed and stored for fast access to an approximation of the spline. The fidelity of the approximation depends on the spline's CacheDensity and MaxPointsPerUnit properties. Approximations are computed when the spline is refreshed. Spline refreshing is done automatically when needed (see UpdateIn), but you can also force it by calling Refresh().
public SubArray<Vector3> TangentsApproximation { get; }
Property Value
- SubArray<Vector3>
- See Also
UpsApproximation
List of directions approximating the segments's orientation Approximations are a set of precomputed properties of points sampled along the spline. Approximations are computed and stored for fast access to an approximation of the spline. The fidelity of the approximation depends on the spline's CacheDensity and MaxPointsPerUnit properties. Approximations are computed when the spline is refreshed. Spline refreshing is done automatically when needed (see UpdateIn), but you can also force it by calling Refresh().
public SubArray<Vector3> UpsApproximation { get; }
Property Value
- SubArray<Vector3>
- See Also
Methods
BSpline(ReadOnlyCollection<CurvySplineSegment>, float, bool, bool, int, Vector3[])
Gets the position of a point on the B-Spline
public static Vector3 BSpline(ReadOnlyCollection<CurvySplineSegment> controlPoints, float tf, bool isClamped, bool isClosed, int degree, Vector3[] p0Array)
Parameters
controlPointsReadOnlyCollection<CurvySplineSegment>The spline's control points.
tffloatA value between 0 and 1 defining where the point is on the spline
isClampedboolisClosedbooldegreeintp0ArrayVector3[]An array used in internal computations. This is to avoid excessive allocations.The length of the array should be greater or equal to
degree+ 1. The content of the array does not matter, since it gets overwritten by the method
Returns
- Vector3
BakeOrientationToTransform()
Modify the control point's local rotation to match the segment's orientation
public void BakeOrientationToTransform()
CanFollowUpHeadToEnd(CurvySplineSegment)
Returns true if followUp can be associated with a heading direction of Plus
public static bool CanFollowUpHeadToEnd(CurvySplineSegment followUp)
Parameters
followUpCurvySplineSegment
Returns
CanFollowUpHeadToStart(CurvySplineSegment)
Returns true if followUp can be associated with a heading direction of Minus
public static bool CanFollowUpHeadToStart(CurvySplineSegment followUp)
Parameters
followUpCurvySplineSegment
Returns
DeleteMetadata()
Removes all Metadata components of this Control Point
public void DeleteMetadata()
Disconnect()
Resets the connections related data (Connection, FollowUp, etc) while updating the Connection object and dirtying relevant splines.
public void Disconnect()
Disconnect(bool)
Resets the connections related data (Connection, FollowUp, etc) while updating the Connection object and dirtying relevant splines.
public void Disconnect(bool destroyEmptyConnection)
Parameters
destroyEmptyConnectionboolwhether the related Connection should be destroyed if it becomes empty due to this Disconnect call
DistanceToLocalF(float)
Gets the local F of a point given its local distance Local F stands for Local Fragment. It's a value ranging from 0 to 1 inclusive. 0 means the segment's start and 1 means the segment's end. This is the "time" parameter used in the splines' formulas. A point's localF is not proportional to its distance from the segment's start. Depending on the spline, a value of 0.5 does not always mean the middle, distance wise, of the segment
public float DistanceToLocalF(float localDistance)
Parameters
localDistancefloatThe distance between the segment's start and the point you are interested in. Value should be in the range from 0 to Length inclusive
Returns
GetInterpolatedMetadata<T, U>(float)
Gets an interpolated Metadata value for a certain F
public U GetInterpolatedMetadata<T, U>(float f) where T : CurvyInterpolatableMetadataBase<U>
Parameters
ffloata local F in the range 0..1
Returns
- U
The interpolated value. If no Metadata of specified type is present at the given tf, the default value of type U is returned
Type Parameters
TMetadata type inheriting from CurvyInterpolatableMetadataBase
UMetadata's Value type
GetMetadata<T>(bool)
Gets Metadata of this ControlPoint
public T GetMetadata<T>(bool autoCreate = false) where T : CurvyMetadataBase
Parameters
autoCreateboolwhether to create the Metadata component if it's not present
Returns
- T
the Metadata component or null
Type Parameters
TMetadata type
GetNearestPointF(Vector3, Space)
Gets the localF of the point on the segment that is the nearest to a given position localF stands for Local Fragment. It's a value ranging from 0 to 1 inclusive. 0 means the segment's start and 1 means the segment's end. This is the "time" parameter used in the splines' formulas. A point's localF is not proportional to its distance from the segment's start. Depending on the spline, a value of 0.5 does not always mean the middle, distance wise, of the segment
public float GetNearestPointF(Vector3 position, Space space = Space.Self)
Parameters
positionVector3The point's position
spaceSpaceThe space (spline's local space or the world space) in which
positionis expressed
Returns
Remarks
This method's precision and speed depend on the CacheDensity
GetOrientationFast(float, bool, Space)
Gets the rotation of a point on the spline segment. The rotation's forward is the segment's tangent, and it's up is the segment's orientation Instead of computing the exact value, this method uses a linear interpolation between cached points for faster result
public Quaternion GetOrientationFast(float localF, bool inverse = false, Space space = Space.Self)
Parameters
localFfloatlocalF stands for Local Fragment. It's a value ranging from 0 to 1 inclusive. 0 means the segment's start and 1 means the segment's end. This is the "time" parameter used in the splines' formulas. A point's localF is not proportional to its distance from the segment's start. Depending on the spline, a value of 0.5 does not always mean the middle, distance wise, of the segment
inverseboolwhether the orientation should look at the opposite direction of the tangent
spaceSpaceThe space (spline's local space or the world space) in which the returned result is expressed
Returns
- Quaternion
GetOrientationUpFast(float, Space)
Gets the Up vector of a point on the spline segment. Instead of computing the exact value, this method uses a linear interpolation between cached points for faster result
public Vector3 GetOrientationUpFast(float localF, Space space = Space.Self)
Parameters
localFfloatlocalF stands for Local Fragment. It's a value ranging from 0 to 1 inclusive. 0 means the segment's start and 1 means the segment's end. This is the "time" parameter used in the splines' formulas. A point's localF is not proportional to its distance from the segment's start. Depending on the spline, a value of 0.5 does not always mean the middle, distance wise, of the segment
spaceSpaceThe space (spline's local space or the world space) in which the returned result is expressed
Returns
- Vector3
GetTangent(float, Space)
Gets the normalized tangent at a point on the spline segment
public Vector3 GetTangent(float localF, Space space = Space.Self)
Parameters
localFfloatlocalF stands for Local Fragment. It's a value ranging from 0 to 1 inclusive. 0 means the segment's start and 1 means the segment's end. This is the "time" parameter used in the splines' formulas. A point's localF is not proportional to its distance from the segment's start. Depending on the spline, a value of 0.5 does not always mean the middle, distance wise, of the segment
spaceSpaceThe space (spline's local space or the world space) in which the returned result is expressed
Returns
- Vector3
GetTangentFast(float, Space)
Gets the normalized tangent at a point on the spline segment. Instead of computing the exact value, this method uses a linear interpolation between cached points for faster result
public Vector3 GetTangentFast(float localF, Space space = Space.Self)
Parameters
localFfloatlocalF stands for Local Fragment. It's a value ranging from 0 to 1 inclusive. 0 means the segment's start and 1 means the segment's end. This is the "time" parameter used in the splines' formulas. A point's localF is not proportional to its distance from the segment's start. Depending on the spline, a value of 0.5 does not always mean the middle, distance wise, of the segment
spaceSpaceThe space (spline's local space or the world space) in which the returned result is expressed
Returns
- Vector3
Interpolate(float, Space)
Gets the position of a point on the spline segment
public Vector3 Interpolate(float localF, Space space = Space.Self)
Parameters
localFfloatlocalF stands for Local Fragment. It's a value ranging from 0 to 1 inclusive. 0 means the segment's start and 1 means the segment's end. This is the "time" parameter used in the splines' formulas. A point's localF is not proportional to its distance from the segment's start. Depending on the spline, a value of 0.5 does not always mean the middle, distance wise, of the segment
spaceSpaceThe space (spline's local space or the world space) in which the returned result is expressed
Returns
- Vector3
InterpolateAndGetTangentFast(float, out Vector3, out Vector3, Space)
Gets the position and normalized tangent at a point on the spline segment Is Faster than calling Interpolate(float, Space) and Interpolate(float, Space) separately Instead of computing the exact value, this method uses a linear interpolation between cached points for faster result
public void InterpolateAndGetTangentFast(float localF, out Vector3 position, out Vector3 tangent, Space space = Space.Self)
Parameters
localFfloatlocalF stands for Local Fragment. It's a value ranging from 0 to 1 inclusive. 0 means the segment's start and 1 means the segment's end. This is the "time" parameter used in the splines' formulas. A point's localF is not proportional to its distance from the segment's start. Depending on the spline, a value of 0.5 does not always mean the middle, distance wise, of the segment
positionVector3the output position
tangentVector3the output tangent
spaceSpaceThe space (spline's local space or the world space) in which the returned result is expressed
InterpolateFast(float, Space)
Gets the position of a point on the spline segment. Instead of computing the exact value, this method uses a linear interpolation between cached points for faster result
public Vector3 InterpolateFast(float localF, Space space = Space.Self)
Parameters
localFfloatlocalF stands for Local Fragment. It's a value ranging from 0 to 1 inclusive. 0 means the segment's start and 1 means the segment's end. This is the "time" parameter used in the splines' formulas. A point's localF is not proportional to its distance from the segment's start. Depending on the spline, a value of 0.5 does not always mean the middle, distance wise, of the segment
spaceSpaceThe space (spline's local space or the world space) in which the returned result is expressed
Returns
- Vector3
LinkToSpline(CurvySpline)
public void LinkToSpline(CurvySpline spline)
Parameters
splineCurvySpline
LocalFToDistance(float)
Gets the local distance of a point at a certain localF. Local distance is the distance between a point and the start of its segment. Value ranges from 0 to the segment's Length, inclusive
public float LocalFToDistance(float localF)
Parameters
localFfloatlocalF stands for Local Fragment. It's a value ranging from 0 to 1 inclusive. 0 means the segment's start and 1 means the segment's end. This is the "time" parameter used in the splines' formulas. A point's localF is not proportional to its distance from the segment's start. Depending on the spline, a value of 0.5 does not always mean the middle, distance wise, of the segment
Returns
LocalFToTF(float)
Gets TF for a certain local F TF stands for Total Fragment. It's a value ranging from 0 to 1 inclusive. 0 means the spline's start and 1 means the spline's end. This is the "time" parameter used in the splines' formulas. A point's TF is not proportional to its distance from the spline's start. Depending on the spline, a value of 0.5 does not always mean the middle, distance wise, of the spline
public float LocalFToTF(float localF)
Parameters
localFfloatlocalF stands for Local Fragment. It's a value ranging from 0 to 1 inclusive. 0 means the segment's start and 1 means the segment's end. This is the "time" parameter used in the splines' formulas. A point's localF is not proportional to its distance from the segment's start. Depending on the spline, a value of 0.5 does not always mean the middle, distance wise, of the segment
Returns
- float
a TF value
OnAfterPop()
Is called after the object is popped from its associated pool
public void OnAfterPop()
OnBeforePush()
Is called before the object is pushed into its associated pool
public void OnBeforePush()
RegisterMetaData(CurvyMetadataBase)
Adds a MetaData instance to Metadata
public void RegisterMetaData(CurvyMetadataBase metaData)
Parameters
metaDataCurvyMetadataBase
ResetConnectionUnrelatedProperties()
Resets the properties of this control point , except the ones related to connections. Use Disconnect() to reset connections related properties.
public void ResetConnectionUnrelatedProperties()
SetBezierHandleIn(Vector3, Space, CurvyBezierModeEnum)
Sets Bezier HandleIn
public void SetBezierHandleIn(Vector3 position, Space space = Space.Self, CurvyBezierModeEnum mode = CurvyBezierModeEnum.None)
Parameters
positionVector3HandleIn position
spaceSpaceThe space (spline's local space or the world space) in which the
positionis expressedmodeCurvyBezierModeEnumHandle synchronization mode
SetBezierHandleOut(Vector3, Space, CurvyBezierModeEnum)
Sets Bezier HandleOut
public void SetBezierHandleOut(Vector3 position, Space space = Space.Self, CurvyBezierModeEnum mode = CurvyBezierModeEnum.None)
Parameters
positionVector3HandleOut position
spaceSpaceThe space (spline's local space or the world space) in which the
positionis expressedmodeCurvyBezierModeEnumHandle synchronization mode
SetBezierHandles(float, bool, bool, bool)
Automatically place Bezier handles relative to neighbour Control Points
public void SetBezierHandles(float distanceFrag = -1, bool setIn = true, bool setOut = true, bool noDirtying = false)
Parameters
distanceFragfloathow much % distance between neighbouring CPs are applied to the handle length?
setInboolSet HandleIn?
setOutboolSet HandleOut?
noDirtyingboolIf true, the Bezier handles will be modified without dirtying any spline
SetBezierHandles(float, Vector3, Vector3, bool, bool, bool)
Automatically place Bezier handles
public void SetBezierHandles(float distanceFrag, Vector3 p, Vector3 n, bool setIn = true, bool setOut = true, bool noDirtying = false)
Parameters
distanceFragfloathow much % distance between neighbouring CPs are applied to the handle length?
pVector3Position the In-Handle relates to
nVector3Position the Out-Handle relates to
setInboolSet HandleIn?
setOutboolSet HandleOut?
noDirtyingboolIf true, the Bezier handles will be modified without dirtying any spline
SetFollowUp(CurvySplineSegment, ConnectionHeadingEnum)
Sets Follow-Up of this Control Point
public void SetFollowUp(CurvySplineSegment target, ConnectionHeadingEnum heading = ConnectionHeadingEnum.Auto)
Parameters
targetCurvySplineSegmentthe Control Point to follow to
headingConnectionHeadingEnumthe Heading on the target's spline
SetLocalPosition(Vector3)
Sets the local position while dirtying the spline, dirtying the connected splines, and updating the connected control points' positions accordingly.
public void SetLocalPosition(Vector3 newPosition)
Parameters
newPositionVector3
SetLocalRotation(Quaternion)
Sets the local rotation while dirtying the spline, dirtying the connected splines, and updating the connected control points' rotations accordingly.
public void SetLocalRotation(Quaternion value)
Parameters
valueQuaternion
SetPosition(Vector3)
Sets the global position while dirtying the spline, dirtying the connected splines, and updating the connected control points' positions accordingly.
public void SetPosition(Vector3 value)
Parameters
valueVector3
SetRotation(Quaternion)
Sets the global rotation while dirtying the spline, dirtying the connected splines, and updating the connected control points' rotations accordingly.
public void SetRotation(Quaternion value)
Parameters
valueQuaternion
ToString()
Returns the name of the object.
public override string ToString()
Returns
- string
The name returned by ToString.
UnlinkFromSpline(CurvySpline)
public void UnlinkFromSpline(CurvySpline spline)
Parameters
splineCurvySpline
UnregisterMetaData(CurvyMetadataBase)
Removes a MetaData instance from Metadata
public void UnregisterMetaData(CurvyMetadataBase metaData)
Parameters
metaDataCurvyMetadataBase
getApproximationIndexINTERNAL(float, out float)
Internal, gets the index of mApproximation by F and the remaining fragment
public int getApproximationIndexINTERNAL(float localF, out float frag)