#include <lib_splinehelp.h>
Class for helping to deal with splines. Defines routines to get positions along splines from real-world units, non flipping/non gimbal locked matrices and vectors from splines.
Must be initialized before use. All values returned are in global space. The slow part is the InitSpline() routine; other access is pretty fast.
Private Member Functions | |
SplineHelp () | |
~SplineHelp () | |
Alloc/Free | |
static SplineHelp * | Alloc () |
static void | Free (SplineHelp *&node) |
Init/Free Spline | |
Bool | InitSplineEx (const BaseObject *op, Vector upvector=Vector(0.0), const BaseObject *rail=nullptr, Bool target_rail=true, Bool use_deformed_points=false, Bool force_update=false, Bool use_global_space=true) |
void | FreeSpline () |
Bool | InitSpline (const BaseObject *op, SPLINEHELPFLAGS flags=SPLINEHELPFLAGS::GLOBALSPACE|SPLINEHELPFLAGS::CONTINUECURVE) |
Bool | InitSpline (const BaseObject *op, Vector upvector, SPLINEHELPFLAGS flags=SPLINEHELPFLAGS::GLOBALSPACE|SPLINEHELPFLAGS::CONTINUECURVE) |
Bool | InitSpline (const BaseObject *op, const BaseObject *rail, SPLINEHELPFLAGS flags=SPLINEHELPFLAGS::TARGETRAIL|SPLINEHELPFLAGS::GLOBALSPACE|SPLINEHELPFLAGS::CONTINUECURVE) |
Count | |
Int32 | GetSegmentCount () const |
Int32 | GetVertexCount (Int32 segment=NOTOK) const |
Int32 | GetPointCount () const |
Operations | |
Float | GetSplineLength () const |
Float | GetSegmentLength (Int32 segment) const |
Matrix | GetVertexMatrix (Int32 index) const |
Float | GetPointValue (Float offset, Int32 segment) const |
Int32 | GetPointIndex (Float offset, Int32 segment) const |
Vector | GetPosition (Float offset, Int32 segment=0, Bool smooth=true, Bool realoffset=false) const |
Vector | GetTangent (Float offset, Int32 segment=0, Bool smooth=true, Bool realoffset=false) const |
Vector | GetNormal (Float offset, Int32 segment=0, Bool smooth=true, Bool realoffset=false) const |
Vector | GetCrossNormal (Float offset, Int32 segment=0, Bool smooth=true, Bool realoffset=false) const |
Float | GetOffsetFromUnit (Float unitoffset, Int32 segment=0) const |
Float | GetOffsetFromReal (Float offset, Int32 segment=0) const |
Matrix | GetMatrix (Float offset, Int32 segment=0, Bool smooth=true, Bool realoffset=false) const |
void | GetLinePointSegment (Int32 index, Float *offset, Int32 *ind, Int32 *segment) const |
void | GetSplinePointSegment (Int32 index, Float *offset, Int32 *ind, Int32 *segment) const |
void | GlobalToLocal (Float offset, Float *off, Int32 *segment, Bool realoffset=false) const |
Int32 | SplineToLineIndex (Int32 index) const |
Int32 | LineToSplineIndex (Int32 index) const |
Float | GetSize (Float offset, Int32 segment=0, Bool smooth=true, Bool realoffset=false) const |
Float | GetVertexSize (Int32 index) const |
Matrix | GetVertexMatrix (Int32 segment, Int32 index) const |
Miscellaneous | |
Bool | CopyTo (SplineHelp *dest) const |
Bool | Exists () const |
Bool | IsClosed (Int32 segment=0) const |
SPLINETYPE | GetType () const |
void | SetOwner (BaseObject *op) |
UInt32 | GetDirty () const |
Matrix | GetPointMatrix (Int32 splineVertexIndex) const |
LineObject * | GetLineObject () |
SplineObject * | GetSplineObjectCache () |
|
private |
|
private |
|
static |
|
static |
Bool InitSplineEx | ( | const BaseObject * | op, |
Vector | upvector = Vector(0.0) , |
||
const BaseObject * | rail = nullptr , |
||
Bool | target_rail = true , |
||
Bool | use_deformed_points = false , |
||
Bool | force_update = false , |
||
Bool | use_global_space = true |
||
) |
Initializes the spline data. Deprecated since R17.
[in] | op | The spline object to use. The caller owns the pointed spline object. |
[in] | upvector | An optional up-vector for the spline normals generation. This is only used at the start of splines/segments; this way it avoids gimbal lock if at all possible. |
[in] | rail | An optional rail spline object for the spline normals generation. The caller owns the pointed spline object. |
[in] | target_rail | If true the optional rail spline is not only used as up-vector but also as target. This is used for instance in MoGraph's Rail options (Cloner, Spline effector, Spline Wrap etc.). |
[in] | use_deformed_points | If true uses the deformed point positions of the spline. |
[in] | force_update | If true forces a full initialization. The spline help class internally caches its own content. Thus it will be much faster if the same splines are used for initialization. . |
[in] | use_global_space | If false the resulting matrices are in local space rather than in the spline objects' global space. |
void FreeSpline | ( | ) |
Frees the spline data. Recalling InitSpline() or calling Free() will automatically call this.
Int32 GetSegmentCount | ( | ) | const |
Gets the number of segments in the spline.
Gets the number of vertices for a spline segment.
[in] | segment | The segment index: 0 <= segment < GetSegmentCount() |
Int32 GetPointCount | ( | ) | const |
Retrieves the number of spline points.
Float GetSplineLength | ( | ) | const |
Retrieves the spline's real-world unit length including all segments.
Retrieves a specific segment's real-world unit length.
[in] | segment | The segment index: 0 <= segment < GetSegmentCount() |
Retrieves a full matrix for a specific point of the line.
[in] | index | The index of the line object vertex: 0 <= index < op->GetPointCount() |
Converts a natural offset value to a real percentage offset value.
[in] | offset | The offset given in spline space. |
[in] | segment | The segment index: 0 <= segment < GetSegmentCount() |
Retrieves the nearest line point index to the given real offset.
[in] | offset | The spline space offset. |
[in] | segment | The segment index: 0 <= segment < GetSegmentCount() |
Vector GetPosition | ( | Float | offset, |
Int32 | segment = 0 , |
||
Bool | smooth = true , |
||
Bool | realoffset = false |
||
) | const |
Gets a position along the spline.
[in] | offset | The spline offset. |
[in] | segment | The segment index: 0 <= segment < GetSegmentCount() |
[in] | smooth | If true the position is smoothed. |
[in] | realoffset | If true uses uniform spline distribution. |
Vector GetTangent | ( | Float | offset, |
Int32 | segment = 0 , |
||
Bool | smooth = true , |
||
Bool | realoffset = false |
||
) | const |
Gets a tangent vector for any point along the spline.
[in] | offset | The spline offset. |
[in] | segment | The segment index: 0 <= segment < GetSegmentCount() |
[in] | smooth | If true the position is smoothed. |
[in] | realoffset | If true uses uniform spline distribution. |
Vector GetNormal | ( | Float | offset, |
Int32 | segment = 0 , |
||
Bool | smooth = true , |
||
Bool | realoffset = false |
||
) | const |
Gets a normal vector for any point along the spline.
[in] | offset | The spline offset. |
[in] | segment | The segment index: 0 <= segment < GetSegmentCount() |
[in] | smooth | If true the position is smoothed. |
[in] | realoffset | If true uses uniform spline distribution. |
Vector GetCrossNormal | ( | Float | offset, |
Int32 | segment = 0 , |
||
Bool | smooth = true , |
||
Bool | realoffset = false |
||
) | const |
Gets a cross normal vector (i.e. perpendicular to the normal and the tangent) for any point along the spline.
[in] | offset | The spline offset. |
[in] | segment | The segment index: 0 <= segment < GetSegmentCount() |
[in] | smooth | If true the position is smoothed. |
[in] | realoffset | If true uses uniform spline distribution. |
Converts a percentage offset into a natural offset. Percentage offsets ignore spline interpolation etc and are always x% along the spline.
[in] | unitoffset | A percentage offset: 0 <= unitoffset <= 1.0. |
[in] | segment | The segment index: 0 <= segment < GetSegmentCount() |
Retrieves an offset from a real-world unit.
For example, if a spline is 50 units long, 25 would be 50% of the length, i.e. 0.5.
[in] | offset | The real unit offset to convert. |
[in] | segment | The segment index: 0 <= segment < GetSegmentCount() |
Matrix GetMatrix | ( | Float | offset, |
Int32 | segment = 0 , |
||
Bool | smooth = true , |
||
Bool | realoffset = false |
||
) | const |
Retrieves a full matrix for any point along the spline, constructed as a local coordinate system at that point.
Optionally uses real-world percentage rather than spline natural space for the offset.
[in] | offset | The spline offset. |
[in] | segment | The segment index: 0 <= segment < GetSegmentCount() |
[in] | smooth | If true the position is smoothed. |
[in] | realoffset | If true uses uniform spline distribution. |
Converts a global point index in a line (i.e. from 0 to the number of points in the line object) to a local set of values within a single segment returning the segment the point is in, the offset along the segment and the point index within the segment (0 to the segment point count).
[in] | index | The line object vertex index: 0 <= index < op->GetPointCount() (Using LOD = 1.0 for the line object.) |
[out] | offset | Assigned the offset along the segment. |
[out] | ind | Assigned the point index within the segment. |
[out] | segment | Assigned the segment index. |
Converts a global point index in (i.e. from 0 to the number of points in the spline) to a local set of values within a single segment returning the segment the point is in, the offset along the segment and the point index within the segment (0 0 to the segment point count).
[in] | index | The global spline point index: 0 <= index < op->GetPointCount() |
[out] | offset | Assigned the offset along the segment. |
[out] | ind | Assigned the point index within the segment. |
[out] | segment | Assigned the segment index. |
Turns a percentage along the whole spline to local segment info, offset along segment, the segment the point exists in.
Optionally uses a real % offset rather than the spline natural offset.
[in] | offset | The percentage along the whole spline. |
[out] | off | Assigned the offset along the segment. |
[out] | segment | Assigned the segment index. |
[in] | realoffset | If true a real-world percentage is used, rather than the natural spline space. |
Converts a spline vertex index to its corresponding line object vertex index.
[in] | index | The spline vertex index: 0 <= index < op->GetPointCount() |
Converts a line object vertex index to its corresponding spline vertex index.
[in] | index | The line object vertex index: 0 <= index < op->GetPointCount() |
Float GetSize | ( | Float | offset, |
Int32 | segment = 0 , |
||
Bool | smooth = true , |
||
Bool | realoffset = false |
||
) | const |
Gets the distance to an existing rail spline for any point along the spline.
[in] | offset | The spline offset. |
[in] | segment | The segment index: 0 <= segment < GetSegmentCount() |
[in] | smooth | If true the position is smoothed. |
[in] | realoffset | If true uses uniform spline distribution. |
Gets the distance to an existing rail spline for a spline vertex specified by index.
[in] | index | The vertex index: 0 <= index < GetVertexCount() |
Gets the matrix for a spline vertex specified by segment and index.
[in] | segment | The segment index: 0 <= segment < GetSegmentCount() |
[in] | index | The vertex index: 0 <= index < GetVertexCount() |
Bool CopyTo | ( | SplineHelp * | dest | ) | const |
Copies the spline helper data to another SplineHelp.
[in,out] | dest | The destination spline help. The caller owns the pointed spline help. |
Bool Exists | ( | ) | const |
Checks if the spline helper contains data and has been initialized.
Checks if a spline segment is closed.
[in] | segment | The segment index: 0 <= segment < GetSegmentCount() |
SPLINETYPE GetType | ( | ) | const |
Retrieves the spline interpolation type.
void SetOwner | ( | BaseObject * | op | ) |
Prevents recursion lock crashes when SplineHelp needs to create the cache of the passed spline.
This is the case if for instance the developer has no control over the placement of a spline object in relation to its node.
For instance prevents infinite recursion in an object generator linking to itself using link fields.
Example:
It is also possible to call
ObjectData::GetVirtualObjects() rather than in ObjectData::Init(). SetOwner() is not very costly to call.
[in] | op | The object owning the current node data. If called from within a tag plugin pass the tag's parent object: shelp->SetOwner(tag->GetObject())
shelp->SetOwner((BaseObject*)node->Get())
|
UInt32 GetDirty | ( | ) | const |
Gets the dirty value for the SplineHelp which indicates how often the help has been updated with new values. i.e. how often the source spline has changed, and or the spline has been cleared.
Gets the matrix for a spline vertex.
[in] | splineVertexIndex | The zero-based index of the spline vertex. |
LineObject* GetLineObject | ( | ) |
Gets a LineObject from SplineHelp functions.
SplineObject* GetSplineObjectCache | ( | ) |
Get the cached SplineObject. The SplineHelp owns the pointed SplineObject.
Bool InitSpline | ( | const BaseObject * | op, |
SPLINEHELPFLAGS | flags = SPLINEHELPFLAGS::GLOBALSPACE|SPLINEHELPFLAGS::CONTINUECURVE |
||
) |
Initializes the SplineHelp with the passed spline op, must be called before any other functions can be utilized.
[in] | op | The spline object to initialize from. The caller owns the pointed spline object. |
[in] | flags | The optional flags used to control how the SplineHelp is setup: SPLINEHELPFLAGS |
Bool InitSpline | ( | const BaseObject * | op, |
Vector | upvector, | ||
SPLINEHELPFLAGS | flags = SPLINEHELPFLAGS::GLOBALSPACE|SPLINEHELPFLAGS::CONTINUECURVE |
||
) |
Initializes the SplineHelp with the passed spline op, must be called before any other functions can be utilized.
[in] | op | The spline object to initialize from. The caller owns the pointed spline object. |
[in] | upvector | The initial up-vector for the spline if no rail spline is passed. |
[in] | flags | The optional flags used to control how the SplineHelp is setup: SPLINEHELPFLAGS |
Bool InitSpline | ( | const BaseObject * | op, |
const BaseObject * | rail, | ||
SPLINEHELPFLAGS | flags = SPLINEHELPFLAGS::TARGETRAIL|SPLINEHELPFLAGS::GLOBALSPACE|SPLINEHELPFLAGS::CONTINUECURVE |
||
) |
Initializes the SplineHelp with the passed spline op, must be called before any other functions can be utilized.
[in] | op | The SplineObject to initialize from. The caller owns the pointed spline object. |
[in] | rail | The rail spline. The caller owns the pointed spline object. |
[in] | flags | The optional flags used to control how the SplineHelp is setup: SPLINEHELPFLAGS |