PDA

View Full Version : API: set nParticle positions


ciclopez
12-18-2012, 04:15 PM
Hi,
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");
dagMod.doIt();

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

particle.setObject(partShape);
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?

Thanks!

sciLoop
12-18-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:
MFnParticleSystem::saveInitialState();
for that.

ciclopez
12-18-2012, 04:38 PM
That works :cool:
Many thanks!

ciclopez
12-19-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...

Thanks!

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

zoharl
12-20-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:

http://www.creativecrash.com/forums/mel/topics/delete-particles
http://forums.cgsociety.org/showthread.php?t=81945

sciLoop
12-20-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
MFnParticleSystem::findPlug
to get the attribute/
MGlobal::executeCommand
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
MFnParticleSystem::setInitialState()

CGTalk Moderation
12-20-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.