Kornelius
Hello hello!
I really don't like mel, but as far as I know there is no way to use python or pymel in the expression editor. (please correct me if I'm wrong..)
Let's say I've got a nice swarm of particles and i want to drive the scale of them with a random value between 2 and 11.
I've created an attribute called randScalePP wich is a float array and assigned it a very basic creation expression.

nParticleShape1.randomScalePP= rand(2,11);

Now, I'd like to have more contrast between big and small particles, and filter out the values of randScalePP from 4 to 7.
In this way I'll have very small or very big instances.
I thought about an IF selection that assign 2 or 11 if the number choosen is inbetween 4 and 7.
But I'm pretty sure there is a smoother way to do this.
Cheers!!
Simo.
win 7 maya 2014 x64
Reply 0 0
Kornelius
ok, this is what I came out with so far:

nParticleShape1.randomScalePP=python("import random;sample([2,3,7,8,9,10],1)[0]+random.random()");

all of this in the expression editor.
But I'm pretty sure there's an alternative way to do this smoothly, even if (with my surprise) the python command doesn't slowdown very much the simulation speed.
win 7 maya 2014 x64
Reply 0 0
JeremyR
I would do it this way, for no other reason than this is my preferred workflow.
I would use mel's rand command still and then use lifespanPP to kill off anything that is born with a scale you dont really want. If you still require a few of these guys at that scale then you could include  particleID and modula in the if condition to keep those ones alive. So...

if (particleId%5==0 && scalePP>2 && scalePP<4)
lifespanPP==100
else if (scalePP>2 && scalePP<4)
lifespanPP==0

it can get messy when you have a lot of variables you want to include but it works on smaller expressions.
Reply 0 0
Kornelius
Can't you get rid of the "else if" construct?

if (scalePP>2 && scalePP<4||......){
  lifespanPP==100;
}
else{
  lifespanPP==0;
}

Cheers!
win 7 maya 2014 x64
Reply 0 0
JeremyR
they are the same thing really, sometimes its good to be explicit rather than throwing all other variables into an else I find, but you can experiment with what works for you.
Reply 0 0
Kornelius
Cheers, Jeremy!
win 7 maya 2014 x64
Reply 0 0
Reply