PDA

View Full Version : How can I use MEL to animate this?


orgeeizm
08-10-2003, 08:39 PM
Lets say I make a box and duplicate it 100 times and having
them placed randomly on the X and Z planes and I would like to animate each box rising up the Y direction with each Y values of the box being incremented randomly. I know how to do this normally in C++ with a graphics lib and it would be something like this pseudocode assuming the boxes are already created:

animateAllBoxesToHeaven()
{
integer index;

for index = 0 to 100
{
box[index].y -= random(3);
}
}

main()
{
animateAllBoxesToHeaven();
}


Basically after I create the scene with the random boxes, how would I or where would I code the MEL script to keep the boxes animated going up and up with random increments throughout the whole range of time my animation regardless how long it is.
So if the frame range was 0-360, the script would go from frame 0 till 360 but I only write it once.

http://www.orgeeizm.net/pix/boxquestionss.jpg

CRAP!!! Sorry Moderator, i put this on the wrong section, shouldve been on the MEL section. :banghead:

boraddd
08-10-2003, 10:28 PM
i`ll show you one way of doing this,
first, using a script i`ll create an foat array to define each boxes random Y speed than i`ll use those random speeds to move boxes in an expression.... here is how;

1st run this script once;

global float $ySpeed[];
string $box[];
$box=`ls -tr "box*"`;
for($n=0;$n<`size($box)`;$n++){
$ySpeed[$n]=rand(0.1,0.5);
}


than create this expression

global float $ySpeed[];
string $box[];
$box=`ls -tr "box*"`;
for($n=0;$n<`size($box)`;$n++){
if(frame==1) setAttr ($box[$n]+".ty") 0;
move -r 0 $ySpeed[$n] 0 $box[$n];
}

hope this helps

orgeeizm
08-10-2003, 10:46 PM
Ahh Thank you. But ehh, I want the box Y speed to be not set.
When you created the array, it created a static Y increment value for the corresponding box.

i.e: lets say $yspeed[23] == 2.4;

$box[23] would always be using 2.4 as its decrement value.

But if i wanted to make it random, i would do this inside the the move loop:

$ySpeed = rand(0.1, 0.5);
move -r 0 $ySpeed 0 $box[$n];

so that for example, box[23] would always have a different Y increment value.

OK Another question:

You say to run that first script once. And so it creates the array $ySpeed and im taking it stores it in the scene file, how would I get to this $ySpeed and delete it or do some things with it?
Basically im looking for like an 'Outliner' for the array created with the script.

Thanks for your help! =)

I should get a MEL book than read the A|W Manual so i can stop asking these noobs questions hehe.

boraddd
08-10-2003, 11:24 PM
easiest way is to create an expression like this

global float myarray[];
if(frame==1){
seed 153723;
// set the random values for myarray here
}

you can also write that array to a text file using fopen fwrite and such....


but don`t forget you can also key frame the animation once you get it as you like(->bake simulation)

orgeeizm
08-10-2003, 11:45 PM
Thanks! Youve been very helpful.

CGTalk Moderation
01-15-2006, 08:00 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.