PDA

View Full Version : particle expression broken after save?


ginodauri
01-25-2011, 02:09 AM
Hi

I particles running on nurbs plane.
I'm trying to duplicate some object to particles.
It is like particle instancing , but instancing has some limitation etc.

http://vimeo.com/19154877

So in general:

1.duplicate object with history
2.place this object to particle
3.orient this object
4.Adjust object cache based on scale and particle velocity.

I have three expressions:

Non-particle expression

if(frame==1){delete `listRelatives -children "instances"`;}


This to delete all objects in first frame.

--------
Creation expression:


particleShape1.rand1=`rand 0 1`;
particleShape1.lifespanPP=rand(5,10);

float $randScaleMin=`getAttr Ctrl.randScaleMin`;
float $randScaleMax=`getAttr Ctrl.randScaleMax`;

string $inst[]=`duplicate -upstreamNodes -name ("inst_"+ particleShape1.particleId) object`;
parent $inst[0] "instances";
float $randScale=`rand $randScaleMin $randScaleMax`;
setAttr -type "float3" ($inst[0]+".s") $randScale $randScale $randScale;


This is where object get created on particle creation.
-------
Runtime expression



float $cacheScaleMult=`getAttr Ctrl.cacheScaleMult`;
float $worldPos[]=particleShape1.position;
float $partVel[]=particleShape1.velocity;
float $goalU=particleShape1.goalU;
float $goalV=particleShape1.goalV;
setAttr -type "float3" ("inst_"+particleShape1.particleId+".t") $worldPos[0] $worldPos[1] $worldPos[2];//objects position

vector $frontVector=<<$partVel[0],$partVel[1],$partVel[2]>>;
float $normal[]=`pointOnSurface -u $goalU -v $goalV -normalizedNormal nurbsPlaneShape1`;
float $frontVectorNorm[]=unit($frontVector);
float $thirdVector[]= crossProduct($frontVectorNorm, $normal, 1, 1);

setAttr ("fbfm.in00") $frontVectorNorm[0];
setAttr ("fbfm.in01") $frontVectorNorm[1];
setAttr ("fbfm.in02") $frontVectorNorm[2];

setAttr ("fbfm.in10") $normal[0];
setAttr ("fbfm.in11") $normal[1];
setAttr ("fbfm.in12") $normal[2];

setAttr ("fbfm.in20") $thirdVector[0];
setAttr ("fbfm.in21") $thirdVector[1];
setAttr ("fbfm.in22") $thirdVector[2];

float $outRotate[]=`getAttr ("dm.outputRotate")`;

setAttr -type "float3" ("inst_"+particleShape1.particleId+".r") $outRotate[0] $outRotate[1] $outRotate[2];

//cache speed
string $nodeHistory[]=`listHistory ("inst_"+particleShape1.particleId)`;

for ($hisNode in $nodeHistory){
if(`nodeType $hisNode`== "cacheFile"){
string $trans[]=`listRelatives -parent $nodeHistory[0]`;
float $nodeScale=`getAttr ($trans[0]+".sx")`;
float $vel = `mag($frontVector)`;
setAttr ($hisNode+".scale") ($nodeScale*$cacheScaleMult*(1/($vel>0?$vel:1)));
}
}


----------------------------------------------


When i create this runtime particle expression everything is fine.
But when i save scene , and open it , everything is broken.
Like when i delete all particle expressions particles don't emit anymore etc...

Then when i want to create new scene maya crashes.

Someone has some clue why this is happening?

P.S.
Two questions regarding this.

1.With duplicate command maya select duplicate object,how to avoid this?
2.How to get dead particles id's?
I know this is possible throw mel,python "custom" procedure , but is there some easy way?

jschieck
01-26-2011, 02:39 PM
the duplicate command doesn't select the newly duplicated item unless you have the item your duplicating selected as far as i know.

not sure about getting dead particles but you could just store the id's in an array each frame then compare them and the missing ones are the dead ones.

no idea why your expression messes up on save tho, weird.

ginodauri
01-26-2011, 04:43 PM
I made it work but with regular expression.

This is not first time i have problems with particle expression when using mel code.

Obviously it is not designed to write to much mel , and things can go wrong.

About dead particles i solve it with python sets with mel it is too much effort.

With expression running i see objects in viewport get selected on creation.

Btw in the end i rewrote mel expression in python as procedure and i only call procedure in expression.

CGTalk Moderation
01-26-2011, 04:43 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.