Feedback

What's your question?

By: Asked

Creating a custom node with a mesh in Maya

Hi, I create a mesh with the Maya API using the create function from the MfnMesh function set. I would like to be able to add a type id to it to allow me to retrieve all the object of that type. I would also like to a an attribute to store related data in the scene.

At the moment, I am thinking about deriving MPxNode, but I'm not sure where I would have to put my code to create the mesh. Also, I don't think I should use MPxSurfaceShape because I don't want to have to rewrite everything (bounding box, drawing etc).

Any advice on the best way to create a Mesh with a custom type id and attributes ?

Add comment viewed 748 times Latest activity 11 months ago

or Cancel

1 answer

  • 2

julian [ Admin ]

You can write a node, derived from MPxNode, and construct mesh geometry in there. For the geometry you need vertex positions, face counts, and connectivity. See the docs for a good explanation of how geometry is specified. Basically the face counts and connectivity arrays are MIntArrays containing the number of vertices per face, and the vertex ids for those faces respectively. When you have those arrays you can build meshData and put it on the output plug of your node. Then in maya you connect that output to a mesh node, which takes care of drawing and many other meshy things like connections to deformers and bounding box calculations.

Here's how you create and output the mesh data in your node's compute: (note - assume you have valid vertices, faceCounts, and connectivity. Also I left out error checking)

MFnMesh fnMesh;
MObject outGeom;
MFnMeshData fnData;
outGeom = fnData.create();
fnMesh.create( vertices.length(), faceCounts.length(), vertices, faceCounts, connectivity, outGeom );

// data is the dataBlock, aOutMesh is the output plug
MDataHandle hMesh = data.outputValue(aOutMesh);
hMesh.set(outGeom);
data.setClean(aOutMesh);

Here are a couple of plugins that create meshes:

particle_mesh This is a little complex, but it illustrates creating the mesh from vertex, counts and connectivity arrays.

shrink_wrap This makes a copy of the input mesh, modifies its vertex positions, and outputs the new mesh.

Both these nodes have their own type of course, so you can type in MEL for example:

`ls -type "shrinkWrap"`; 

And both show how to add attributes to the node. Look in the initialize() function.

NN comments
julian
-

cool – glad to have helped

or Cancel