Class Patch

3DS Max Plug-In SDK

Class Patch

See Also: Class PatchMesh, Class TVPatch, Working with Patches.

class Patch : public BaseInterfaceServer

Description:

A PatchMesh is made up of a series of Patch objects derived from this class. This is similar to the way faces relate to a mesh. All methods of this class are implemented by the system.

Data Members:

public:

int type;

The patch type. One of the following values:

PATCH_UNDEF

Undefined.

PATCH_TRI

Triangular patch.

PATCH_QUAD

Quadrilateral patch.

int v[4];

A patch can have three or four vertices based on the type. The corner vertices on a patch are referred to as a, b, c, (and if it's a quad patch d). These are ordered a, b, c, d going counter-clockwise around the patch.

int vec[8];

A patch can have six or eight vector points. The vectors are referred to as follows: ab is the vector coming out of vertex a towards b. ba is the one coming out of b towards a. bc is the vector coming out of b towards c. cb is the one coming out of c towards b, and so on.

int interior[4];

A patch can have three or four interior vertices.

Point3 aux[9];

This is used internally for triangular patches only (degree 4 control points).

int edge[4];

Pointers into the edge list. There can be three or four depending on the patch type.

DWORD smGroup;

The smoothing group. This defaults to 1. All patches are smoothed in a PatchMesh.

DWORD flags;

Patch Flags. The following value may be set.

PATCH_AUTO

Interior vertices are computed automatically if this flag is set (and normally it is set). An example of when this flag would not be set is if you were creating a primitive using patches that needed to make special interior control points to create the shape. In this case you'd clear this flag and then put whatever values you needed into the vec array.

PATCH_HIDDEN

The patch is hidden.

PATCH_LINEARMAPPING

This option is available in release 4.0 and later only.

The patch is using the old linear mapping scheme.

PATCH_USE_CRUVED_MAPPING_ON_VERTEX_COLOR

This option is available in release 4.0 and later only.

The patch is using the new curved mapping for vertex colors also.

int aux1;

This data member is available in release 3.0 and later only.

This is used to track topology changes during editing (Edit Patch).

int aux2;

This data member is available in release 3.0 and later only.

This is used to track topology changes during editing (PatchMesh).

Methods:

Prototype:

Patch();

Remarks:

Constructor. The type is set to undefined, the smooth group is set to 1, and the flags indicate automatic interior points. Note: This constructor does not allocate arrays. Use SetType(type).

Prototype:

Patch(Patch& fromPatch);

Remarks:

Constructor. The this pointer is set to the fromPatch.

Prototype:

~Patch();

Remarks:

Destructor.

Prototype:

void Init();

Remarks:

This method is used by the constructors internally. Developers should not call this method.

Prototype:

void setVerts(int *vrt);

Remarks:

The vertices are copied from the array passed. Based on the patch type either three or four vertices are copied.

Parameters:

int *vrt

The vertices are set to these values. These values are indices into the v array.

Prototype:

void setVerts(int a, int b, int c);

Remarks:

Sets the vertices for Tri Patch to those passed.

Parameters:

int a, int b, int c

The vertices to set. v[0]=a; v[1]=b; v[2]=c; These values are indices into the v array.

Prototype:

void setVerts(int a, int b, int c, int d)

Remarks:

Sets the vertices for a Quad Patch to those passed.

Parameters:

int a, int b, int c, int d

The vertices to set. v[0]=a; v[1]=b; v[2]=c; v[3] = d; These values are indices into the v array.

Prototype:

void setVecs(int ab, int ba, int bc, int cb, int ca, int ac)

Remarks:

Sets the vectors for a Tri Patch to those passed.

Parameters:

int ab, int ba, int bc, int cb, int ca, int ac;

The vectors to set. vec[0]=ab; vec[1]=ba; vec[2]=bc;

vec[3]=cb; vec[4]=ca; vec[5]=ac; These values are indices into the vec array.

Prototype:

void setVecs(int ab, int ba, int bc, int cb, int cd,

int dc, int da, int ad)

Remarks:

Sets the vectors for a Quad patch to those passed.

Parameters:

int ab, int ba, int bc, int cb,

int cd, int dc, int da, int ad ;

The vectors to set. vec[0]=ab; vec[1]=ba; vec[2]=bc; vec[3]=cb;

vec[4]=cd; vec[5]=dc; vec[6]=da, vec[7]=ad; These values are indices into the vec array.

Prototype:

void setInteriors(int a, int b, int c)

Remarks:

Sets the interior vertex values for a Tri Patch.

Parameters:

The interior values to set: interior[0]=a; interior[1]=b; interior[2]=c; These values are indices into the interior array.

Prototype:

void setInteriors(int a, int b, int c, int d)

Remarks:

Sets the interior vertex values for a Tri Patch.

Parameters:

int a, int b, int c, int d

The interior values to set: interior[0]=a; interior[1]=b; interior[2]=c; interior[3]=d; These values are indices into the interior array.

Prototype:

int getVert(int index);

Remarks:

Returns the vertex specified by the index.

Parameters:

int index

The vertex to retrieve. This value may be 0, 1, 2 (or 3 if it's a quad patch).

Prototype:

int *getAllVerts(void);

Remarks:

Returns a pointer to the vertex array.

Prototype:

int WhichEdge(int v1, int v2);

Remarks:

This method is available in release 4.0 and later only.

This method provides an easy way to find out which edge of a patch uses two vertices. Simply supply the two vertices of the desired edge and call this method.

Parameters:

int v1, int v2

The index of the two vertices.

Return Value:

The index of the edge within the patch (0 - 2 for triangular patches, 0 - 3 for quad patches).

CAUTION: Be sure to check the return value before using it for an index – If the two vertices supplied are not used as an edge on this patch, -1 is returned.

Prototype:

int WhichVert(int v);

Remarks:

This method is available in release 4.0 and later only.

This method provides an easy way to find out which corner of a patch uses a given vertex. Simply supply the vertex index and call this method.

Parameters:

int v

The index of the vertex.

Return Value:

The corner index of the given vertex within the patch (0 - 2 for triangular patches, 0 - 3 for quad patches).

CAUTION: Be sure to check the return value before using it for an index – If the vertex supplied is not used as a corner on this patch, -1 is returned.

Prototype:

Point3 interp(PatchMesh *pMesh, float u, float v);

Remarks:

Quadrilateral patch interpolator. This method returns a point on the surface of the patch based on the specified u and v values.

Parameters:

PatchMesh *pMesh

Points to the PatchMesh to interpolate.

float u

The u value in the range 0.0 to 1.0. This defines the distance along one axis of the patch.

float v

The v value in the range 0.0 to 1.0. This defines the distance along the other axis of the patch.

Return Value:

A point on the surface of the patch.

Prototype:

Point3 interp(PatchMesh *pMesh, float u, float v, float w);

Remarks:

Triangle patch interpolator. This method returns a point on the surface of the patch based on the specified u, v and w values. The u, v, w values are barycentric coordinates. u+v+w = 1.0. If u is 1, and v and w are 0, the point is at the first vertex. If u is 0, v is 1, and w is 0, then the point is at the second vertex. If u and v are 0 and w is 1 then the point is at the third vertex. Varying positions between these values represent different positions on the patch.

Parameters:

PatchMesh *pMesh

Points to the PatchMesh to interpolate.

float u, float v, float w

The barycentric coordinates.

Return Value:

A point on the surface of the patch.

Prototype:

void ComputeAux(PatchMesh *pMesh, int index);

Remarks:

This method is used internally. It compute the degree-4 alias control points.

Prototype:

void computeInteriors(PatchMesh* pMesh);

Remarks:

Whenever you are done working on a PatchMesh, this method should be called. If the interior vertices of the patch are automatic it will update them to correctly match the changes to the other vectors. This computes interior vertices considering this patch only.

Parameters:

PatchMesh* pMesh

Points to the PatchMesh to compute the interior vertices of.

Prototype:

void SetType(int type, BOOL init = FALSE);

Remarks:

Sets the type of the patch to either Tri or Quad and optionally resets the arrays.

Parameters:

int type

The patch type. One of the following values:

PATCH_TRI - Triangular Patch

PATCH_QUAD - Quadrilateral Patch

BOOL init = FALSE

If TRUE the arrays are reset to undefined; otherwise they are left unchanged. Normally this is set to FALSE.

Prototype:

void SetAuto(BOOL sw = TRUE);

Remarks:

Sets the flag controlling if interior vertices are computed automatically.

Parameters:

BOOL sw = TRUE

TRUE to set; FALSE to clear.

Prototype:

BOOL IsAuto();

Remarks:

Returns TRUE if the PATCH_AUTO flag is set; otherwise FALSE.

Prototype:

void SetHidden(BOOL sw = TRUE);

Remarks:

This method is available in release 3.0 and later only.

Sets the hidden state of the patch.

Parameters:

BOOL sw = TRUE

TRUE to hide; FALSE to unhide.

Prototype:

BOOL IsHidden();

Remarks:

This method is available in release 3.0 and later only.

Returns TRUE if the patch is hidden; otherwise FALSE.

Prototype:

void Dump();

Remarks:

This may be called to dump the patch mesh structure via DebugPrint(). See Debugging.

Operators:

Prototype:

Patch& operator=(Patch& from);

Remarks:

Assignment operator.

Parameters:

Patch& from

The patch to copy from.