Class Mesh

3DS Max Plug-In SDK

Class Mesh

See Also: Class BitArray, Class Face, Class TVFace, Class Point3, Class TriObject, Class RNormal, Class RVertex, Class TriObject, Class MeshMap, Working with Meshes, Class PerData.

class Mesh : public BaseInterfaceServer

Description:

The Mesh class is provided for use by plug-ins and is used by the system. It is the data structure for meshes in the system and maintains pointers to the vertices, faces, texture vertices, etc. It provides methods to handle most of the functionality that procedural objects must implement. All methods of this class are implemented by the system.

Note: There is a set of classes for working with parts of a mesh such as its face structure, element structure, and cluster structure. For details see: Class AdjEdgeList, Class AdjFaceList, Class FaceElementList, Class FaceClusterList.

Method Groups:

The hyperlinks below take you to the start of groups of related methods within the class:

Vertex Methods

Color Per Vertex Methods

Face Methods

Texture Vertex-Texture Face Methods

Multiple Map Support

Vertex Data Methods

Render, HitTest, Snap Methods

Bounding Box Methods

Edge Methods

Strips Methods

Mesh / Display Flags

Selection Access Methods

Data Flow Evaluation Methods

IntersectRay, Weld, Optimize, Apply Mapping Methods

Normals / Smoothing / Edges / Face check Functions

Boolean Operations / Combine Meshes

Sub-Object Selection Color Control

Operators

Data Members:

private:

MeshMap hmaps[NUM_HIDDENMAPS];

The "Hidden Maps". Eventually these will be supported by Patches and PolyMeshes, as well as in the general object interface. The purpose is to use a separate, private array for a fixed number of these maps (unlike the allocable regular map array). This allows us to reserve and support as many map channels as we need for features such as vertex alpha, vertex illumination, possible vertex normals, or other needs that may arise.

The interface for accessing these channels uses the usual map methods, with negative indices. For instance, hmaps[0] is indexed as MAP_SHADING, -1. hmaps[1] is indexed as MAP_ALPHA=-2. So now methods like Mesh::mapVerts (int mp) have a range of -NUM_HIDDENMAPS to getNumMaps(), instead of 0 to getNumMaps() as before.

NUM_HIDDENMAPS: The number of "Hidden" or negative-indexed maps in objects which support hidden maps. (Currently set to 2.)

MAP_SHADING: The shading (or illumination) map. Set to -1.

MAP_ALPHA: The Alpha channel map. Note that only the x (or u) coordinate of the map vertices is currently used. Set to -2.

public:

Topology Data

int numVerts;

Number of vertices.

int numFaces;

Number of faces.

Face *faces;

Array of faces.

Geometry Data

Point3 *verts;

Array of vertex coordinates.

Texture Coordinate Data

int numTVerts;

Number of texture vertices.

UVVert *tVerts;

The array of texture vertices. This stores the UVW coordinates. For a 2D mapping only two of them are used, i.e. UV, VW, or WU. This just provides greater flexibility so the user can choose to use UV, VW, or WU.

Note: typedef Point3 UVVert;

TVFace *tvFace;

The array of texture faces. There needs to be one TVFace for every face, but there can be three indices into the UVVert array that are any UVs. Each face of the object can have its own mapping.

int numMaps;

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

The number of maps supported by the mesh. By default this is 2 but may be changed with the multiple map methods listed below.

MeshMap *maps;

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

When the number of mapping channels is set to a value greater than 1 then an instance of this class is allocated for each channel up to numMaps. An instance maintains the mapping information for a single channel.

BitArray vdSupport;

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

This bit array indicates if a particular vertex data channel is supported in this mesh. If the bit is set the channel is suported.

PerData *vData;

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

The array of PerData objects which maintain and provide access to the floating point vertex data. There is one of these for each supported channel. The first two PerData objects in this array are used internally by 3ds max.

Color Per Vertex Data

int numCVerts;

Number of color vertices.

VertColor *vertCol;

Array of color vertices.

TVFace *vcFace;

Array of color per vertex faces.

VertColor *curVCArray;

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

Points to storage for a possible external color array (default = NULL). This can be either an external array or one of the mapping channels. See the method Mesh::setVCDisplayData();

int curVCChan;

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

Storage for the current mapping channel to use for vertex colors (default = 0).

VertColor *vertColArray;

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

When 3ds max is rendering the color values come from this variable. This array defaults to the internal vertCol but can be set to an external array, or a map channel. See the method Mesh:: setVCDisplayData ();

TVFace *vcFaceData;

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

When 3ds max is rendering the vertex color lookup comes from this structure. This defaults to the vcFace data but if a mapping channel is used for color lookup, its TVFace structure is used.

Selection Data

BitArray vertSel;

Indicates the selected vertices. There is one bit for each vertex. Bits that are 1 indicate the vertex is selected.

BitArray faceSel;

Indicates the selected faces. There is one bit for each face. Bits that are 1 indicate the face is selected.

BitArray edgeSel;

Indicates the selected edges. There is one bit for each edge of each face. Bits that are 1 indicate the edge is selected. The edge is identified by 3*faceIndex + edgeIndex.

BitArray vertHide;

Hidden flags for vertices.

Display attribute flags

DWORD dispFlags;

These control various aspect of the Mesh objects display and may be one or more of the following values:

DISP_VERTTICKS - Display vertices as small tick marks.

DISP_SELVERTS - Display selected vertices.

DISP_SELFACES - Display selected faces.

DISP_SELEDGES - Display selected edges.

DISP_SELPOLYS - Display selected polygons. Polygons are defined as adjacent triangles with hidden edges. A selected face would show all edges regardless of if they were hidden edges. A polygon would only show the edges of the polygon that were not hidden.

Selection level

DWORD selLevel;

This is the current level of selection. When all the bits are 0, the object is at object level selection. The selection level bits are:

MESH_OBJECT - Object level.

MESH_VERTEX - Vertex level.

MESH_FACE - Face level.

MESH_EDGE - Edge level.

Normals

int normalsBuilt;

Nonzero if normals have been built for the current mesh; otherwise 0.

Render Data

MeshRenderData *renderData;

Points to the render data used by the renderer.

Methods:

Prototype:

Mesh();

Remarks:

Constructor. Initializes the mesh object. The mesh counts are set to 0 and its pointers are set to NULL.

Prototype:

Mesh(const Mesh& fromMesh);

Remarks:

Constructor. The mesh is initialized equal to fromMesh.

Prototype:

~Mesh();

Remarks:

Destructor. Frees any allocated arrays (faces, verts, tverts, tvfaces).

Prototype:

void Init();

Remarks:

Initializes the mesh object. The mesh counts are set to 0 and its pointers are set to NULL. Note: This method is not intended to be called by developers. It is used internally.

Prototype:

void DeleteThis();

Remarks:

This method is available in release 3.0 and later only.

This method deletes this mesh.

Vertex Methods

Prototype:

BOOL setNumVerts(int ct, BOOL keep=FALSE, BOOL synchSel=TRUE);

Remarks:

Sets the number of geometric vertices in the mesh.

Parameters:

int ct

Specifies the number of vertices.

BOOL keep=FALSE

Specifies if the previous vertices should be kept. If TRUE the previous vertices are kept; otherwise they are discarded.

BOOL synchSel=TRUE

This parameter is available in release 2.0 and later only.

If TRUE the selection set BitArrays are resized to fit the number of vertices; otherwise they are left unaltered.

Return Value:

TRUE if storage was allocated and the number of vertices was set; otherwise FALSE.

Prototype:

int getNumVerts() const

Remarks:

Returns the number of vertices.

Prototype:

void setVert(int i, const Point3 &xyz);

Remarks:

Sets a single vertex in the verts array.

Parameters:

int i

A zero based index into the verts array of the vertex to store.

const Point3 &xyz

Specifies the coordinate of the vertex.

Prototype:

void setVert(int i, float x, float y, float z);

Remarks:

Sets a single vertex in the verts array.

Parameters:

int i

A zero based index into the verts array of the vertex to store.

float x

Specifies the X coordinate of the vertex.

float y

Specifies the Y coordinate of the vertex.

float z

