Class PolyLine

3DS Max Plug-In SDK

Class PolyLine

See Also: Class PolyPt, Class PolyShape.

class PolyLine

Description:

This class describes a single polygon in a PolyShape using linear segments. 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:

Constructors / Destructor / Init() / GetMatID()

Opened/Closed/Self Intersects/Clockwise/Surrounds Point/SetNumPts()/CurveLength()

SpliceLine() / HitsSegment() / HitsPolyLine()

Vertex / Segment counts

Append / Insert / Delete / Reverse()

Bounding Box / InvalidateGeomCache()

Render / Select / Snap / Transform

Interpolated Points / Tangent Vectors

Capping Methods

Dump()

Operators

Data Members:

public:

int numPts;

The number of points in the polyline.

PolyPt *pts;

The points themselves.

DWORD flags;

PolyLine flags. One or more of the following values:

POLYLINE_CLOSED

Indicates the polyline is closed.

POLYLINE_NO_SELF_INT

Ignore self-intersections. This is used internally in the patch capping to indicate that this line always returns FALSE from the self intersects test. Normally this should not be set.

Box3 bdgBox;

The bounding box of the polyline.

float cachedLength;

The length of the polyline.

float *lengths;

Cached lengths for each point

float *percents;

Cached percentages for each point

BOOL cacheValid;

Indicates if the cache is valid.

Methods:

Constructors / Destructor / Init / GetMatID()

Prototype:

PolyLine();

Remarks:

Constructor. The number of points is set to zero, the points array is set to NULL, the flags are set to 0, the cache validity is set to FALSE and the bounding box is set to empty.

Prototype:

PolyLine(PolyLine& from);

Remarks:

Constructor. The PolyLine is initialized using from.

Prototype:

~PolyLine();

Remarks:

Destructor. The array of points is freed.

Prototype:

void Init();

Remarks:

Initializes the PolyLine. The pts array is freed, the number of points is set to 0, and the cache validity is set to FALSE.

Prototype:

MtlID GetMatID(int segment);

Remarks:

This method is available in release 3.0 and later only.

Returns the material ID for the specified segment.

Parameters:

int segment

The zero based index of the segment.

Opened / Closed / Self Intersects / Clockwise / Surrounds Point / SetNumPts()

Prototype:

void Close();

Remarks:

Call this method to indicate the polyline is closed.

Prototype:

BOOL IsClosed();

Remarks:

Returns TRUE if the polyline is closed; otherwise FALSE.

Prototype:

void Open();

Remarks:

Call this method to indicate the polyline is open.

Prototype:

BOOL IsOpen();

Remarks:

Returns TRUE if the polyline is open; otherwise FALSE.

Prototype:

void SetNoSelfInt();

Remarks:

Call this method to set the self intersects flag. This is used in the patch capping to indicate that this line always returns FALSE from the self intersects test. Normally this should not be set.

Prototype:

BOOL IsNoSelfInt()

Remarks:

Returns TRUE if the no self intersect flag is set; otherwise FALSE.

Prototype:

BOOL IsClockWise();

Remarks:

Returns TRUE if the polyline is clockwise in the XY plane (it ignores Z); otherwise FALSE. If the PolyLine self intersects, the results from this method are meaningless.

Prototype:

BOOL SelfIntersects(BOOL findAll = FALSE, IntersectionCallback3D *cb = NULL);

Remarks:

Returns TRUE if the polyline intersects itself in the XY plane (it ignores Z); otherwise FALSE.

Parameters:

BOOL findAll = FALSE

TRUE to find all self intersections. FALSE to find only the first self intersection.

IntersectionCallback3D *cb = NULL

A pointer to an IntersectionCallback3D class.

Prototype:

float CurveLength();

Remarks:

Returns the length of the PolyLine.

Prototype:

BOOL SurroundsPoint(Point2 &point);

Remarks:

Returns TRUE if the specified point is surrounded (contained within) this spline. This method should only be called on closed PolyLines.

Parameters:

Point2 &point

The point to check.

Vertex / Segment counts

Prototype:

int Verts()

Remarks:

Returns the number of vertices (points) in the polyline.

Prototype:

int Segments();

Remarks:

Returns the number of segments (edges between vertices) of the polyline.

Prototype:

BOOL SetNumPts(int count, BOOL keep = TRUE);

Remarks:

Sets the number of points in the polyline.

Parameters:

int count

The number to set.

BOOL keep = TRUE

If TRUE any existing points are copied to the new array; otherwise they are freed.

Return Value:

TRUE if the number of points was set; otherwise FALSE.

Append() / Insert() / Delete() / Reverse()

Prototype:

void Append(PolyPt& p);

Remarks:

Appends the specified point to the polyline. This adds the point to the end of the points list.

Parameters:

PolyPt& p

The point to append.

Prototype:

void Insert(int where, PolyPt& p);

Remarks:

Inserts the specified point at the location passed.

Parameters:

int where

The pts array index indicating where to insert the point.

PolyPt& p

The point to insert.

Prototype:

void Delete(int where);

Remarks:

Deletes the specified point.

Parameters:

int where

The pts array index indicating which point to delete.

Prototype:

void Reverse(BOOL keepZero=FALSE);

Remarks:

Reverses the order of the points in the polyline.

Parameters:

