Pages

Friday 26 October 2012

nCloth instances

I have been working on a confetti shot and wanted to use nCloth. I decided to use a particle emitter and to instance the nCloth object onto the particles - but how? If I were to simply assign the nCloth object to the instance, then each instance would be identical. I wanted to have a different starting point in the nCloth cache for each instance. Unfortunately Maya's instancer doesn't support this kind of connection. I tried to use an userScalarPP attribute along with a particle sampler to access the cacheStart attribute on the nCloth cache, but that didn't work.

Here's how I did it:

First cache the nCloth object

Export the nCloth as a sequence of OBJs. I used a python script called objsExporter_v2 from Christos Parliaros

Re-import the OBJ sequence using Dave Girard's objSequenceImporter

Use the imported OBJs to create an instancer with cycling set to On

On the particle object I setup a per-particle attribute; cyclePP and used this to select the correct OBJ in the sequence. For example, if there are 30 OBJs in your sequence, in the creation expression:

cyclePP=0;

and in the Runtime before dynamics:

cyclePP=(cyclePP+1) % 30;

so the nCloth object will loop through the cache and start from the beginning at the end of the loop.