Class Face

3DS Max Plug-In SDK

Class Face

See Also: Class Mesh.

class Face

Description:

This class represents a single triangular face. The class maintains three indices into the vertex list for the face, a 32-bit smoothing group for the face, and 32-bits of face flags. The flags also store information about the visibility of the face, the visibility of the three edges, and whether or not the face has texture vertices present. The most significant 16-bits of the face flags store the material index. All methods of this class are implemented by the system.

Data Members:

public:

DWORD v[3];

These are 0 based indices into a mesh object's array of vertices.

DWORD smGroup;

Smoothing group bits for the face.

Each bit of this 32 bit value represents membership in a smoothing group. The least significant bit represents smoothing group #1 while the most significant bit represents group #32. If two adjacent faces are assigned the same smoothing group bit, the edge between them is rendered smoothly.

DWORD flags;

The Face Flags:

Edge visibility bits: If the bit is 1, the edge is visible.

EDGE_A

EDGE_B

EDGE_C

EDGE_ALL (EDGE_A|EDGE_B|EDGE_C)

Face visibility bit: If the bit is 1, the face is hidden.

FACE_HIDDEN

Texture vertices bit: If the bit is 1, texture vertices are present. FROM R5 THIS IS NOW OBSOLETE. YOU CAN USE MAPSUPPORT METHODS INSTEAD

HAS_TVERTS

The material ID is stored in the HIWORD of the face flags.

FACE_MATID_SHIFT

This is the number of bits to shift the flags to access the material.

FACE_MATID_MASK

This is a mask used to access the material ID.

Methods:

Prototype:

Face()

Remarks:

Constructor. The smoothing groups and face flags are initialized to zero.

Prototype:

MtlID getMatID()

Remarks:

Retrieves the zero based material ID for this face. Note: typedef unsigned short MtlID;

Prototype:

void setMatID(MtlID id)

Remarks:

Sets the material ID for this face.

Parameters:

MtlID id

Specifies the zero based material index.

Prototype:

void setSmGroup(DWORD i)

Remarks:

Sets the smoothing group bits for this face.

Parameters:

DWORD i

Specifies the smoothing group bits for this face.

Prototype:

DWORD getSmGroup()

Remarks:

Returns the smoothing group bits for this face.

Prototype:

void setVerts(DWORD *vrt)

Remarks:

Sets the vertices of this face.

Parameters:

DWORD *vrt

An array of the 3 vertices to store. These are zero based indices into the mesh object's array of vertices.

Prototype:

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

Remarks:

Sets the vertices of this face. The specified indexes are zero based indices into the mesh object's array of vertices.

Parameters:

int a

Specifies the first vertex.

int b

Specifies the second vertex.

int c

Specifies the third vertex.

Prototype:

void setEdgeVis(int edge, int visFlag);

Remarks:

Sets the visibility of the specified edge.

Parameters:

int edge

Specifies the edge to set the visibility of. You may use 0, 1, or 2.

int visFlag

One of the following values:

EDGE_VIS

Sets the edge as visible.

EDGE_INVIS

Sets the edge as invisible.

Prototype:

void setEdgeVisFlags(int va, int vb, int vc);

Remarks:

Sets the visibility of the all the edges.

Parameters:

int va

Specifies the visibility for edge 0. Use either EDGE_VIS or EDGE_INVIS.

int vb

Specifies the visibility for edge 1. Use either EDGE_VIS or EDGE_INVIS.

int vc

Specifies the visibility for edge 2. Use either EDGE_VIS or EDGE_INVIS.

Prototype:

int getEdgeVis(int edge)

Remarks:

Retrieves the edge visibility for the specified edge.

Parameters:

int edge

Specifies the edge.

Return Value:

Nonzero if the edge is visible, zero if the edge is invisible.

Prototype:

DWORD getVert(int index)

Remarks:

Returns the index into the mesh vertex array of the specified vertex.

Parameters:

int index

Specifies the vertex to retrieve. You may use 0, 1 or 2.

Prototype:

DWORD *getAllVerts()

Remarks:

Retrieves a pointer to the vertex array.

Return Value:

A pointer to the vertex array.

Prototype:

BOOL Hidden()

Remarks:

Determines if the face is hidden or visible.

Return Value:

TRUE if the face is hidden; otherwise FALSE.

Prototype:

void Hide()

Remarks:

Hides this face (makes it invisible in the viewports).

Prototype:

void Show()

Remarks:

Shows this face (makes it visible in the viewports).

Prototype:

void SetHide(BOOL hide)

Remarks:

Sets the hidden state of this face.

Parameters:

BOOL hide

Specifies the hidden state for the face. Pass TRUE to hide the face; FALSE to show it.

Prototype:

DWORD GetOtherIndex(DWORD v0, DWORD v1);

Remarks:

This method is available in release 3.0 and later only.

Returns the first vertex in the face that isn't v0 or v1.

Parameters:

DWORD v0

The zero based index of one of the vertices to check.

DWORD v1

The zero based index of the other vertex to check.

Return Value:

The zero based index of the vertex found in the Mesh's vertex list.

Prototype:

DWORD GetEdgeIndex(DWORD v0, DWORD v1);

Remarks:

This method is available in release 3.0 and later only.

Returns the index of the edge in the face that goes from v0 to v1, or v1 to v0.

Parameters:

DWORD v0

The zero based index of the vertex at one end of the edge.

DWORD v1

The zero based index of the vertex at the other end of the edge.

Return Value:

The zero based index of the edge found in the Fesh's edge list.

 

Prototype:

int Direction(DWORD v0, DWORD v1);

Remarks:

This method is available in release 3.0 and later only.

Indicates order in which vertices v0 and v1 appear in the face.

Parameters:

DWORD v0

One vertex on this face.

DWORD v1

Another vertex on this face.

Return Value:

1 if v1 follows v0 in sequence (This includes e.g. when Face::v[2] == v0 and Face::v[0] == v1.)

-1 if v0 follows v1 in sequence

0 if v0 or v1 are not on the face.

Prototype:

DWORD GetVertIndex(DWORD v0);

Remarks:

This method is available in release 3.0 and later only.

Returns the index of the specified vertex in this face's vertex list (0, 1 or 2). If not found 3 is returned.

Parameters:

DWORD v0

The zero based index of the vertex to check.

Prototype:

void OrderVerts(DWORD &v0, DWORD &v1);

Remarks:

This method is available in release 3.0 and later only.

This method switches v0,v1 if needed to put them in face-order. If v0 and v1 are in the order in which they appear in the face, or if one or both of them are not actually on the face, nothing happens. If however v0 follows v1, the values of the parameters are switched, so that they are then in the correct order for this face.

Parameters:

DWORD &v0

One vertex on this face.

DWORD &v1

Another vertex on this face.

Sample Code:

Face & f = mesh.faces[edge.f[0]];

DWORD v0 = edge.v[0];

DWORD v1 = edge.v[1];

// Switch v0, v1 if needed to match orientation in selected face.

f.OrderVerts(v0,v1);