Specifies the Z coordinate of the vertex.

Prototype:

Point3& getVert(int i);

Remarks:

Returns the 'i-th' vertex.

Parameters:

int i

Specifies the index of the vertex to retrieve.

Prototype:

Point3* getVertPtr(int i);

Remarks:

Returns a pointer to the 'i-th' vertex.

Parameters:

int i

Specifies the index of the vertex address to retrieve.

Color Per Vertex Methods

Prototype:

BOOL setNumVertCol(int ct, BOOL keep=FALSE);

Remarks:

This method is available in release 2.0 and later only.

Sets the number of color per vertex vertices.

Parameters:

int ct

The number of color vertices to set.

BOOL keep=FALSE

If TRUE previous values are kept; otherwise they are discarded.

Return Value:

TRUE if the value was set; otherwise FALSE.

Prototype:

int getNumVertCol() const;

Remarks:

This method is available in release 2.0 and later only.

Returns the number of color per vertex vertices.

Prototype:

BOOL setNumVCFaces(int ct, BOOL keep=FALSE, int oldCt=0);

Remarks:

This method is available in release 2.0 and later only.

Sets the number of color per vertex faces.

Parameters:

int ct;

The number of color per vertex faces to set.

BOOL keep=FALSE

Specifies if the old faces should be kept if the array is being resized. If FALSE they are freed.

int oldCt=0

The length of the existing VCFaces array.

Return Value:

TRUE if storage has been allocated and the number is set; otherwise FALSE.

Prototype:

void setVCDisplayData(int mapChan = 0, VertColor *VCArray=NULL, TVFace *VCf=NULL);

Remarks:

This method is available in release 4.0 and later only.

This method would typically be called right before display, as with a node display callback, or through an extension object. If mapChan parameter is set to MESH_USE_EXT_CVARRAY then the data in VCArray and TVFace is stored for internal use and consequent drawing. If the arrays are NULL then the internal source is used.

 

Parameters:

int mapChan

the mapping channel to use.

VertColor * VCArray

An external array hosting the vertex colors

TVFace * vcf

An external array of TVFace indexing into the color array

 

 

Prototype:

void setSmoothFlags(int f);

Remarks:

This method is available in release 2.0 and later only.

This method should be called when the user has clicked on the 'Smooth' check box in a procedural object. It invalidates the appropriate caches of the mesh so the display is updated properly. If this method is not called, the internal topology cache might prevent the mesh from appearing changed.

Parameters:

int f

Nonzero indicates smoothed; zero unsmoothed.

Prototype:

int getSmoothFlags();

Remarks:

This method is available in release 2.0 and later only.

Returns the state of the smooth flags. See setSmoothFlags() above.

Face Methods

Prototype:

BOOL setNumFaces(int ct, BOOL keep=FALSE, BOOL synchSel=TRUE);

Remarks:

Sets the number of faces in the mesh.

Parameters:

int ct

Specifies the number of faces.

BOOL keep=FALSE

Specifies if the previous faces should be kept. If TRUE the previous faces are kept; otherwise they are discarded.

BOOL synchSel=TRUE

This parameter is available in release 2.0 and later only.

If TRUE the selection set BitArrays are resized to fit the number of faces; otherwise they are left unaltered.

Return Value:

TRUE if storage was allocated and the number of faces was set; otherwise FALSE.

Prototype:

int getNumFaces() const

Remarks:

Returns the number of faces in the mesh.

Texture Vertex-Texture Face Methods

Prototype:

BOOL setNumTVerts(int ct, BOOL keep=FALSE);

Remarks:

Sets the number of texture vertices (in mapping channel 1).

Parameters:

int ct

Specifies the number of texture vertices.

BOOL keep=FALSE

Specifies if the previous texture vertices should be kept. If TRUE the previous texture vertices are kept; otherwise they are discarded.

Return Value:

TRUE if storage was allocated and the number of texture vertices was set; otherwise FALSE.

Prototype:

int getNumTVerts() const

Remarks:

Returns the number of texture vertices (in mapping channel 1).

Prototype:

BOOL setNumTVFaces(int ct, BOOL keep=FALSE, int oldCt=0);

Remarks:

Sets the number of TVFaces. This method is automatically called if you set the number of faces to keep these two in sync (because the number of TVFaces should be the same as the number of faces). The following rules apply:

If you have no TVFaces and keep is TRUE then the TVFaces array stays empty.

If you have no TVFaces and keep is FALSE they are allocated.

If you have TVFaces and ct = 0 then the TVFaces are freed.

Parameters:

int ct

The number of TVFaces.

BOOL keep=FALSE

Specifies if the old faces should be kept.

int oldCt=0

The length of the existing TVFaces array.

Return Value:

TRUE if storage has been allocated and the number is set; otherwise FALSE.

Prototype:

void setTVert(int i, const UVVert &xyz);

Remarks:

Sets a single texture vertex in the tVerts array.

Parameters:

int i

A zero based index into the tVerts array of the texture vertex to store.

const UVVert &xyz

Specifies the coordinate of the vertex.

Prototype:

void setTVert(int i, float x, float y, float z);

Remarks:

Sets a single texture vertex in the tVerts array.

Parameters:

int i

A zero based index into the tVerts array of the texture vertex to store.

float x

Specifies the X coordinate of the texture vertex.

float y

Specifies the Y coordinate of the texture vertex.

float z

Specifies the Z coordinate of the texture vertex.

Prototype:

UVVert& getTVert(int i)

Remarks:

Returns the 'i-th' texture vertex.

Parameters:

int i

Specifies the index of the texture vertex to retrieve.

Prototype:

UVVert* getTVertPtr(int i)

Remarks:

Returns a pointer to the 'i-th' texture vertex.

Parameters:

int i

Specifies the index of the texture vertex address to retrieve.

Multiple Map Support

Prototype:

void setNumMaps(int ct, BOOL keep=FALSE);

Remarks:

This method is available in release 3.0 and later only.

Set the number of texture maps used by this Mesh. Note that this call is made automatically if Mesh::setMapSupport() is called.

Parameters:

int ct

The number of texture maps to use. This is a value between 2 and MAX_MESHMAPS-1.

BOOL keep=FALSE

TRUE to keep the old mapping information after the resize; FALSE to discard it.

Prototype:

int getNumMaps() const;

Remarks:

This method is available in release 3.0 and later only.

Returns the number of mapping channels in use.

Prototype:

BOOL mapSupport(int mp) const;

Remarks:

This method is available in release 3.0 and later only.

Returns TRUE if the specified mapping channel is supported; otherwise FALSE.

Parameters:

int mp

Specifies the channel. See List of Mapping Channel Index Values.

Prototype:

void setMapSupport(int mp, BOOL support=TRUE);

Remarks:

This method is available in release 3.0 and later only.

Sets whether the specified mapping channels is supported or not.

Parameters:

int mp

Specifies the channel. See List of Mapping Channel Index Values.

BOOL support=TRUE

TRUE to indicate the channel is supported; otherwise FALSE.

Prototype:

void setNumMapVerts(int mp, int ct, BOOL keep=FALSE);

Remarks:

This method is available in release 3.0 and later only.

Sets the number of texture or vertex color vertices for the specified mapping channel of this mesh.

Parameters:

int mp

Specifies the channel. See List of Mapping Channel Index Values.

int ct

The number of vertices to allocate.

BOOL keep=FALSE

If TRUE previous values are kept; otherwise they are discarded.

Prototype:

int getNumMapVerts(int mp) const;

Remarks:

This method is available in release 3.0 and later only.

Returns the number of texture or vertex color verticies for the specified channel of this mesh.

Parameters:

int mp

Specifies the channel. See List of Mapping Channel Index Values.

Prototype:

void setNumMapFaces(int mp, int ct, BOOL keep=FALSE, int oldCt=0);

Remarks:

This method is available in release 3.0 and later only.

Sets the number of texture or vertex color faces for the specified channel of this mesh.

Parameters:

int mp

Specifies the channel. See List of Mapping Channel Index Values.

int ct

The number of faces to allocate.

BOOL keep=FALSE

If TRUE previous values are kept; otherwise they are discarded.

Prototype:

