Build Mesh and Convert to MNMesh

If you want to write a plug-in object in Max, probably you are starting with the Widget example offered by Max SDK. It is a class derived from SimpleObject2, so it can only have triangular Mesh. Inside BuildMesh() method, this is howto create a simple mesh with only one quad face:

mesh.verts[0] = Point3(0.0,0.0,0.0);
 mesh.verts[1] = Point3(10.0,0.0,-0.5);
 mesh.verts[2] = Point3(10.0,10.0,0.0);
 mesh.verts[3] = Point3(0.0,10.0,1.5);
mesh.faces[0].v[0] = 0;
 mesh.faces[0].v[1] = 1;
 mesh.faces[0].v[2] = 2;
 mesh.faces[1].v[0] = 0;
 mesh.faces[1].v[1] = 2;
 mesh.faces[1].v[2] = 3;
mesh.setMapSupport(1, TRUE);
MeshMap& map = mesh.Map(1);
 map.setNumFaces(2);[0]=UVVert(0,0,0);[1]=UVVert(1,0,0);[2]=UVVert(1,1,0);[3]=UVVert(0,1,0);[0].setTVerts(0, 1, 2);[1].setTVerts(0, 2, 3);

Actually there are 2 triangles. But as long as there is:


It will appear to be a single quad face. Now turn off the object display of “Edge Only”, the hidden edges will show up as a dotted line, two overlapped dotted lines indeed.

So how to convert Mesh to MNMesh? In fact you don’t have to, Max will do that for you. If you attached an EditPoly modifier to the Mesh object, it will be converted to Poly (MNMesh), unless you bother to override the ConvertToType() method, in which you can explicitly create an MNMesh and send to the pipeline. Don’t think that is necessary if you want the mesh unchanged.

Then how Max converts Mesh to MNMesh? I suggest Max traverses through all those triangles, looking for hidden edges, and remove those hidden edges to merger triangles into polygons. So the mesh we built above will be converted to a single quad face. The catch is Max will merger any triangles happened to be meeting at the same hidden edge, regardless whether those triangles are from the same “face”. That could lead to unexpected conversion. So set hidden edges carefully.


Leave a comment

Filed under Max SDK

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s