View Full Version : API: set nParticle positions

12 December 2012, 04:15 PM
I'm trying to create a command plug-in that scatters particles (nParticles) inside closed geometry, and it's actually working, but the problem is that when I play some frames and return to the first frame of simulation, the particles are deleted.

This is the part of the code where I create the nParticle:

MDagModifier dagMod;
MFnParticleSystem particle;

MObject partTransform = dagMod.createNode("nParticle");

MFnDagNode dagFn(partTransform);
MObject partShape = dagFn.child(0);

particle.emit(scatteredPoints); // scatteredPoints is a previously calculated MPointArray

What is the correct way of adding particles to an nParticle node, as the "particleFill" command does?


12 December 2012, 04:26 PM
You obviously forgot to set the initial state for the particles.
For the position attribute, for example, there`s a position0 attribute where the initial state is saved.
The API gives you:
for that.

12 December 2012, 04:38 PM
That works :cool:
Many thanks!

12 December 2012, 04:03 PM
Hi again,
I have a new question. What's the way to delete all particles or individual particles from a nParticle node?

I'm thinking on setting the age to "1" and using
MFnParticleSystem::evaluateDynamics()for one frame.

Would that work or is there a better way of doing this?
EDIT: I tried this and it's not working. Maybe I'm missing something...


12 December 2012, 02:55 AM
Age normally refers to one second in dynamics rather than 1 frame. Im not sure about the API though.

12 December 2012, 04:50 AM
If you need to delete all the particles, maybe you should just delete the particle system. To delete individual particles maybe:

12 December 2012, 09:58 AM
If you want to kill individual particles, you should set the lifespan mode to "lifespanPP". Or, if it does not exist, create it.
If you want to do that with the API, use
to get the attribute/
to add the attribute.

You got to set the lifespanPP as a MDoubleArray. So, find the particles you want to kill and set the individual array-elements to zero, than create a MObject with that array, set the plug with ::setValue and, again, apply

CGTalk Moderation
12 December 2012, 09:58 AM
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.