Class MNMap

3DS Max Plug-In SDK

Class MNMap

See Also: Class FlagUser, Class MNMapFace, Class Point3, Class Matrix3.

class MNMap : public FlagUser

Description:

This class is available in release 3.0 and later only. It replaces the old tv and cv arrays in MNMesh, and the old tvrt and cvrt arrays in MNFace.

Each MNMap holds the mapping information for a particular map channel of the MNMesh. As with regular Mesh maps, the MNMap holds an array of map vertices and an array of map faces that define how those mapping vertices are applied to the MNMesh. The number (numf) of mapping faces should always match the number of faces in the parent MNMesh, and each MNMapFace gives the map vertices for the related MNFace. The number of map vertices may be different from the number of MNVerts in the parent MNMesh.

Friend Classes:

friend class MNMesh;

Data Members:

public:

MNMapFace *f;

The array of map faces.

UVVert *v;

The array of UVVerts. Note: typedef Point3 UVVert;

int numv

The number of verticies in the v array.

int numf;

The number of map faces in the f array.

Methods:

public:

Prototype:

MNMap();

Remarks:

Constructor. This calls Init().

 

Prototype:

~MNMap();

Remarks:

Destructor. This calls ClearAndFree().

Prototype:

void Init();

Remarks:

Initializes the map – sets numv and numf to 0, and sets the pointers to NULL. Also initializes private allocation related data members.

Prototype:

void VAlloc(int num, bool keep=TRUE);

Remarks:

Allocates the specified number of UVVerts in the v array. (If you’re creating a number of map verts, but you’re not sure exactly how many, it’s good to pre-allocate a large number using this method.) This method doesn’t affect MNMap::numv, only the allocation amount.

Parameters:

int num

The number of UVVerts to allocate.

bool keep=TRUE

If TRUE any previous verts are kept; otherwise they are discarded.

Prototype:

void FAlloc(int num, bool keep=TRUE);

Remarks:

Allocates the specified number of map faces in the f array. This method doesn’t affect MNMap::numf, just the number allocated.

Parameters:

int num

The number of map verts to allocate.

bool keep=TRUE

If TRUE any previous map faces are kept; otherwise they are discarded.

Prototype:

int VNum() const;

Remarks:

Returns the current number of UVVerts.

Prototype:

UVVert V(int i) const;

Remarks:

Returns the 'i-th' UVVert.

Parameters:

int i

The zero based index into the v array of the UVVert to return.

Prototype:

int FNum() const;

Remarks:

Returns the number of map faces.

 

Prototype:

MNMapFace *F(int i) const;

Remarks:

Returns a pointer to the 'i-th' map face.

Parameters:

int i

The zero based index of the map face to return.

Prototype:

int NewTri(int a, int b, int c);

Remarks:

Like MNMesh::NewTri, this creates a new mapping face, of degree 3, with the specified map vertices.

Parameters:

int a

int b

int c

The mapping vertices for the new triangle.

Prototype:

int NewTri(int *vv);

Remarks:

Like MNMesh::NewTri, this creates a new mapping face, of degree 3, with the specified map vertices.

Parameters:

int *vv

The mapping vertices for the new triangle.

Prototype:

int NewQuad(int a, int b, int c, int d);

Remarks:

Like MNMesh::NewQuad, this creates a quad, with the specified map vertices.

Parameters:

int a

int b

int c

int d