BOOL keepZero=FALSE

This should normally be passed as TRUE. If TRUE, and the polyline is closed, this method will make sure that vertex zero is the same on the reversed version as on the non-reversed version. Otherwise if passed as FALSE the last vertex becomes the first vertex, and the first vertex becomes the last. This is an important distinction for the lofter because it always wants vertex zero to be in the same place.

Bounding Box / InvalidateGeomCache()

Prototype:

void BuildBoundingBox();

Remarks:

Computes the bounding box of the polyline. The result is stored in the bdgBox data member.

Prototype:

Box3 GetBoundingBox(Matrix3 *tm=NULL);

Remarks:

Returns the bound box of the polyline. The optional TM allows the box to be calculated in any space.

Parameters:

Matrix3 *tm=NULL

The points of the polyline are multiplied by this matrix before the box computation.

Prototype:

void InvalidateGeomCache();

Remarks:

This method makes sure the PolyLine has flushed out any cached data it may have had. This resets the bounding box size and sets the cache validity to FALSE. This should be called when any points have been changed in the polyline.

Render / Select / Snap / Transform

Prototype:

void Render(GraphicsWindow *gw, Material *ma, RECT *rp, int compFlags, int numMat);

Remarks:

This method is used internally.

Prototype:

void Render(GraphicsWindow *gw, Material *ma, in numMat, BOOL colorSegs, BitArray &segsel);

Remarks:

This method is used internally.

Prototype:

BOOL Select(GraphicsWindow *gw, Material *ma, HitRegion *hr,

int abortOnHit = FALSE);

Remarks:

This method is used internally.

Prototype:

void Snap(GraphicsWindow *gw, SnapInfo *snap, IPoint2 *p, Matrix3 &tm, DWORD flags);

Remarks:

This method is used internally.

Prototype:

void Transform(Matrix3 &tm);

Remarks:

Transforms the points of the polyline by the specified matrix.

Parameters:

Matrix3 &tm

The matrix to transform the points.

Dump()

Prototype:

void Dump(TCHAR *title = NULL);

Remarks:

You may call this method to dump the polyline structure via DebugPrint(). See Debugging.

Parameters:

TCHAR *title = NULL

This title string is displayed using a DebugPrint() before the rest of the data.

Splice() / HitsSegment() / HitsPolyLine()

Prototype:

void SpliceLine(int where, PolyLine &source, int splicePoint);

Remarks:

This method is used internally as part of the capping mechanism and should not be used.

Prototype:

BOOL HitsSegment(Point2 p1, Point2 p2, BOOL findAll=FALSE, IntersectionCallback3D *cb = NULL);

Remarks:

Returns TRUE if the line segment defined between points p1 and p2 intersects this PolyLine; otherwise FALSE.

Parameters:

Point2 p1, Point2 p2

The endpoints of the line to check.

BOOL findAll=FALSE

TRUE to find all intersections. FALSE to find only the first intersection.

IntersectionCallBack3D *cb = NULL

A pointer to an IntersectionCallback3D class.

Prototype:

BOOL HitsPolyLine(PolyLine &line, BOOL findAll=FALSE, IntersectionCallback3D *cb = NULL);

Remarks:

Returns TRUE if the specified PolyLine intersects this PolyLine; otherwise FALSE.

Parameters:

PolyLine &line

The PolyLine to check

BOOL findAll=FALSE

TRUE to find all intersections. FALSE to find only the first intersection.

IntersectionCallBack3D *cb = NULL

A pointer to an IntersectionCallback3D class.

Capping Methods

Prototype:

int Cap3DS(CapVert *capverts, MeshCapInfo &capInfo, DWORD options = 0);

Remarks:

This method is used internally.

Interpolated Points / Tangent Vectors

Prototype:

Point3 InterpPiece3D(int segment, float t);

Remarks:

This method returns a point interpolated on a segment between two points.

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 point and 1 is the second point.

Return Value:

The interpolated point.

Prototype:

Point3 InterpCurve3D(float u, int ptype=POLYSHP_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.

Parameters:

float u

A value in the range of 0.0 to 1.0 for the entire curve.

int ptype=POLYSHP_INTERP_SIMPLE

This parameter is available in release 2.0 and later only.

The parameter type for interpolation. The default value is based on segments (rather than the entire curve). See List of Parameter Types for PolyLine Interpolation.

Return Value:

The interpolated point.

Prototype:

Point3 TangentPiece3D(int segment, float t);

Remarks:

This method returns a tangent vector interpolated on a segment between two points.

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 point and 1 is the second point.

Return Value:

The tangent vector.

Prototype:

Point3 TangentCurve3D(float u, int ptype=POLYSHP_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=POLYSHP_INTERP_SIMPLE

This parameter is available in release 2.0 and later only.

The parameter type for interpolation. The default value is based on segments (rather than the entire curve). See List of Parameter Types for PolyLine Interpolation.

Return Value:

The tangent vector.

Operators:

Prototype:

PolyLine& operator=(PolyLine& from);

Remarks:

Assignment operator.

Prototype:

PolyLine& operator=(Spline3D& from);

Remarks:

Assignment operator. This generates a polyline from the spline.

Prototype:

PolyPt& operator[](int index);

Remarks:

Array access operator. Returns the specified point in the pts array.