PDA

View Full Version : particleShape name in expression


akril
07-29-2008, 07:32 PM
Hi everybody,
I have a big trouble on my particle expression and I'm not able to figure out how to fix it. So I hope you will help me to find the way...
Actually, I put all my expressions (creation, rbd and rad) in 3 differents files. It's pretty usefull 'cause these are long expression scripts.

Using a script I build my dynamics setup (particle, emitter, goal and fields) and afterwards I call each files separetly (store the result in a string) to create each expression using the dynExpression command.
Sometimes Maya is pretty smart :applause:, for instance in the creation of the particles expression is able to replace the attribute "position" or "rgbPP" by the name "particleShape.position" or "particleShape.rgbPP". That's usefull because I don't want to use any particleShape in my expressions files... it's better for kinda dynamic setup.

But...I guess this is the but you waiting for... if I use the attribute name as command parameters (`listConnections goalGeometry[0]`)... it's not working and I'm affraid there's no way for Maya to replace it.

This is an example of an expression file :

// maya will replace "position" by "particleShape.position"
vector $pos = position;
vector $vel = velocity;

goalPP = 1;

// here I need to retrieve the goal Shape in order to send it to an inhouse plug... but it's not working because maya don't replace goalGeometry[0] by particleShape.goalGeometry[0]
string $buf[] = `listConnections -p 1 goalGeometry[0]`;
string $goalShape = plugNode($buf[0]);

// so I'd like to use this syntax... If I set the valid name it works but i don't know how to retrieve it as string inside the expression.
string $pShape = THE_PARTICLE_SHAPE_NAME
string $buf[] = `listConnections -p 1 ($pShape+".goalGeometry[0]")`;
string $goalShape = plugNode($buf[0]);

string $eConnect[] = `listConnections ($pShape+".newParticles[0]")`;
string $emitter = $eConnect[0];

Some people propose me to store the shape name, the emitter name and the goal shape name in attributes but it's not a dynamic way and I really don't like this way. If the user change the particle Shape name it will crash :-/

so if anyone have some tips to share.. I will appreciate ;-)
thanks.

zoo-prod
07-29-2008, 10:30 PM
Maybe you could use a little simple script that you launch before your simulation. To store the name of your particle shape in a string... And then call this string in your expression.

YourDaftPunk
07-29-2008, 11:07 PM
So you have a call something like this?
dynExpression -c -s $theFileString paritcleShape1;

Right before that couldn't you run a substitute command with a simple regular expression to replace a unique word with the correct current particle name? You might then have:

string $file; // your file you read in
string $regularExpr = "@@@@"; // what we replace
string $pExp; // the adjusted particle expression

for ($node in $particleShapeNodes) {
string $pExp = `substitute $regularExpr $file $node`;
dynExpression -c -s $pExp $node;
}

And that line in your file would look like:
string $buf[] = `listConnections -p 1 @@@@.goalGeometry[0]`;

Aikiman
07-30-2008, 12:44 AM
Then capture the particle shape by having to select the particle first and write this code in the beginning of your script.

pickWalk -d down;
string $particle[] = `ls -sl`;
print $particle;

or use a global proc where you write in your particle as in

global proc yourMel( string $particleShape )

Either way would work and is more flexible than your way because yours assumes there is only one particle shape in your scene at one time. The above code means you can have many particle shapes but because you are specifying which one, maya knows where to apply the expression.

akril
07-30-2008, 10:14 AM
ok so... I think there was some misunderstanding of my explanations.

Boris, heureux de te voir ici ;-)... alors la Nouvelle Zelande c'est cool ?
In fact, use a simple string to store the particleShape name in the particle expression will not resolve the trouble.

YourDaftPunk, I already tried your tips (with "substituteAllString" command) but it will also not resolve the maya errors. Let's try this example in maya.

seed(particleShape1.particleId);

vector $pos = particleShape1.position;
vector $vel = particleShape1.velocity;

string $buf[] = `listConnections -p 1 particleShape1.goalGeometry[0]`;

If you change the name of your particle (so the shape name as-well)... the expression make some failures because Maya don't replace the shape name in the last line. That's why I need to retrieve "dynamically" the particle shape name in a string and not like a simple string in order to change the particle name as I want.

thanks for your replys ;-)

YourDaftPunk
07-30-2008, 07:56 PM
Ah! I see what you are saying. So the user is changing the name of the particle shape nodes after the script is run and the expressions are built... How about attaching a script job which can run when the particles are renamed?

CGTalk Moderation
07-30-2008, 07:56 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.