Hi Joojaa, after browsing for a while on CreativeCrash to find mel script help, I thought you must have the answers to my problems. Can I hire you on a project ? Is there any way to reach you ?
Otherwise, here's my trouble below:
I'm trying to make an animated field of barley for this animated film that I'm making with my wife. I previously struggled and asked questions here and I evolved to other solutions.
The foreground strands are made of planes with 5 subdivisions in height, bended vertically by a bend deformer.
The middle and background strands are nParticle sprites, showing billboards of 5,10,20, and 50 barley strands together.
I put a script node at Open to initialize the coordinates of the foreground strands and global variables:
global proc int init{
global int $nbPlants = 1000;
global matrix $coord[10000][2];
global float $color[];
global float $tmpcoord[];
global string $alphabet[] = {"a","b","c","d","e","f","g","h","i","j"};
global float $fractalScale;
$fractalScale = getAttr("previewFractal.scaleX")/2;
for ($j=0;$j<10;$j++){
for ($i=$j*$nbPlants;$i<($j+1)*$nbPlants;$i++){
$obj = "barley"+$alphabet[$j]+(1+$i%$nbPlants);
$tmpcoord = xform -ws -q -t $obj;
$coord[$i][0] = ($tmpcoord[0]+($fractalScale/2)) / $fractalScale;
$coord[$i][1] = ($tmpcoord[0]+($fractalScale/2)) / $fractalScale;
}
}
}
4. To animate those fg strands, there's an expression:
if(!$fractalScale){init();} // that was to force the execution of the node, but it still doesn't work.
for ($j=0;$j<10;$j++){
for ($i=$j*$nbPlants;$i<($j+1)*$nbPlants;$i++){
$color = colorAtPoint -u $coord[$i][0] -v $coord[$i][1] -o "RGB" fractal;
setAttr("bend"+$alphabet[$j]+(1+$i%$nbPlants)+".curvature") (($color[0] - 0.5) * 1.2);
}
}
5. Then to animate all the nParticle strands, each of them (billboard of 5, 10, 20... strands) have their own Runtime Before Dynamics which looks like this:
float $pos1[] = particule_gBackShape.position;
$pos1[0] = ($pos1[0]+($fractalScale/2)) / $fractalScale;
$pos1[2] = ($pos1[2]+($fractalScale/2)) / $fractalScale;
float $color1[] = colorAtPoint -u $pos1[0] -v $pos1[2] -o "RGB" fractal;
particule_gBackShape.spriteNumPP = int($color1[0]*200);
Here are the issues:
Sometimes, Maya doesn't load the script node when the scene opens: none of the variables are initialized, nothing works.
- On a network rendering accross 20 computers, frames are frozen, skipped... Not even a single frame is usable.
It is very slow (about 30 seconds per frame for a playblast). There are 10,000 close up strands, and about 200,000 sprites.
I understood from your replies on this post http://www.creativecrash.com/forums/mel/topics/run-script-every-frame that it's not efficient to use a script on the Runtime before dynamics, and other expressions that would run on each frame, but rather use a script inside the script editor, that would vary with the time. But I don't know how to write such a script. Your precious help would be very welcomed.
/forums/mel/topics/run-script-every-frame