 Make a surface |
week 8
|
|
-
Folding Surface
This exercise will walk you through making animated surface using the 'turtle' commands and Maya's built-in object history. The technique uses two steps. The first step uses the 'turtle' commands to create splines and the 'loft' command to make a surface between them. The next step is to use the 'turtle' commands to repeatedly reposition the points on the original splines and keyframing them. With the original splines animated to move, the surface will automatically move to keep up with the splines because of Maya's object history.
This technique of animating surfaces is indespensible for creating animations that would otherwise be impossible or prohibitively time-consuming. In this example you will be make a folding surface that could be used as a retractable wall or roof.
[Click here for animation of end result]
Step 1
 Make a surface
The first step is to create a surface using two curves created with the 'turtle' commands. This can be done by making two turtles and using two loops, then using the 'loft' command to create a surface between the two.
///////////////////////////////////////////////
// generate a surface
//
//surface 1
//make a turtle, set its starting position and use a loop to make 20 points
$turtle = aa_turtle_newturtle("CURVE");
aa_turtle_setPosition($turtle,<<0,0,0>>);
$i = 0;
while($i < 20){
aa_turtle_move($turtle,10);
$i++;
}
//surface 2
//make a turtle, set its starting position (over 100 from the last)
//and use a loop to make 20 points
$turtle2 = aa_turtle_newturtle("CURVE");
aa_turtle_setPosition($turtle2,<<0,0,100>>);
$i = 0;
while($i < 20){
aa_turtle_move($turtle2,10);
$i++;
}
//get the names of the curves generated by the two turtles
$curve1 = aa_turtle_getCurve($turtle);
$curve2 = aa_turtle_getCurve($turtle2);
//create a lofted surface between the two curves
loft $curve1 $curve2;
Step 2
 Animate the surface by repositioning the curves
The second step takes the two curves made in Step 1 ($curve1 and $curve2) and animates them to move. This is done by using a new turtle as a positioning tool, moving the points of $curve1 and $curve1 to new positions and keyframing them. To do this it takes two nested loops.
The inner loop takes a turtle and loops through creating points and using the new points to position the $curve1 and $curve2. The loop that moves the turtle uses the MEL 'sin' function to make the curve a sine-wave.
The outer loop is used to set the current frame in the animation. The loop moves the time incrementally forward so that each new set of positions for the curves can be key-framed at new times.
///////////////////////////////////////////////
// animate the surface
//
// create two loops
// the first loop ($j) will be used to step through keyframes, going from frame 1 to 100, every 10
$j = 0;
while($j < 100){
currentTime $j;
$turtle = aa_turtle_newturtle("CURVE");
$i = 0;
while($i < 21){
aa_turtle_move($turtle,(10));
aa_turtle_turn($turtle,0,($j * sin($i)));
//get the position of the point
$position = aa_turtle_getPosition($turtle);
//move and animate curve 1
//use this position and move the CV of the first curve from the original curve to match this position
$cv= $curve1 + ".cv[" + $i + "]";
move $position[0] $position[1] $position[2] $cv;
//key frame it.
setKeyframe $cv;
//move and animate curve 2
//use this position and move the CV of the second from the original curve to match this position
$cv= $curve2 + ".cv[" + $i + "]";
move $position[0] $position[1] ($position[2] + 100) $cv;
//key frame it.
setKeyframe $cv;
$i++;
}
//increase j by 10 (so that it animates every tenth frame)
$j = $j + 10;
}
Step 3
The third step is to adjust the behavior of the animation so that the surface doesn't just fold, but also retracts. This can be done by progressively shortening the distance that the turtle move each time. Also, a second adjustment is to turn each turtle slightly each time so that the surface does not fold down, but merely retracts. To do this, make the few adjustments noted in the code below and re-run the entire script. To re-generate the animation you will need to delete everything in your scene, so you will need to run both parts of the script (the script that generates the surface, and the second portion that animates it), both scripts are included below.
///////////////////////////////////////////////
// generate a surface
//
//surface 1
//make a turtle, set its starting position and use a loop to make 20 points
$turtle = aa_turtle_newturtle("CURVE");
aa_turtle_setPosition($turtle,<<0,0,0>>);
$i = 0;
while($i < 20){
aa_turtle_move($turtle,10);
$i++;
}
//surface 2
//make a turtle, set its starting position (over 100 from the last)
//and use a loop to make 20 points
$turtle2 = aa_turtle_newturtle("CURVE");
aa_turtle_setPosition($turtle2,<<0,0,100>>);
$i = 0;
while($i < 20){
aa_turtle_move($turtle2,10);
$i++;
}
//get the names of the curves generated by the two turtles
$curve1 = aa_turtle_getCurve($turtle);
$curve2 = aa_turtle_getCurve($turtle2);
//create a lofted surface between the two curves
loft $curve1 $curve2;
///////////////////////////////////////////////
// animate the surface
//
// create two loops
// the first loop ($j) will be used to step through keyframes, going from frame 1 to 100, every 10
$j = 0;
while($j < 100){
currentTime $j;
//change the turtle command so it doesn't actually draw curves while it moves
$turtle = aa_turtle_newturtle("");
//change the initial orientation of the turtle so that it doesn't
//slowly bend downwards as it folds
aa_turtle_turn($turtle,0,(-1 * $j));
//start the loop that moves the lines
$i = 0;
while($i < 21){
//change the movement to be incrementally less each step
aa_turtle_move($turtle,(10 - ($j/10)));
aa_turtle_turn($turtle,0,($j * sin($i)));
//get the position of the point
$position = aa_turtle_getPosition($turtle);
//move and animate curve 1
//use this position and move the CV of the first curve from the original curve to match this position
$cv= $curve1 + ".cv[" + $i + "]";
move $position[0] $position[1] $position[2] $cv;
//key frame it.
setKeyframe $cv;
//move and animate curve 2
//use this position and move the CV of the second from the original curve to match this position
$cv= $curve2 + ".cv[" + $i + "]";
move $position[0] $position[1] ($position[2] + 100) $cv;
//key frame it.
setKeyframe $cv;
$i++;
}
$j= $j + 10;
}
|
week 8
|