Class Spline3D
See Also: Class SplineKnot, Class PolyLine, Structure Knot.
class Spline3D
Description:
General-purpose 3D spline class. The BezierShape class has a list of these splines that make up the bezier shape. Methods of this class are used to access the properties of the spline. All methods of this class are implemented by the system.
Method Groups:
The following hyperlinks take you to the start of groups of related methods within the class:
NewSpline() / InvalidateGeomCache()
KnotCount(), Flags(), Segments(), Closed()
AddKnot(), DeleteKnot(), GetKnot(), SetKnot()
Get/SetKnotType() / Get/SetLineType()
InterpBezier() / InterpBezier3D() / TangentBezier3D() / TangentCurve3D()
IsAuto() / IsBezierPt() / IsCorner()
Reverse() / Append() / Prepend()
Get/SetInVec() / Get/SetOutVec()
Get/SetVert() / Verts() / Get/SetKnotPoint()
IsClockWise() / SelfIntersects() / IntersectsSpline() / SurroundsPoint() / SplineLength()
Internal Methods / Methods that should not be used by plug-in developers
Friend Classes:
friend class BezierShape;
friend class SplineShape;
Methods:
Prototype:
Spline3D(int itype = KTYPE_CORNER,int dtype = KTYPE_BEZIER,
int ptype = PARM_UNIFORM);
Remarks:
Constructor. The data members are initialized to the values passed.
Prototype:
~Spline3D();
Remarks:
Destructor.
NewSpline() / InvalidateGeomCache()
Prototype:
void NewSpline();
Remarks:
This method clears out the spline. It frees the knots attributes array and the bezier points array.
Prototype:
void InvalidateGeomCache();
Remarks:
This method makes sure the shape has flushed out any cached data it may have had.
KnotCount(), Flags(), Segments(), Closed()
Prototype:
inline int KnotCount()
Remarks:
Returns the Knot (point) count.
Prototype:
inline int Flags();
Remarks:
Returns the private spline flags.
SPLINE_CLOSED
This indicates if the spline is closed or not.
Prototype:
inline int Segments();
Remarks:
Returns the number of line segments in the spline. For example if you have a 4 knot spline that is open you'll get 3 segments.
Prototype:
inline int Closed();
Remarks:
Returns the closed status. Nonzero if closed; otherwise zero.
AddKnot(), DeleteKnot(), GetKnot, SetKnot()
Prototype:
int AddKnot(SplineKnot &k,int where = -1);
Remarks:
Add a knot to the spline at the specified location.
Parameters:
SplineKnot &k
The knot to add.
int where = -1
The location to add the knot. where < 0 indicates the end of the spline.
Return Value:
Nonzero on success; otherwise zero.
Prototype:
int DeleteKnot(int where);
Remarks:
Delete the specified knot.
Parameters:
int where
The location of the knot to delete.
Return Value:
Nonzero if the knot was deleted; otherwise zero.
Prototype:
void SetKnot(int i, SplineKnot &k);
Remarks:
This method is available in release 2.0 and later only.
This method sets the 'i-th' knot object which contain the knot point, in and out
vectors, knot and line types and auxiliary values.
Parameters:
int i
Specifies the knot to set.
SplineKnot &k
The knot to set.
Prototype:
SplineKnot GetKnot(int i);
Remarks:
This method is available in release 2.0 and later only.
This method gets the 'i-th' knot object which contain the knot point, in and out
vectors, knot and line types and auxiliary values.
Parameters:
int i
Specifies the knot to retrieve.
Prototype:
int Create(ViewExp *vpt,int msg, int point, int flags, IPoint2 m,
Matrix3* mat, IObjParam *ip=NULL);
Remarks:
This method is used internally by the free form line object SPLINE.CPP. This method allows the user to use the mouse to create a line. See the sample code in \MAXSDK\SAMPLES\OBJECTS\SPLINE.CPP for an example of this method in use.
New for 3ds max 2.0 is an additional parameter is a pointer to an IObjParam object, which is used to access the DisplayTempPrompt() mechanism. The parameter is optional; omitting it allows the spline operation to work as in 3ds max 1.x. Adding the parameter causes the spline to display the delta, distance and angle of the current segment being edited.
Prototype:
int StartInsert(ViewExp *vpt,int msg, int point, int flags,
IPoint2 theP, Matrix3* mat, int where );
Remarks:
This method is used internally by the free form line object SPLINE.CPP. See the sample code in \MAXSDK\SAMPLES\OBJECTS\SPLINE.CPP for an example of this method in use.
Get/SetKnotType() / Get/SetLineType()
Prototype:
inline int GetKnotType(int index);
Remarks:
Returns the knot type from the specified knot. See List of Spline Knot Types.
Parameters:
int index
The index of the knot type to return.
Prototype:
int SetKnotType(int index,int type);
Remarks:
Sets the knot type of the specified knot.
Parameters:
int index
The knot to set.
int type
See List of Spline Knot Types.
Return Value:
Nonzero if set; otherwise zero.
Prototype:
inline int GetLineType(int index);
Remarks:
Returns the type of line segment between knots for the specified segment.
Parameters:
int index
The index of the segment whose line type to return.
Return Value:
See List of Spline Line Types.
Prototype:
int SetLineType(int index,int type);
Remarks:
Sets the line type of the specified segment.
Parameters:
int index
The index of the segment.
int type
See List of Spline Line Types.
Return Value:
Nonzero if set; otherwise zero.
Prototype:
void ComputeBezPoints();
Remarks:
This method should be called whenever you finish changing points on the spline. This updates all the information internal to the spline needed to calculate all the bezier handles.
InterpBezier() / InterpBezier3D() / TangentBezier3D() / TangentCurve3D()
Prototype:
Point2 InterpBezier(IPoint2 *bez, float t);
Remarks:
Developers should use InterpBezier3D() below instead of this method and just use the x and y values returned.
Prototype:
Point3 InterpBezier3D(int segment, float t, int ptype=SPLINE_INTERP_SIMPLE);
Remarks:
This method returns a point interpolated on a segment between two knots.
Parameters:
int segment
The index of the segment to interpolate.
float t
A value in the range of 0.0 to 1.0. 0 is the first knot and 1 is the second knot.
int ptype=SPLINE_INTERP_SIMPLE
The spline type to use.
Return Value:
The interpolated point.
Prototype:
Point3 InterpCurve3D(float u, int ptype=SPLINE_INTERP_SIMPLE);
Remarks:
This method returns a point interpolated on the entire curve. This method returns a point but you don't know which segment the point falls on. Typically the method InterpBezier3D() will give better control of the curve as it interpolates a bezier segment.
Parameters:
float u
A value in the range of 0.0 to 1.0 for the entire curve.
int ptype=SPLINE_INTERP_SIMPLE
The spline type to use.
Return Value:
The interpolated point.
Prototype:
Point3 TangentBezier3D(int segment, float t, int ptype=SPLINE_INTERP_SIMPLE);
Remarks:
This method returns a tangent vector interpolated on a segment between two knots.
Parameters:
int segment
The index of the segment.
float t
A value in the range of 0.0 to 1.0. 0 is the first knot and 1 is the second knot.
int ptype=SPLINE_INTERP_SIMPLE
The spline type to use.
Return Value:
The tangent vector.
Prototype:
Point3 TangentCurve3D(float u, int ptype=SPLINE_INTERP_SIMPLE);
Remarks:
This method returns a tangent vector interpolated on the entire curve.
Parameters:
float u
A value in the range of 0.0 to 1.0 for the entire curve.
int ptype=SPLINE_INTERP_SIMPLE
The spline type to use.
Return Value:
The tangent vector.
IsAuto() / IsBezierPt() / IsCorner()
Prototype:
int IsAuto(int i);
Remarks:
Returns nonzero if the knot type is KTYPE_AUTO otherwise zero.
Parameters:
int i
The index of the knot.
Prototype:
int IsBezierPt(int i);
Remarks:
Returns nonzero if the knot type is KTYPE_BEZIER otherwise zero.
Parameters:
int i
The index of the knot.
Prototype:
int IsCorner(int i);
Remarks:
Returns nonzero if the knot type is KTYPE_CORNER otherwise zero.
Parameters:
int i
The index of the knot.
Prototype:
void GetBBox(TimeValue t, Matrix3& tm, Box3& box);
Remarks:
Returns the bounding box of the curve in the space specified by the tm.
Parameters:
TimeValue t
This parameter is not used.
Matrix3& tm
The tm to transform the points by prior to computing the bounding box.
Box3& box
The bounding box
Prototype:
void Transform(Matrix3 *tm);
Remarks:
This method may be used to transform the points of the spline into another space defined by the specified transformation matrix.
Parameters:
Matrix3 *tm
The transformation matrix.
Prototype:
int SetClosed(int flag = 1);
Remarks:
This method may be used to close or open the spline. If the optional parameter is not specified it is closed.
Parameters:
int flag = 1
Nonzero to close; zero to open.
Return Value:
Nonzero if changed, zero if not.
Prototype:
int SetOpen();
Remarks:
Sets the spline to open.
Return Value:
Nonzero if changed, zero if not.
Get/SetInVec() / Get/SetKnotPoint() Get/SetOutVec()
Prototype:
Point3 GetInVec(int i);
Remarks:
This method is available in release 2.0 and later only.
This method is used to retrieve the 'i-th' in vector position in absolute coordinates.
Parameters:
int i
The vector position to retrieve.
Prototype:
void SetInVec(int i, const Point3 &p);
Remarks:
This method is available in release 2.0 and later only.
This method is used to set the 'i-th' in vector position in absolute coordinates.
Parameters:
int i
The position to alter.
const Point3 &p
The value to set in absolute coordinates.
Prototype:
Point3 GetRelInVec(int i);
Remarks:
This method is available in release 2.0 and later only.
This method is used to retrieve the 'i-th' in vector position relative to the knot point.
Parameters:
int i
The postion to retrieve.
Prototype:
void SetRelInVec(int i, const Point3 &p);
Remarks:
This method is available in release 2.0 and later only.
This method sets the 'i-th' bezier in vector position relative to the knot point.
Parameters:
int i
The vector to set.
const Point3 &p
The vector data to set, relative to the knot point.
Prototype:
Point3 GetKnotPoint(int i);
Remarks:
This method is available in release 2.0 and later only.
This methods returns the 'i-th' knot point.
Parameters:
int i
Specifies which knot point to get.
Prototype:
void SetKnotPoint(int i, const Point3 &p);
Remarks:
This method is available in release 2.0 and later only.
This methods sets the 'i-th' knot point to the specified value.
Parameters:
int i
Specifies which knot point to set.
const Point3 &p
The value to set.
Prototype:
Point3 GetOutVec(int i);
Remarks:
This method is available in release 2.0 and later only.
This method is used to retrieve the 'i-th' out vector position in absolute coordinates.
Parameters:
int i
Specifies which out vector point to get.
Prototype:
void SetOutVec(int i, const Point3 &p);
Remarks:
This method is available in release 2.0 and later only.
This method is used to set the 'i-th' out vector position in absolute coordinates.
Parameters:
int i
Specifies which out vector point to get.
const Point3 &p
The out vector to set in absolute coordinates.
Prototype:
Point3 GetRelOutVec(int i);
Remarks:
This method is available in release 2.0 and later only.
This method is used to retrieve the 'i-th' out vector position relative to the knot point.
Parameters:
int i
Specifies the point to get.
Prototype:
void SetRelOutVec(int i, const Point3 &p);
Remarks:
This method is available in release 2.0 and later only.
This method is used to set the 'i-th' out vector position relative to the knot point.
Parameters:
int i
Specifies the point to set.
const Point3 &p
The out vector position to set relative to the knot point.
Get/SetVert() / Verts() / KnotPoint()
Prototype:
inline Point3& GetVert(int i);
Remarks:
Each control point is made up of three points. The in vector coming off the bezier control point, the knot point itself, and the out vector. There are these three points for every control point. This method will return any item in this list.
Parameters:
int i
The index into the vertex list.
Prototype:
inline void SetVert(int i, const Point3& p);
Remarks:
This method should not be used.
Prototype:
inline int Verts();
Remarks:
Returns the number of vertices. This is always the number of knots times 3.
Prototype:
int GetAux(int knot);
Remarks:
This method is available in release 2.0 and later only.
Returns the auxilliary data associated with the specified knot. This is used internally for tracking topological changes to the spline during editing. Developers can use it for temporary purposes but it will be altered by the EditableSpline (SplineShape) code.
Parameters:
int knot
The knot to retrieve the data from.
Prototype:
void SetAux(int knot, int value);
Remarks:
This method is available in release 2.0 and later only.
Sets the first integer auxilliary data associated with the specified knot.
Parameters:
int knot
Specifies the knot to whose auxilliary data is set.
int value
The value to set.
Prototype:
int GetAux2(int knot);
Remarks:
This method is available in release 2.0 and later only.
Returns the second integer auxilliary data associated with the specified knot
Parameters:
int knot
The knot to retrieve the data from.
Prototype:
void SetAux2(int knot, int value);
Remarks:
This method is available in release 2.0 and later only.
Sets the second integer auxilliary data associated with the specified knot.
Parameters:
int knot
Specifies the knot to whose auxilliary data is set.
int value
The value to set.
Prototype:
int GetAux3(int knot);
Remarks:
This method is available in release 3.0 and later only.
Returns the third integer auxilliary data associated with the specified knot. This field is available for any use.
Parameters:
int knot
Specifies the knot to whose auxilliary data is returned.
Prototype:
void SetAux3(int knot, int value);
Remarks:
This method is available in release 3.0 and later only.
Sets the third integer auxilliary data associated with the specified knot. This field is available for any use.
Parameters:
int knot
Specifies the knot whose auxilliary data is set.
int value
The value to set.
Prototype:
int GetKnotAux(int knot, int which);
Remarks:
This method is available in release 3.0 and later only.
Returns the specified integer auxilliary data associated with the specified knot.
Parameters:
int knot
Specifies the knot whose auxilliary data is returned.
int which
Specifies which auxiliary field. One of the following values:
0=aux1
1=aux2
2=aux3
Prototype:
void SetKnotAux(int knot, int which, int value);
Remarks:
This method is available in release 3.0 and later only.
Sets the specified integer auxilliary data associated with the specified knot.
Parameters:
int knot
Specifies the knot whose auxilliary data is set.
int which
Specifies which auxiliary field. One of the following values:
0=aux1
1=aux2
2=aux3
int value
The value to set.
Prototype:
int GetInAux(int knot, int which);
Remarks:
This method is available in release 3.0 and later only.
Returns the specified integer auxilliary data associated with the specified in vector.
Parameters:
int knot
Specifies the knot whose auxilliary data is returned.
int which
Specifies which auxiliary field. One of the following values:
0=aux1
1=aux2
2=aux3
Prototype:
void SetInAux(int knot, int which, int value);
Remarks:
This method is available in release 3.0 and later only.
Sets the specified integer auxilliary data associated with the specified in vector.
Parameters:
int knot
Specifies the knot whose auxilliary data is set.
int which
Specifies which auxiliary field. One of the following values:
0=aux1
1=aux2
2=aux3
int value
The value to set.
Prototype:
int GetOutAux(int knot, int which);
Remarks:
This method is available in release 3.0 and later only.
Returns the specified integer auxilliary data associated with the specified out vector.
Parameters:
int knot
Specifies the knot whose auxilliary data is returned.
int which
Specifies which auxiliary field. One of the following values:
0=aux1
1=aux2
2=aux3
Prototype:
void SetOutAux(int knot, int which, int value);
Remarks:
This method is available in release 3.0 and later only.
Sets the specified integer auxilliary data associated with the specified out vector.
Parameters:
int knot
Specifies the knot whose auxilliary data is set.
int which
Specifies which auxiliary field. One of the following values:
0=aux1
1=aux2
2=aux3
int value
The value to set.
Prototype:
int GetVertAux(int i, int which);
Remarks:
This method is available in release 3.0 and later only.
Returns the specified integer auxilliary data associated with the specified bezier vertex.
Parameters:
int i
The zero based bezier vertex index.
int which
Specifies which auxiliary field. One of the following values:
0=aux1
1=aux2
2=aux3
Prototype:
void SetVertAux(int i, int which, int value);
Remarks:
This method is available in release 3.0 and later only.
Sets the specified integer auxilliary data associated with the specified bezier vertex.
Parameters:
int i
The zero based bezier vertex index.
int which
Specifies which auxiliary field. One of the following values:
0=aux1
1=aux2
2=aux3
int value
The value to set.
Prototype:
MtlID GetMatID(int seg);
Remarks:
This method is available in release 3.0 and later only.
Returns the material ID for the specified spline segment.
Parameters:
int seg
The zero based index of the segment.
Prototype:
void SetMatID(int seg, MtlID id);
Remarks:
This method is available in release 3.0 and later only.
Sets the material ID for the specified spline segment.
Parameters:
int seg
The zero based index of the segment.
MtlID id
The material ID to set.
Prototype:
void GetSmoothingMap(IntTab &map);
Remarks:
This method is available in release 3.0 and later only.
This method allows this Spline3D to create a map of smoothing groups that eases the creation of meshes.
It fills in a developer supplied IntTab with smoothing groups for each segment of the spline. A spline with 4 segments will cause the IntTab to be set to 4 entries, for example.
Five smoothing groups are used for this operation, 1<<0 through 1<<4. Once you have them, you can shift them as needed for your application. The smoothing groups are set up so that segments connected by knots with KTYPE_SMOOTH or KTYPE_BEZIER types are smoothed together.
Parameters:
IntTab &map
A table of integers. See Template Class Tab.
Reverse() / Append() / Prepend()
Prototype:
void Reverse(BOOL keepZero = FALSE, BOOL weldCoincidentFirstVertex=TRUE);
Remarks:
This method reverses all the points of the spline.
Parameters:
BOOL keepZero = FALSE
This optional parameter is available in release 2.0 and later only.
This parameter defaults to FALSE in order to retain backwards compatibility. Setting it to TRUE insures that a closed spline will have the same vertex as its first point when it is reversed. The parameter is ignored on open splines.
BOOL weldCoincidentFirstVertex=TRUE
Set this to TRUE to weld coincident first vertices. FALSE to disable welding.
Prototype:
void Append(Spline3D *spline, BOOL weldCoincidentFirstVertex=TRUE);
Remarks:
This method appends the specified spline onto the end of this one. The splines should both be opened.
Parameters:
Spline3D *spline
The spline to append.
BOOL weldCoincidentFirstVertex=TRUE
Set this to TRUE to weld coincident first vertices. FALSE to disable welding.
Prototype:
void Prepend(Spline3D *spline);
Remarks:
This method takes the specified spline and puts it on the front of this spline.
Parameters:
Spline3D *spline
The spline to prepend.
IsClockWise() / SelfIntersects() / IntersectsSpline() / SurroundsPoint() / SplineLength()
Prototype:
BOOL IsClockWise();
Remarks:
Returns TRUE if the spline is clockwise in the XY plane (it ignores Z); otherwise FALSE. This call is meaningless if the shape self intersects.
Prototype:
BOOL SelfIntersects();
Remarks:
Returns TRUE if the spline intersects itself in the XY plane (it ignores Z); otherwise FALSE.
Prototype:
BOOL IntersectsSpline(Spline3D *spline);
Remarks:
Returns TRUE if this spline intersects the specified spline in the XY plane (it ignores Z); otherwise FALSE.
Parameters:
Spline3D *spline
The spline to check.
Prototype:
BOOL SurroundsPoint(Point2 p);
Remarks:
Returns TRUE if the specified point is surrounded (contained within) this spline.
Parameters:
Point2 p
The point to check.
Prototype:
float SplineLength();
Remarks:
Returns the length of the spline.
Prototype:
float SegmentLength(int seg);
Remarks:
This method is available in release 3.0 and later only.
Returns the length of the specified segment of this spline.
Parameters:
int seg
The zero based index of the segment to check.
Prototype:
void MakePolyLine(PolyLine &line, int steps = -1, BOOL optimize = FALSE);
Remarks:
This creates a PolyLine from this spline given a steps setting and an optimize parameter.
Note the following constraints on this method. When a ShapeObject is asked to output a PolyShape with a given number of steps and FALSE is specified for optimization, it must output a PolyLine with [steps * pieces + pieces + 1] vertices if it's an open shape and [steps * pieces + pieces] vertices if it's closed.
Parameters:
PolyLine &line
The result is stored here.
int steps = -1
The number of steps between knots in the spline.
BOOL optimize = FALSE
If TRUE, linear segments between control points in the spline will not generate steps in between. It will just be one line segment.
Prototype:
void Dump(int where);
Remarks:
This displays data about the specified knot using DebugPrints(). See Debugging.
Parameters:
int where
The index of the knot.
Internal Methods / Methods that should not be used by plug-in developers
Prototype:
int ShiftKnot(int where, int direction);
Remarks:
This method is used internally.
Prototype:
Point3 AverageTangent(int i);
Remarks:
This method should not be used.
Prototype:
void MakeBezCont(int i);
Remarks:
This method should not be used.
Prototype:
void RedistTangents(int i, Point3 d);
Remarks:
This method should not be used.
Prototype:
void FixAdjBezTangents(int i);
Remarks:
This method should not be used.
Prototype:
void DrawCurve(GraphicsWindow *gw, Material *mtl);
Remarks:
This method should not be used.
Prototype:
inline void SetEditMode(int mode);
Remarks:
This method should not be used.
Prototype:
IPoint2 ProjectPoint(ViewExp *vpt, Point3 fp, Matrix3 *mat);
Remarks:
This method is used internally.
Prototype:
Point3 UnProjectPoint(ViewExp *vpt, IPoint2 p, Matrix3 *mat);
Remarks:
This method is used internally.
Prototype:
void Snap(GraphicsWindow *gw, SnapInfo *snap, IPoint2 *p, Matrix3 &tm);
Remarks:
This method is used internally.
Prototype:
IOResult Save(ISave *isave);
Remarks:
This method is used internally to save the class data from disk.
Prototype:
IOResult Load(ILoad *iload);
Remarks:
This method is used internally to load the class data from disk.
Prototype:
Point3 GetDragVector(ViewExp *vpt,IPoint2 p,int i,Matrix3* mat);
Remarks:
This method is used internally.
Prototype:
int AppendPoint(ViewExp *vpt,const Point3& p, int where = -1);
Remarks:
This method is used internally.
Prototype:
int DrawPhase();
Remarks:
This method is used internally.
Prototype:
int GetiCur();
Remarks:
This method is used internally.
Prototype:
inline int ParmType()
Remarks:
This method is used internally.
Prototype:
int SetParam(int index,float param);
Remarks:
This method is used internally.
Prototype:
float GetParam(int index);
Remarks:
This method is used internally.
Prototype:
virtual void CustomParams()
Remarks:
This method is used internally.
Prototype:
void CompParams();
Remarks:
This method is used internally.
Prototype:
Spline3D& operator=(Spline3D& fromSpline);
Remarks:
Assignment operator.
Prototype:
Spline3D& operator=(PolyLine& fromLine);
Remarks:
Assignment operator. This generates a PolyLine from the spline, where points are added in between the knots on the spline. For example if the steps value was 5, it will interpolate 5 points in between each knot on the spline.