View Full Version : Find output mesh vertex for given nCloth particle

04 April 2011, 07:46 PM
Hello there,

I've got the following problem: I am simulating an nCloth mesh in Maya 2011. So far, I found that the particle data of the nClothShape node is accessible, and I can even attach dynamic expressions to it like with a particleShape node (i.e. I get expressions to run before and after the dynamic calculations, as well as at particle creation).

What I need to do in one such expression, is find what vertex (in the mesh that the nCloth simulation is deforming for me) corresponds to a given nCloth particle. In this particular case, the nCloth is tearing by means of a tear constraint. When the tear constraint is created, the nClothShape immediately creates extra particles on the vertices that are assigned to this constraint, in order to simulate the two sides of the tear. But the mesh only has the original amount of vertices, until the tear rips. Only at that point, will the mesh have an additional vertex for each ripped vertex. But how can I know which nCloth particle is connected to which vertex using MEL?

At first I (sheepishly) assumed that the vertex IDs on the output mesh would always correspond to the nCloth particle IDs, but since the nCloth particles are created right away, while the mesh vertices are obviously not, this is not true.

I have found a (rather clumsy) way to query which vertex is closest to a given position in space, using the polySelectConstraint command, but there has to be a better and more reliable way to figure out the relation between nCloth's particles and the vertices of the outputMesh node.

Any help would be greatly appreciated.

04 April 2011, 03:13 PM
To answer my own question: As with many things, Maya tries to "smart" and "efficient", keeping the correlation implicit by using the same ID numbers. This saves on lookup. Maya does this also in the above scenario, but I've been looking in the wrong place. I was looking at the vertices of the output mesh, i.e. the "outputCloth" mesh shape that the nCloth simulation generates. Turns out, that mesh can be merged after the simulation. As a matter of fact, when one creates a tear constraint, Maya goes back to the original input mesh, splits the edges, and then adds the nConstraint appropriately. One could do this manually as well, because at the end of the day, what matters to nCloth, is simply which vertices are connected, and which are not. (To verify: add a tear constraint to an nCloth, then remove the entire nCloth stuff using nMesh -> Remove nCloth ... you will end up with the original mesh, but the edges where the tear constraint was, will now be detached!)

So the bottom line is: the particleId values correspond to the vertexId values of the input mesh.

I hope this helps someone else one day.

CGTalk Moderation
04 April 2011, 03:13 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.