UVVert *mapVerts(int mp) const;

Remarks:

This method is available in release 3.0 and later only.

Returns a pointer to the list of UVVerts for the specified channel of this mesh.

Parameters:

int mp

Specifies the channel. See List of Mapping Channel Index Values.

Prototype:

TVFace *mapFaces(int mp) const;

Remarks:

This method is available in release 3.0 and later only.

Returns a pointer to the list of TVFaces for the specified channel of this mesh.

Parameters:

int mp

Specifies the channel. See List of Mapping Channel Index Values.

Prototype:

void setMapVert(int mp, int i, const UVVert&xyz);

Remarks:

This method is available in release 3.0 and later only.

Sets a single texture or vertex color value for the specified channel of this mesh.

Parameters:

int mp

Specifies the channel. See List of Mapping Channel Index Values.

int i

The zero based index of the vertex to set.

const UVVert&xyz

The value to set.

Prototype:

void MakeMapPlanar(int mp);

Remarks:

This method is available in release 3.0 and later only.

Applies a simple planar mapping to the specified channel. This is done by copying the mesh topology and vertex locations into the map.

Parameters:

int mp

Specifies the channel. See List of Mapping Channel Index Values.

Prototype:

BitArray GetIsoMapVerts(int mp);

Remarks:

This method is available in release 3.0 and later only.

Returns a BitArray with a bit set for each isolated vertex (un-referenced by any face) for the specified channel.

Parameters:

int mp

Specifies the channel. See List of Mapping Channel Index Values.

Prototype:

void DeleteMapVertSet(int mp, BitArray set, BitArray *fdel=NULL);

Remarks:

This method is available in release 3.0 and later only.

Deletes the map vertices indicated.

Parameters:

int mp

Specifies the channel. See List of Mapping Channel Index Values.

BitArray set

Indicates which map verts should be deleted. set.GetSize() should equal this mesh's getNumMapVerts(mp).

BitArray *fdel=NULL