The mapping vertices for this quad. (The two faces are formed with mapping verts (a,b,c) and (c,d,a).

Prototype:

int NewQuad(int *vv);

Remarks:

Like MNMesh::NewQuad, this creates a quad, with the specified map vertices.

Parameters:

int *vv

The mapping vertices for this quad. (The two faces are formed with mapping verts (vv[0],vv[1],vv[2]) and (vv[2],vv[3],vv[0]).

Prototype:

int NewFace(int degg=0, int *vv=NULL);

Remarks:

Like MNMesh::NewFace, this creates a new mapping face with the specified degree and map vertices.

Parameters:

int degg=0

The degree of the new face. (Note that this should match the degree of the associated MNFace.)

int *vv=NULL

The new mapping vertices, in order around the perimeter.

Prototype:

void setNumFaces(int nfnum);

Remarks:

Sets the number of map faces keeping any previously allocated faces.

Parameters:

int nfnum

The number of faces to set.

Prototype:

int NewVert(UVVert p, int uoff=0, int voff=0);

Remarks:

Allocates storage for a new specified UVVert. An optional offset to the UVVert may be supplied. (The offset is useful when you want to create a new UVVert which is on the other side of a seam in U or V from some existing UVVert p.)

Parameters:

UVVert p

The UVVert to store.

int uoff=0

If non-zero this is an offset applied in U when p is stored.

int voff=0

If non-zero this is an offset appled in V when p is stored.

Prototype:

void setNumVerts(int nvnum);

Remarks:

Sets the number of UVVerts keeping any previously allocated UVVerts.

Parameters:

int nvnum

The number of UVVerts to set.

Prototype:

void CollapseDeadVerts(MNFace *faces);

Remarks:

Eliminates the mapping vertices not used by any active mapping faces in this map. (Analogous to the Mesh::DeleteIsoMapVerts method.)

Parameters:

MNFace *faces

This should point to the MNFace array of the parent MNMesh. This allows the method to find out if any faces should be considered MN_DEAD, so that it won’t mark such faces’ map verts as used. (The MN_DEAD flag is stored in the MNFace, but not in the related MNMapFaces.)

Prototype:

void CollapseDeadFaces(MNFace *faces);

Remarks:

Eliminates the MN_DEAD map faces from the array. This should be called immediately before calling CollapseDeadFaces on the parent MNMesh, to keep the face arrays in sync.

Parameters:

MNFace *faces

The parent MNMesh’s array of MNFaces. This array is used to find out which faces are MN_DEAD.

Prototype:

void Clear();

Remarks:

Sets the number of UVVerts and map faces to 0.

Prototype:

void ClearAndFree();

Remarks:

Sets the number of UVVerts and map faces to 0 and deallocates the memory.

Prototype:

void Transform(Matrix3 & xfm);

Remarks:

Transforms each UVVert with the specified matrix.

Parameters:

Matrix3 &xfm

The matrix to transform the UVVerts by.

Prototype:

MNMap & operator=(const MNMap &from);

Remarks:

Assignment operator.

Prototype:

MNMap & operator+=(const MNMap &from);

Remarks:

Appends the specified MNMap object onto this MNMap.

Parameters:

const MNMap &from

The source MNMap.

Prototype:

MNMap & operator+=(const MNMesh &from);

Remarks:

Appends a default planar map corresponding to the mesh passed onto this map. This is typically used when joining two MNMeshes together when one MNMesh has a map channel active but the other doesn’t. Rather than eliminate the map channel, we just use the object coordinates of the other mesh to generate a planar map for its faces.

Parameters:

const MNMesh &from

The source MNMesh.

Prototype:

void ShallowCopy(const MNMap & from);

Remarks:

Copies pointers. To avoid memory errors, this method should only be used by the pipeline.

Parameters:

const MNMap & from

The map to copy pointers from.

Prototype:

void NewAndCopy();

Remarks:

Creates new pointers and copies over all the data. To avoid memory errors, this method should only be used by the pipeline.

Prototype:

void MNDebugPrint(MNFace *faces);

Remarks:

Uses DebugPrint to print out information about this MNMap to the Debug Results window in DevStudio. This includes all map verts and faces, one per line.

Parameters:

MNFace *faces

This should be the MNFace array of the parent MNMesh. It’s used to prevent the DebugPrinting of MN_DEAD faces.

Prototype:

bool CheckAllData(int mp, int nf, MNFace *faces);

Remarks:

Checks the MNMap for internal errors, such as a MNMapFace referring to an out of range map vertex. If an error is found, an error message is DebugPrinted, and a the method returns FALSE. This is strictly a debugging tool of no use in releases – a good way to use it is to say DbgAssert (CheckAllData()), so it won’t be called when not in a Debug build, and so it’ll throw up an assertion failure if something’s wrong.

Error messages generated:

Map %d: Wrong number of faces. Should be %d, is %d. (Sent if nf != MNMap::numf)

Map %d, Face %d has wrong degree. Should be %d, is %d. (Sent if f[i].deg != faces[i].deg)

Map %d, Face %d has wrong hdegree. Should be %d, is %d. (Sent if f[i].hdeg != faces[i].hdeg)

Map %d, Face %d has an out-of-range map vertex: %d.

Map %d, Face %d has an out-of-range hidden map vertex: %d

Parameters:

int mp

The map channel this MNMap represents – used to give more helpful debug information.

int nf

The number of faces of the parent MNMesh.

MNFace *faces

The parent MNMesh’s face array. This is used to prevent checking of MN_DEAD faces, which may safely be invalid.

Prototype:

IOResult Save(ISave *isave, MNFace *faces=NULL);

Remarks:

Used internally to save this MNMap to the 3ds max file.

Prototype:

IOResult Load(ILoad *iload, MNFace *faces=NULL);

Remarks:

Used internally to load this MNMap from the 3ds max file.