If non-NULL, this points to a BitArray that will be filled in with the faces that will need to be deleted or have new map verts assigned because they used a map vert that was deleted. (The size will be set to this mesh's numFaces.)

Prototype:

void DeleteIsoMapVerts(int mp);

Remarks:

This method is available in release 4.0 and later only.

This method deletes each isolated vertex (un-referenced by any face) for the specified channel.

Parameters:

int mp=-1

Specifies the channel. See List of Mapping Channel Index Values. The default value of -1 indicates to do all active maps.

Prototype:

void DeleteIsoMapVerts();

Remarks:

This method is available in release 4.0 and later only.

This method deletes each isolated vertex (un-referenced by any face) for the all active maps.

Prototype:

void freeMapVerts(int mp);

Remarks:

This method is available in release 3.0 and later only.

Deallocates the texture or vertex color vertices for the specified channel of this mesh.

Parameters:

int mp

Specifies the channel. See List of Mapping Channel Index Values.

Prototype:

void freeMapFaces(int mp);

Remarks:

This method is available in release 3.0 and later only.

Deallocates the texture or vertex color faces for the specified channel of this mesh.

Parameters:

int mp

Specifies the channel. See List of Mapping Channel Index Values.

Vertex Data Methods

Prototype:

void setNumVData(int ct, BOOL keep=FALSE);

Remarks:

This method is available in release 3.0 and later only.

Sets the number of channels of vertex data used by the mesh.

Parameters:

int ct

The number of elements of vertex data to set.

BOOL keep=FALSE

If TRUE any old vertex data is kept; otherwise it is discarded.

Prototype:

int getNumVData() const;

Remarks:

This method is available in release 3.0 and later only.

Returns the number of vertex data channels maintained by this mesh.

Prototype:

BOOL vDataSupport(int vd) const;

Remarks:

This method is available in release 3.0 and later only.

Returns TRUE if the specified channel of vertex data is available for this mesh; otherwise FALSE.

Parameters:

int vd

The vertex data channel. See List of Vertex Data Index Options.

Prototype:

void setVDataSupport(int vd, BOOL support=TRUE);

Remarks:

This method is available in release 3.0 and later only.

Sets if the specified channel of vertex data is supported by this mesh.

Parameters:

int vd

The vertex data channel. See List of Vertex Data Index Options.

BOOL support=TRUE

TRUE to indicate the channel is supported; FALSE to indicate it's not. If TRUE is specified then numVerts elements are allocated (if needed). If FALSE is specified the data for the channel is freed.

Prototype:

void *vertexData(int vd) const;

Remarks:

This method is available in release 3.0 and later only.

Returns a pointer to the vertex data for the specified channel or NULL if the channel is not supported. If supported then the size of this array is numVerts.

Parameters:

int vd

The vertex data channel. See List of Vertex Data Index Options.

Prototype:

float *vertexFloat(int vd) const;

Remarks:

This method is available in release 3.0 and later only.

Returns a pointer to the floating point vertex data for the specified channel of this mesh or NULL if the channel is not supported. If supported then the size of this array is numVerts.

Parameters:

int vd

The vertex data channel. See List of Vertex Data Index Options.

Prototype:

void freeVData(int vd);

Remarks:

This method is available in release 3.0 and later only.

Deallocates the vertex data for the specified chanel.

Parameters:

int vd

The vertex data channel. See List of Vertex Data Index Options.

Prototype:

void freeAllVData();

Remarks:

This method is available in release 3.0 and later only.

Deallocates the vertex data from all the channels and sets the number of supported channels to 0.

Prototype:

float *getVertexWeights();

Remarks:

This method is available in release 3.0 and later only.

Returns a pointer to the floating point vertex weight data.

Prototype:

void SupportVertexWeights();

Remarks:

This method is available in release 3.0 and later only.

Sets the channel support for the vertex weights channel (VDATA_WEIGHT).

Prototype:

void ClearVertexWeights();

Remarks:

This method is available in release 3.0 and later only.

Clears (deallocates) the vertex weights channel data.

Prototype:

void freeVertexWeights();

Remarks:

This method is available in release 3.0 and later only.

Deallocates the vertex weights channel data (same as ClearVertexWeights() above).

Prototype:

float *getVSelectionWeights();

Remarks:

This method is available in release 3.0 and later only.

Returns a pointer to the floating point vertex selection weights data.

Prototype:

void SupportVSelectionWeights();

Remarks:

This method is available in release 3.0 and later only.

Sets the channel support for the vertex weights channel (VDATA_SELECT).

Prototype:

void ClearVSelectionWeights();

Remarks:

This method is available in release 3.0 and later only.

Clears (deallocates) the vertex selection weights channel data.

Prototype:

void freeVSelectionWeights();

Remarks:

This method is available in release 3.0 and later only.

Deallocates the vertex selection weights channel data (same as ClearVSelectionWeights() above).

Normals Methods

Prototype:

void setNormal(int i, const Point3 &xyz);

Remarks:

Sets a single 'rendered' normal in the rVerts array of RVertex instances.

Parameters:

int i

A zero based index into the rVerts array of the normal to store.

const Point3 &xyz

The normal to store in device coordinates. This should be a unit vector.

Prototype:

Point3& getNormal(int i);

Remarks:

Returns the 'i-th' 'rendered' normal from the rVerts array.

Parameters:

int i

A zero based index into the rVerts array of the normal to get.

Prototype:

void setFaceNormal(int i, const Point3 &xyz);

Remarks:

Sets the 'i-th' face normal.

Parameters:

int i

A zero based index into the face normal array of the normal to store.

const Point3 &xyz

The face normal to store. This should be a unit vector.

Prototype:

Point3& getFaceNormal(int i);

Remarks:

Returns the 'i-th' face normal.

Parameters:

int i

Specifies the index of the face normal to retrieve.

Prototype:

void buildNormals();

Remarks:

This method resolves the normals on the RVertex array. If the Mesh already has normals at each vertex, the normal is just moved to the RVertex array. See Class RVertex and Class RNormal.

If you are creating a Mesh by hand, after you are done specifying all the vertices and faces, this method should be called. This allocates the RVertex and RNormal database for the Mesh. This will allow you to query the Mesh and ask about normals on the vertices. Also, if you deform a Mesh (i.e. take one of the vertices and move it), you should call this method again. Actually, if you are only moving one normal you only need to smooth the polygons that share the vertex. However, there is no method to smooth a subset of a Mesh, you either have to do it by hand or call this method to smooth the entire Mesh.

This method also builds the face normals for the mesh.

Prototype:

void buildRenderNormals();

Remarks:

This method is similar to buildNormals() above, but ignores the material index (mtlIndex). In other words, the difference between this and buildNormals() is that it doesn't look at the mtlIndex of the faces: normals of faces with the same smoothing group are averaged regardless.

Prototype:

void checkNormals(BOOL illum);

Remarks:

This method can be used to build the normals and allocate RVert space only if necessary. This is a very inexpensive call if the normals are already calculated. When illum is FALSE, only the RVerts allocation is checked (since normals aren't needed for non-illum rendering). When illum is TRUE, normals will also be built, if they aren't already. So, to make sure normals are built, call this with illum=TRUE.

Parameters:

BOOL illum

If TRUE then normals are built. If FALSE then only the RVert array is allocated.

Prototype:

RVertex &getRVert(int i)

Remarks:

This method returns the 'i-th' RVertex.

Parameters:

int i

Specifies the index of the RVertex to retrieve.

Prototype:

RVertex *getRVertPtr(int i)

Remarks:

This method returns a pointer to the 'i-th' RVertex.

Parameters:

int i

Specifies the index of the RVertex to retrieve.

Material Methods

Prototype:

MtlID getFaceMtlIndex(int i);

Remarks:

Retrieves the zero based material index of the 'i-th' face.

Parameters:

int i

Specifies the face index. This is the zero based index into the faces array.

Prototype:

void setFaceMtlIndex(int i, MtlID id);

Remarks:

Sets the material index of the 'i-th' face.

Parameters:

int i

Specifies the face index. This is the zero based index into the faces array.

MtlID id

The material index for the 'i-th' face.

Prototype:

void setMtlIndex(MtlID i);

Remarks:

This method is no longer used.

Prototype:

MtlID getMtlIndex();

Remarks:

This method is no longer used.

Prototype:

void createFaceMtlIndexList();

Remarks:

This method is no longer used.

Prototype:

void freeFaceMtlIndexList();

Remarks:

This method is no longer used.

Render / Hit Test / Snap Methods

Prototype:

void render(GraphicsWindow *gw, Material *ma, RECT *rp,

 int compFlags, int numMat=1, InterfaceServer *pi = NULL);

Remarks:

Renders this Mesh using the specified graphics window and array of materials.

Note: If a display routine makes multiple calls to this method you need to have called:

gw->setMaterial(inode->Mtls()[0]);

before calling Mesh::render(). If you don't then you may get the wrong material for material ID 0.

Parameters:

GraphicsWindow *gw

Points to the graphics window to render to.

Material *ma

The list of materials to use to render the mesh. See Class Material, Class INode - Material methods.

RECT *rp

Specifies the rectangular region to render. If the mesh should be rendered to the entire viewport pass NULL.

int compFlags

One or more of the following flags:

COMP_TRANSFORM

Forces recalculation of the model to screen transformation; otherwise attempt to use the cache.

COMP_IGN_RECT

Forces all polygons to be rendered; otherwise only those intersecting the box will be rendered.

COMP_LIGHTING

Forces re-lighting of all vertices (as when a light moves); otherwise only re-light moved vertices

COMP_ALL

All of the above flags.

COMP_OBJSELECTED

If this bit is set then the node being displayed by this mesh is selected. Certain display flags only activate when this bit is set.

int numMat=1

The number of materials for the mesh.

InterfaceServer *pi = NULL

This pointer to an InterfaceServer can be used to get hold of the IXTCAccess pointer.

And IXTCAccess interface can also be obtained from the object by calling Object::GetInterface

(IXTCACCESS_INTERFACE_ID).

Sample Code:

The following code shows this method being used to render the mesh as part of the BaseObject::Display() method:

int SimpleObject::Display(TimeValue t, INode* inode,

 ViewExp *vpt, int flags)

 {

 if (!OKtoDisplay(t)) return 0;

 GraphicsWindow *gw = vpt->getGW();

 Matrix3 mat = inode->GetObjectTM(t);

 UpdateMesh(t); // UpdateMesh() just calls BuildMesh()

 gw->setTransform(mat);

 mesh.render(gw, inode->Mtls(),

(flags&USE_DAMAGE_RECT) ? &vpt->GetDammageRect() : NULL,

COMP_ALL, inode->NumMtls());

 return(0);

 }

Prototype:

BOOL select(GraphicsWindow *gw, Material *ma,

 HitRegion *hr, int abortOnHit = FALSE, int numMat=1);

Remarks:

Checks the given HitRecord hr to see if it intersects this Mesh object.

Parameters:

GraphicsWindow *gw

Points to the graphics window to check.

Material *ma

The list of materials for the mesh.

HitRegion *hr

This describes the properties of a region used for the hit testing. See Class HitRegion.

int abortOnHit = FALSE

If nonzero, the hit testing is complete after any hit; otherwise all hits are checked.

int numMat=1

The number of materials for the mesh.

Return Value:

TRUE if the item was hit; otherwise FALSE.

Prototype:

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

Remarks:

Checks to see if there is a snap point near the given mouse point.

Parameters:

GraphicsWindow *gw

The graphics window in which to check.

SnapInfo *snap

This structure describes the snap settings used, and the results of the snap test. See Structure SnapInfo.

IPoint2 *p

The mouse point to check.

Matrix3 &tm

The object transformation matrix. This is the transformation to place the object into the world coordinate system.

Sample Code:

// Checks to see if there is a snap point near the given mouse point.

void TestObject::Snap(TimeValue t, INode* inode, SnapInfo *snap,

 IPoint2 *p, ViewExp *vpt) {

 // Grab the object TM

 Matrix3 tm = inode->GetObjectTM(t);

 // Grab the graphics window

 GraphicsWindow *gw = vpt->getGW();

 // Make sure our mesh is up to date

 UpdateMesh(t); // UpdateMesh() just calls BuildMesh()

 // Set the transform in the GW

 gw->setTransform(tm);

 // Let the mesh do the work...

 mesh.snap( gw, snap, p, tm );

}

Prototype:

BOOL SubObjectHitTest(GraphicsWindow *gw, Material *ma,

 HitRegion *hr, DWORD flags,

 SubObjHitList& hitList, int numMat=1 );

Remarks:

This method may be called to perform sub-object hit testing on this mesh.

Parameters:

GraphicsWindow *gw

The graphics window associated with the viewport the mesh is being hit tested in.

Material *ma

The list of materials for the mesh. See Class Material, Class INode - Material methods.

HitRegion *hr

This describes the properties of a region used for the hit testing. See Class HitRegion.

DWORD flags

Flags for sub object hit testing. One or more of the following values:

SUBHIT_SELONLY

Selected only.

SUBHIT_UNSELONLY

Unselected only.

SUBHIT_ABORTONHIT

Abort hit testing on the first hit found.

SUBHIT_SELSOLID

This treats selected items as solid and unselected items as not solid. Treating an item as solid means the face will be hit if the mouse is anywhere inside the face region and not just over a visible edge.

SUBHIT_USEFACESEL

When this bit is set, the sel only and unsel only tests will use the faces selection when doing a vertex level hit test

SUBHIT_VERTS

Hit test vertices.

SUBHIT_FACES

Hit test faces.

SUBHIT_EDGES

Hit test edges.

SubObjHitList& hitList

The results are stored here. See Class SubObjHitList.

int numMat=1

The number of materials for the mesh.

Return Value:

TRUE if the item was hit; otherwise FALSE.

Prototype:

void displayNormals(int b, float sc)

Remarks:

Controls the display of surface normals on the mesh object.

Note that there may be more than one normal per vertex if faces that share the vertex are in non-overlapping smoothing groups. In this case, all normals associated with the given vertex are drawn.

Parameters:

int b

Nonzero to display the normals; zero to turn off normals display.

This can be a combination of MESH_DISP_FACE_NORMALS and MESH_DISP_VERTEX_NORMALS. (The arguments may be or'ed together to display both.) For backwards compatibility, MESH_DISP_FACE_NORMALS is #define'd to be "1", so sending in "TRUE" will turn on display of face normals, as before.

float sc

This specifies the length that should be used (in world units) to display the normals. Since all normals start out with length =1 they probably would be too small to see unless they were scaled

Bounding Box Methods

Prototype:

void buildBoundingBox();

Remarks:

Computes the bounding box of the Mesh. If surface normals are displayed, they are taken into account in the computation of the box. The bounding box is stored with the Mesh object, use getBoundingBox() to retrieve it.

Prototype:

Box3 getBoundingBox(Matrix3 *tm=NULL);

Remarks:

Retrieves the bounding box of the mesh object.

Parameters:

Matrix3 *tm=NULL

The optional TM allows the box to be calculated in any space. NOTE: This computation will be slower because all the points must be transformed.

Return Value:

The bounding box of the Mesh.

Edge Methods

Prototype:

void displayAllEdges(int b);

Remarks:

Controls the display of hidden edges of this mesh object. This just sets the Boolean in the mesh that controls whether "hidden" edges (for instance the diagonals on the sides of a cube) are displayed.

Parameters:

int b

Nonzero to display all the hidden edges; otherwise zero.

Prototype:

void EnableEdgeList(int e);

Remarks:

This method is used internally.

Prototype:

void BuildVisEdgeList();

Remarks:

This method is used internally.

Prototype:

void DivideEdge(DWORD edge, float prop, bool visDiag1=TRUE, bool fixNeighbors=TRUE, bool visDiag2=TRUE);

Remarks:

This method is available in release 2.5 and later only.

Divides the edge, creating a new point. The face directly using this edge (face edge/3) is also divided in two, and other faces using the edge may optionally be split to use the split edges.

Parameters:

DWORD edge

The edge to divide.

float prop

The proportion along the edge to make the division. An edge can be expressed as ff*3+ee, where ff is a face using this edge and ee represents which pair of vertices the edge is between, faces[ff]->v[ee] and faces[ff]->v[(ee+1)%3]. The new point is created at (1-prop) times the first vertex plus prop times the second. prop may vary from 0 to 1. prop=.5 gives the same result that DivideEdge (DWORD edge) would generate.

bool visDiag1=TRUE

Indicates whether the "diagonal" used to split the primary face this edge is on (edge/3) is visible or not.

bool fixNeighbors=TRUE

Indicates whether other faces using this edge should also be split to use the two new edges, or if they should be left as they were. In a typical mesh, there is one other face using this edge, the face on the "other side" of the edge. If fixNeighbors is FALSE, the "other side" in this case would still use the original edge, while the face on this side would be split to use the two new edges. This would create a "hole" in the mesh.

bool visDiag2=TRUE

Indicates whether the "diagonals" used to split other faces using this edge are visible or not. This argument is not used if fixneighbors is FALSE.

Prototype:

void DivideFace(DWORD face, DWORD e1, DWORD e2, float prop1=.5f, float prop2=.5f, bool fixNeighbors=TRUE, bool split=FALSE);

Remarks:

This method is available in release 2.5 and later only.

Cuts a face into three faces, arranged as a quad and a triangle, by slicing from a point on one edge to a point on another.

Parameters:

DWORD face

The face to be divided.

DWORD e1, e2

The index of edges to be cut. For instance, if you wanted to cut from the edge between v[0] and v[1], to the edge between v[2] and v[0], you would use e1=0 and e2=2.

float prop1=.5f

The proportion along edge e1 to start cutting.

float prop2=.5f

The proportion along edge e2 to stop cutting.

bool fixNeighbors=TRUE

Indicates whether faces also using the cut edges should be split to use the new, subdivided edges.

bool split=FALSE

Indicates that the triangle and quad created by this action should use different vertices. If TRUE, the vertices created by the cut are duplicated, with one set being used for faces on one side and the other set being used by faces on the other side.

Prototype:

void TurnEdge(DWORD edge, DWORD *otherEdge);

Remarks:

This method is available in release 2.5 and later only.

Turns an edge. The quadrilateral formed by the triangles on either side of this edge essentially has its diagonal switched.

Parameters:

DWORD edge

The edge to be turned.

DWORD *otherEdge

If non-NULL, this should point to a variable in which the index of the "other side" of this edge should be stored. In essence, the two sides of an edge used by two faces, f1 and f2, are stored in two different locations, f1*3+e1 and f2*3+e2, where e1, e2 are 0, 1, or 2. This argument is provided so you have easy access to the other side of the edge, if desired, to make easy selection or visibility changes to the edge or other changes to the faces on both sides.

Prototype:

void DrawVisEdgeList(GraphicsWindow *gw, DWORD flags);

Remarks:

This is used internally.

Prototype:

void HitTestVisEdgeList(GraphicsWindow *gw, int useFloats,

 int abortOnHit );

Remarks:

This is used internally.

Prototype:

void InvalidateEdgeList();

Remarks:

This is used internally.

Prototype:

void InvalidateGeomCache();

Remarks:

Call this method after the geometry of this Mesh has changed. It invalidates the bounding box, and tosses out the cached normals and edge list.

Prototype:

void InvalidateTopologyCache();

Remarks:

Call this method after you alter vertex or face lists or revise edge visibility flags. It will invalidate the edge and strip database maintained by the mesh.

Prototype:

void FreeAll();

Remarks:

Cleans up the allocated arrays. This frees the Faces, Verts, TVerts, TVFaces, FaceMtlIndexList and invalidates the geometry cache.

Strip Methods

Prototype:

BOOL BuildStrips();

Remarks:

This method is available in release 2.0 and later only.

It builds the strips database inside the mesh. See the method BuildStripsAndEdges() below.

Prototype:

void BuildStripsAndEdges();

Remarks:

This method is available in release 2.0 and later only.

It builds the strips and edges database inside the mesh. When developers create a new mesh for display then this method should be called. See the section on Stripping in the Advanced Topics section Working with Meshes for details on this method.

Prototype:

void InvalidateStrips();

Remarks:

This method invalidates the strips database.

Prototype:

void Stripify(Strip *s, StripData *sd, int vtx);

Remarks:

This method is used internally.

Prototype:

void getStripVertColor(GraphicsWindow *gw, int cv, int flipped, MtlID mID, DWORD smGroup, Point3 &rgb);

Remarks:

This method is used internally.

Prototype:

void getStripNormal(GraphicsWindow *gw, int cv, MtlID mID, DWORD smGroup, Point3 &nor);

Remarks:

This method is used internally.

Prototype:

void Draw3DStrips(GraphicsWindow *gw, Material *ma, int numMat);

Remarks:

This method is used internally.

Prototype:

BOOL getStripTVert(GraphicsWindow *gw, int cv, Point3 &uvw);

Remarks:

This method is used internally.

Prototype:

void DrawStrips(GraphicsWindow *gw, Material *ma, int numMat);

Remarks:

This method is used internally.

Data Flow Evaluation Methods

Prototype:

void ShallowCopy(Mesh *amesh, ULONG_PTR channels);

Remarks:

Makes a copy of the specified channels of the specified Mesh object's data structures (but not all the data in these structures) into this Mesh. For example the verts, tVerts, tvFaces, ... are not copied.

Parameters:

Mesh *amesh

Specifies the source Mesh to copy.

ULONG_PTR channels

Specifies the channels to copy. See List of Channels. Note: Prior to R4 this parameter was an unsigned long.

Prototype:

void DeepCopy(Mesh *amesh, ULONG_PTR channels);

Remarks:

Makes a complete copy of the specified channels of the specified Mesh object (its data structures and all the data in these structures) into this Mesh.

Parameters:

Mesh *amesh

Specifies the source Mesh to copy.

ULONG_PTR channels

Specifies the channels to copy. See List of Channels. Note: Prior to R4 this parameter was an unsigned long.

Prototype:

void NewAndCopyChannels(ULONG_PTR channels);

Remarks:

This method replaces the specified channels with newly allocated copies.

Parameters:

ULONG_PTR channels

Specifies the channels to copy. See List of Channels. Note: Prior to R4 this parameter was an unsigned long.

Prototype:

void FreeChannels(ULONG_PTR channels, int zeroOthers=1);

Remarks:

Release the memory associated with the specified channels. For example if the TOPO_CHANNEL is specified the faces are freed, if the GEOM_CHANNEL is specified the vertices are freed, etc.

Parameters:

ULONG_PTR channels

Specifies the channels to free. Channels not specified are left intact. See List of Channels. Note: Prior to R4 this parameter was an unsigned long.

int zeroOthers=1

If nonzero then the various pointers are set to NULL and their counts are zeroed. For example faces, verts, tVerts, and tvFace are set to NULL and numFaces, numVerts and numTVerts are set to 0. If this is passed as 0, these pointers and counts are left unaltered.

Mesh / Display Flags

Prototype:

void SetDispFlag(DWORD f)

Remarks:

Sets the state of the display flags. See Data Members: above for a list of the display flags.

Parameters:

DWORD f

Specifies the flags to set.

Prototype:

DWORD GetDispFlag(DWORD f)

Remarks:

Returns the state of the specified display flags. See Data Members: above for a list of the display flags.

Parameters:

DWORD f

Specifies the flags to retrieve.

Prototype:

void ClearDispFlag(DWORD f)

Remarks:

Sets the state of the specified display flags to 0.

Parameters:

DWORD f

Specifies the flags to clear.

Prototype:

void SetFlag(DWORD f)

Remarks:

Sets the state of the mesh flags.

Parameters:

DWORD f

Specifies the flags to set. See List of Mesh Flags.

Prototype:

DWORD GetFlag(DWORD f)

Remarks:

Returns the state of the specified mesh flags. See Data Members: above for a list of the mesh flags.

Parameters:

DWORD f

Specifies the flags to retrieve. See List of Mesh Flags.

 

Prototype:

void ClearFlag(DWORD f)

Remarks:

Sets the state of the specified mesh flags to 0.

Parameters:

DWORD f

Specifies the flags to clear. See List of Mesh Flags.

Selection Access

Prototype:

BitArray& VertSel()

Remarks:

Retrieves the bits representing the vertex selection status. See Data Members: above.

Return Value:

The vertex selection status.

Prototype:

BitArray& FaceSel()

Remarks:

Retrieves the bits representing the face selection status. See Data Members: above.

Return Value:

The face selection status.

Prototype:

BitArray VertexTempSel();

Remarks:

Constructs a vertex selection list based on the current selection level. For example if the selection level is at object level all the bits are set (vertices, faces and edges). If the selection level is at vertex level only the selected vertex bits are set.

Return Value:

A BitArray reflecting the current selection level.

Sample Code:

BitArray sel = mesh->VertexTempSel();

for ( int i = 0; i < mesh->getNumVerts(); i++ ) {

 if ( sel[i] ) {

...

}

 }

Intersect Ray / Weld / Optimize / Apply Mapping

Prototype:

int IntersectRay(Ray& ray, float& at, Point3& norm);

Remarks:

Calculates the intersection of the specified ray with this mesh object. This allows Mesh objects to easily implement the Object::IntersectRay() method.

Parameters:

Ray& ray

Specifies the origin and direction of the ray to intersect with the mesh. See Class Ray.

float& at

The computed point of intersection on the surface of the mesh.

Point3& norm

The face normal at the point of intersection (at).

Return Value:

Nonzero if the ray intersected the mesh object; otherwise 0. Note that this method ignores backfaces when computing the result.

Prototype:

int IntersectRay(Ray& ray, float& at, Point3& norm, DWORD &fi, Point3 &bary);

Remarks:

This method is available in release 2.0 and later only.

Calculates the intersection of the specified ray with this mesh object. This new version also returns the face index that was intersected and the barycentric coordinates of that face.

Barycentric coordinates are the coordinates relative to the triangular face. The barycentric coordinates of a point p relative to a triangle describe that point as a weighted sum of the vertices of the triangle. If the barycentric coordinates are b0, b1, and b2, then:

p = b0*p0 + b1*p1 + b2*p2;

where p0, p1, and p2 are the vertices of the triangle. The Point3 returned by this method has the barycentric coordinates stored in its three coordinates. These coordinates are relative to the triangular face that was intersected. These barycentric coordinates can be used to interpolate any quantity whose value is known at the vertices of the triangle.

Parameters:

Ray& ray

Specifies the origin and direction of the ray to intersect with the mesh. See Class Ray.

float& at

The computed point of intersection on the surface of the mesh.

Point3& norm

The face normal at the point of intersection (at).

DWORD &fi

The face index of the face that was intersected is returned here.

Point3 &bary

The barycentric coordinates of the face that was hit.

Return Value:

Nonzero if the ray intersected the mesh object; otherwise 0.

Prototype:

void WeldCollinear(BitArray &set);

Remarks:

This method is used internally.

Prototype:

void Optimize(float normThresh, float edgeThresh,

 float bias, float maxEdge, DWORD flags, MeshOpProgress *prog=NULL);

Remarks:

Allows this Mesh to be reduced in complexity by reducing the number of faces based on a surface normal threshold. Adjacent faces whose difference in surface normal angle falls below the specified threshold will be collapsed into a single triangle. The Mesh may also have its edge visibility set based on a surface normal threshold.

Parameters:

float normThresh

When the angle between adjacent surface normals is less than this value the optimization is performed. This angle is specified in radians.

float edgeThresh

When the angle between adjacent surface normals is less than this value the auto edge is performed (if the OPTIMIZE_AUTOEDGE flag is set). This angle is specified in radians.

float bias

When optimizing mesh objects, as the optimization increases, you can get lots of long skinny 'degenerate' triangles (that cause rendering artifacts). Increasing the bias parameter keeps triangles from becoming degenerate. The range of values is from 0 to 1 (where 0 turns bias off). Values close to 1 reduce the amount of optimization in favor of maintaining equilateral triangles.

float maxEdge

This parameter is available in release 2.0 and later only.

This will prevent the optimize function from creating edges longer than this value. If this parameter is <=0 no limit is placed on the length of the edges.

DWORD flags

These flags control the optimization. Specify zero or more of the following values:

OPTIMIZE_SAVEMATBOUNDRIES

Specifies that faces won't be collapsed across a material boundary.

OPTIMIZE_SAVESMOOTHBOUNDRIES

Specifies that faces won't be collapsed across a dissimilar smoothing group boundary.

OPTIMIZE_AUTOEDGE

Specifies that the edge visibility should be set automatically based on the angle between adjacent surface normals. This will only set edges as invisible - it will not set edges as visible.

MeshOpProgress *prog=NULL

A callback used for lengthy optimize operations. See Class MeshOpProgress.

Prototype:

void ApplyUVWMap(int type,float utile, float vtile,

 float wtile,int uflip, int vflip, int wflip,

 int cap,const Matrix3 &tm, int channel=1);

Remarks:

This method may be called to map this Mesh with UVW mapping coordinates.

Parameters:

int type

The mapping type. One of the following values:

MAP_PLANAR

MAP_CYLINDRICAL

MAP_SPHERICAL

MAP_BALL

MAP_BOX

float utile

Number of tiles in the U direction.

float vtile

Number of tiles in the V direction.

float wtile

Number of tiles in the W direction.

int uflip

If nonzero the U values are mirrored.

int vflip

If nonzero the V values are mirrored.

int wflip

If nonzero the W values are mirrored.

int cap

This is used with MAP_CYLINDRICAL. If nonzero, then any face normal that is pointing more vertically than horizontally will be mapped using planar coordinates.

const Matrix3 &tm

This defines the mapping space. As each point is mapped, it is multiplied by this matrix, and then it is mapped.

int channel=1

This parameter is available in release 2.0 and later only.

This indicates which channel the mapping is applied to -- channel==1 corresponds to the original texture mapping channel.

Prototype:

MeshMap & Map(int mp);

Remarks:

This method is available in release 4.0 and later only.

This method returns the map for the specified map channel.

Parameters:

int mp

The map channel.

Default Implementation:

{ return (mp<0) ? hmaps[-1-mp] : maps[mp]; }

Normals / Smoothing / Edges / Face check Functions

Prototype:

void FlipNormal(int i);

Remarks:

Flips the surface normal of the 'i-th' face (this just rearranges the indices for the face structure). This also makes sure the edge flags are rearranged as well. If there are UV coordinates these are rearranged appropriately.

Parameters:

int i

The index of the face to flip.

Prototype:

void UnifyNormals(BOOL selOnly);

Remarks:

Unifies the surfaces normals of this Mesh. This may be for selected faces, or the entire mesh.

Parameters:

BOOL selOnly

If TRUE only the selected faces are unified.

Prototype:

void AutoSmooth(float angle,BOOL useSel,BOOL preventIndirectSmoothing=FALSE);

Remarks:

Performs an auto smooth on the mesh, setting the smoothing groups based on the surface normals.

Parameters:

float angle

The minimum angle between surface normals for smoothing to be applied, in radians.

BOOL useSel

If TRUE only the selected faces are smoothed.

BOOL preventIndirectSmoothing=FALSE

This parameter is available in release 2.0 and later only.

TRUE to turn on; FALSE to leave off. This matches the option in the Smooth Modifier UI -- use this to prevent smoothing �leaks" when using this method. If you use this method, and portions of the mesh that should not be smoothed become smoothed, then try this option to see if it will correct the problem. Note that the problem it corrects is rare, and that checking this slows the Auto Smooth process.

Prototype:

Edge *MakeEdgeList(int *edgeCount, int flagdbls=0);

Remarks:

This method is used internally.

Prototype:

int DeleteFlaggedFaces();

Remarks:

This method removes faces from the face list with the FACE_WORK flag set.

Return Value:

The number of faces deleted.

Prototype:

void DeleteSelected();

Remarks:

This method is available in release 3.0 and later only.

Deletes all seleted elements of the current selection level.

Prototype:

void DeleteVertSet(BitArray set);

Remarks:

This method is available in release 3.0 and later only.

Deletes the vertices as specified by the BitArray.

Parameters:

BitArray set

Set of bits to indicate the vertices to delete.

Prototype:

void DeleteFaceSet(BitArray set, BitArray *isoVert=NULL);

Remarks:

This method is available in release 3.0 and later only.

Deletes faces as specified by the BitArray.

Parameters:

BitArray set

Set of bits to indicate the faces to delete.

BitArray *isoVert=NULL

If non NULL then this method will be setup to flag vertices that were isolated by the face deletion. This set can then be passed to DeleteVertSet() to delete isolated vertices.

Prototype:

BOOL DoesFaceExist(DWORD v0, DWORD v1, DWORD v2);

Remarks:

This method may be called to determine if an equivalent face already exists.

Parameters:

DWORD v0

Index of the first vertex.

DWORD v1

Index of the second vertex.

DWORD v2

Index of the third vertex.

Return Value:

TRUE if an equivalent face already exists; otherwise FALSE.

Prototype:

BOOL RemoveDegenerateFaces();

Remarks:

Removes faces that have two or more equal indices.

Return Value:

TRUE if any degenerate faces were found; otherwise FALSE.

Prototype:

BOOL RemoveIllegalFaces();

Remarks:

Removes faces that have indices that are out of range

Return Value:

TRUE if any illegal faces were found; otherwise FALSE.

Prototype:

Point3 FaceNormal(DWORD fi, BOOL nrmlize=FALSE);

Remarks:

This method is available in release 3.0 and later only.

This method returns the normal of the specified face. If nrmlize is TRUE, it makes this normal unit length. Otherwise, it's the edge cross-product length, which is actually 2 times the area of the face.

Parameters:

DWORD fi

Specifies the face whose normal is returned.

BOOL nrmlize=FALSE

Use TRUE to make the normal unit length.

Prototype:

Point3 FaceCenter(DWORD fi);

Remarks:

This method is available in release 3.0 and later only.

This method returns the center of the specified face.

Parameters:

DWORD fi

Specifies the face whose center is returned.

Prototype:

float AngleBetweenFaces(DWORD f0, DWORD f1);

Remarks:

Returns the angle between two face surface normals in radians.

Parameters:

DWORD f0

Index of the first face.

DWORD f1

Index of the second face.

Prototype:

Point3 BaryCoords(DWORD face, Point3 p);

Remarks:

Computes and returns the barycentric coordinates of a point in the plane of a face relative to that face.

Parameters:

DWORD face

The index of the face to check.

Point3 p

The input point.

Return Value:

The point p barycentric coordinates. If the point p is inside the face the returned values will sum to one. Note: If the face (or set of 3 points) is degenerate, ie if it has a zero length normal vector ((p1-p0)^(p2-p0)), the methods return Point3(-1,1,1).

Prototype:

void FaceCenterTessellate(BOOL ignoreSel=FALSE);

Remarks:

This method is available in release 2.0 and later only.

Tesselates the mesh (or only the selected faces) using the face/center method. This means each face is subdivided by lines from a new vertex at the center to the original vertices.

Parameters:

BOOL ignoreSel=FALSE

If TRUE the entire mesh is tesselated; otherwise only the selected faces.

Prototype:

void EdgeTessellate(float tens,BOOL ignoreSel=FALSE);

Remarks:

This method is available in release 2.0 and later only.

Edge tesselates the mesh using the specified tension parameter. This method can operate on the entire mesh or only the selection set. Edge tesselation means that faces are internally subdivided, with additional faces generated from a new vertex in the middle of each face edge.

Parameters:

float tens

The tension setting. This value can range from -100.0 to 100.0. This value matches the parameter in the Editable Mesh user interface when tessellating faces.

BOOL ignoreSel=FALSE

If TRUE the entire mesh is tesselated; otherwise only the selected faces.

Prototype:

void IndentSelFaces(float amount);

Remarks:

This method is available in release 3.0 and later only.

Indents the selected faces, in a manner consistent with the outlining used in Bevel.

Parameters:

float amount

The amount to indent.

Prototype:

void ExtrudeFaces(BOOL doFace=TRUE);

Remarks:

This method is available in release 2.0 and later only.

Extrudes the selected faces. Note that this is just a topological change. The new extruded faces do not change position but are left on top of the original faces.

Parameters:

BOOL doFace=TRUE

If TRUE the faces are extruded. If FALSE then the selected edges are extruded.

Prototype:

void BreakVerts(BitArray set);

Remarks:

This method is available in release 2.0 and later only.

Splits the vertices specified in the BitArray so that they are only used by a single face.

Parameters:

BitArray set

This array of bits, one per vertex in the mesh. If the bit is set, the corresponding vertex in the mesh is copied as required so it is only used by a single face. If the bit is not set the vertex is ignored.

Prototype:

BitArray GetIsoVerts();

Remarks:

This method is available in release 3.0 and later only.

This method returns a BitArray (of size numVerts), where isolated verts are selected.

Prototype:

void DeleteIsoVerts();

Remarks:

This method is available in release 2.0 and later only.

Deletes the vertices that aren't used by any faces.

Prototype:

void CloneFaces(BitArray fset);

Remarks:

This method is available in release 2.0 and later only.

Creates a copy of the faces and verts used by those faces as specified by the BitArray passed. If texture faces and vertex color faces are present they are cloned as well.

Parameters:

BitArray fset

There is one bit in this array for each face in the mesh. If the bit is set, the corresponding face in the mesh is cloned. If the bit is zero the face is not cloned.

Prototype:

void PolyFromFace(DWORD f, BitArray &set, float thresh, BOOL ignoreVisEdges, AdjFaceList *af=NULL);

Remarks:

This method is available in release 3.0 and later only.

Sets bits for all faces in the same polygon with face f. Faces already selected in set will not be processed -- so if f is "set", nothing happens.

The definition of a polygon is all faces sharing invisible edges with edge angles below "thresh".

Parameters:

DWORD f

Specifies which face to evaluate -- the zero based index into the faces array.

BitArray &set

Specifies which faces are not processed. One bit for each face with set bits not considered.

float thresh

The angle in radians which is the threshold for defining a polygon. A polygon is all faces sharing invisible edges with edge angles below this angle.

BOOL ignoreVisEdges

If TRUE, the edge visibility is ignored but the threshhold is still relevant.

AdjFaceList *af=NULL

This adjacent face list can be passed if there's one handy; otherwise a new one will be computed by the method.

Prototype:

void ElementFromFace(DWORD f, BitArray &set, AdjFaceList *af=NULL);

Remarks:

This method is available in release 3.0 and later only.

This method sets bits for all faces in the same "element", or connected component, with face f. Faces already selected in set will be considered "walls" for this processing and will not be evaluated.

Parameters:

DWORD f

Specifies which face to evaluate -- the zero based index into the faces array.

BitArray &set

Specifies which faces are considered as barriers to the element and are not processed. One bit for each face with set bits not considered.

AdjFaceList *af=NULL

This adjacent face list can be passed if there's one handy; otherwise a new one will be computed by the method.

Prototype:

void FindVertsUsedOnlyByFaces(BitArray & fset, BitArray & vset);

Remarks:

This method is available in release 3.0 and later only.

When faces are deleted in Edit or Editable Mesh, we often want to be able to delete the verts that are isolated by this action. This method generates the list of verts that are used only by the specified set of faces.

Parameters:

BitArray & fset

This method finds those vertices used only by the faces indicated in this BitArray.

BitArray & vset

This BitArray is completely overwritten with the result, and will be set to the right size (numVerts) if needed.

Prototype:

void FindOpenEdges(BitArray & edges);

Remarks:

This method is available in release 3.0 and later only.

This method fills in a BitArray with the edges in the mesh that are "open" or "one-sided". (This is the same as the Edit Mesh "Select Open Edges" function.)

Parameters:

BitArray & edges

This BitArray will be set to size numFaces*3, and only the open edge bits will be set.

Prototype:

void FindVertexAngles(float *vang, BitArray *set=NULL);

Remarks:

This method is available in release 3.0 and later only.

This method calculates, for each vertex, the sum of the angles of this vertex's corner in each face it's on. So for instance, a point lying in the middle of a grid would always have vertex angle 2*PI, whereas a corner of a box would only have 3*PI/2.

Parameters:

float *vang

This should be a pointer to an array of size numVerts. The vertex angle for each vertex is put in this array (in radians).

BitArray *set=NULL

If non-NULL, this points to a BitArray describing which vertices to find angles of. If only some bits are set, some computation time is saved. If NULL, all vertices' angles are found.

Prototype:

void SetRenderData(MeshRenderData *p);

Remarks:

Sets the mesh render data hung off this Mesh. This method and GetRenderData() allow the renderer to 'hang' data on a mesh. This data can be anything the renderer wants. The data will automatically be deleted when the mesh is deleted via the DeleteThis() method.

Parameters:

MeshRenderData *p

See Class MeshRenderData.

Prototype:

MeshRenderData *GetRenderData();

Remarks:

Returns the mesh render data hung off this Mesh. See Class MeshRenderData. This method and SetRenderData() allow the renderer to 'hang' data on a mesh. This data can be anything the renderer wants. The data will automatically be deleted when the mesh is deleted via the DeleteThis() method.

Operators:

Prototype:

Mesh& operator=(const Mesh& fromMesh);

Remarks:

Assignment operator. Note: This operator does not copy the rVerts array. This means that developers who have specified normals will have to explicitly copy them after a mesh assignment is done using this operator. This is because rVerts are instance-specific. In general, normals are computed from smoothing groups, and hence are "generated data". In the case where normals are specified, 3ds max stores the data in the rVerts array so as to not waste space. The way 3ds max uses the mesh = operator assumes that the rVerts are not copied, and thus developers must do the copying themselves.

Parameters:

const Mesh& fromMesh

Specifies the mesh to copy.

Prototype:

Mesh operator+(Mesh &mesh);

Remarks:

Performs a boolean union operation.

Parameters:

Mesh &mesh

Specifies the mesh to use as the other operand of the boolean operation.

Return Value:

A new Mesh resulting from the boolean operation. If the operation fails an empty Mesh is returned.

Prototype:

Mesh operator-(Mesh &mesh);

Remarks:

Performs a boolean difference operation.

Parameters:

Mesh &mesh

Specifies the mesh to use as the other operand of the boolean operation.

Return Value:

A new Mesh resulting from the boolean operation. If the operation fails an empty Mesh is returned.

Prototype:

Mesh operator*(Mesh &mesh);

Remarks:

Performs a boolean intersection operation.

Parameters:

Mesh &mesh

Specifies the mesh to use as the other operand of the boolean operation.

Return Value:

A new Mesh resulting from the boolean operation. If the operation fails an empty Mesh is returned.

The following global functions are not part of the Mesh class:

Function:

void setUseVisEdge(int b);

Remarks:

This is used internally.

Function:

int getUseVisEdge();

Remarks:

This is used internally.

Boolean Operations / CombineMeshes:

The following functions are not part of class Mesh but are available for use:

Prototype:

int CalcBoolOp(Mesh &mesh, Mesh &mesh1, Mesh &mesh2, int op,

MeshOpProgress *prog = NULL, Matrix3 *tm1 = NULL,

Matrix3 *tm2 = NULL, int whichInv = 0, int weld = TRUE);

Remarks:

Note: This method is still in the SDK, but it is now obselete. Calls to CalcBoolOp() should be replaced with calls to the new MNMesh form of Boolean. Please see the method MNMesh::MakeBoolean in Class MNMesh for details.

This function stores the result of a boolean operation between mesh1 and mesh2 into mesh. This operation may be a union, intersection or difference. If tm1 or tm2 are non-NULL, the points of the corresponding mesh will be transformed by these matrices before the boolean operation. The mesh will be transformed back by either Inverse(tm1) or Inverse(tm2) depending on whichInv (a value of 0 will use tm1, a value of 1 will use tm2, unless whichInv is -1 in which case it will not be transformed back).

Parameters:

Mesh &mesh

The result of the boolean operation is stored here. mesh = mesh1 op mesh2.

Mesh &mesh1

The first operand.

Mesh &mesh2

The second operand.

int op

The boolean operation. One of the following values:

MESHBOOL_UNION

MESHBOOL_INTERSECTION

MESHBOOL_DIFFERENCE

MeshOpProgress *prog = NULL

A callback to display a progress. See Class MeshOpProgress.

Matrix3 *tm1 = NULL

If non-NULL then the points of mesh1 will transformed by this matrix before the boolean operation.

Matrix3 *tm2 = NULL

If non-NULL then the points of mesh2 will transformed by this matrix before the boolean operation.

int whichInv = 0

If 0, the resulting mesh will be transformed by Inverse(tm1). If 1, the resulting mesh will be transformed by Inverse(tm2). If -1, the mesh will not be transformed back.

int weld = TRUE

If TRUE, the vertices of the resulting mesh are welded.

Return Value:

Nonzero if the operation completed successfully; otherwise zero.

Prototype:

void CombineMeshes(Mesh &mesh, Mesh &mesh1, Mesh &mesh2, Matrix3 *tm1=NULL, Matrix3 *tm2=NULL, int whichInv=0);

Remarks:

This function is available in release 2.0 and later only.

This function may be used to simply combine two meshes into one.

Parameters:

Mesh &mesh

The result of the combine operation is stored here. mesh = mesh1+mesh2.

Mesh &mesh1

The first operand.

Mesh &mesh2

The second operand.

Matrix3 *tm1 = NULL

If non-NULL then the points of mesh1 will transformed by this matrix before the boolean operation.

Matrix3 *tm2 = NULL

If non-NULL then the points of mesh2 will transformed by this matrix before the boolean operation.

int whichInv=0

If 0, the resulting mesh will be transformed by Inverse(tm1). If 1, the resulting mesh will be transformed by Inverse(tm2). If -1, the mesh will not be transformed back.

Sub-Object Selection Color Control

The following functions are not part of class Mesh but are available for use:

Prototype:

void SetSubSelColor(Point3 *clr);

Remarks:

This methods sets the color used for sub-object selection.

Parameters:

Point3 *clr

The color to use.

Prototype:

Point3 GetSubSelColor();

Remarks:

Returns the color used for sub-object selection.