Specialized Animation Techniques 319
en we have written a simple MEL code fragment. It is: Knob.rotateY = (time *360).
Knob is the name given to the le knob. RotateY is the y-rotation attribute of the
knob. Time is a MEL keyword that represents the frame number divided by the frame
rate. All we have to do is hit Create in the lower le of the Expression Editor and then
run our scene.
(Another way to apply the expression to the knob is to right click on its Rotate attribute,
as seen in Figure11.46.)
Maya now provides some support for scripting using Python, a language that many
other animation applications, including Vue, Rhino3D, Poser, Blender, and Houdini, use.
The Rendering
We have manually keyframed the movement of the bolt into the door as it opens, as well as
the opening of the door itself. e nal frame is shown in Figure11.47. Note the position
of the knob.
A Note on Using the Outliner Window
Carefully building the scene hierarchy is what facilitated the rotation of the knob. e
Outliner window has been used to make
the bolt and the knob children of the door,
thus allowing the bolt and knob to have
their own independent motion, but to also
be constrained by the motion of the door.
USING MAYA EXPRESSIONS AND
VARIABLES TO ANIMATE MODELS
We will look at a couple of examples where
expressions can be used to animate an
object. en, we will look at a few useful
MEL system variables and at dening user
variables.
FIGURE 11.46 Knob expression.
FIGURE 11.47 Moved door and rotated knob.
320 3D Animation for the Raw Beginner Using Maya
Example 1: Applying an Expression to
the Visibility Attribute of an Object That
Has a Material with a Glow Intensity
We will start with our street scene, with the
fog and the car headlights. What we will
do now is color those lights—one red and
one blue—and have them ash on and o
randomly.
e “lights” are actually spheres with
Blinn materials that have a glow inten-
sity. ey are not Maya lights. Figure11.48
shows the attribute editor aer we have
selected the Blinn material for one of them.
We will apply our expression to the visibil-
ity of the two spheres, not to the material on
the spheres.
In Figure11.49, one of the spheres has
been selected in the Main Window, and
we have opened up the Expression Editor
by going to Window at the top of the Main
Menu, selecting Animation Editors, and then choosing Expression Editor. en we clicked
on the visibility attribute in the second column from the le.
The expression, after we have typed it in and hit Create, is at the bottom of the
image.
FIGURE 11.48 Blinn material.
FIGURE 11.49 Visibility attribute.
Specialized Animation Techniques 321
e expression makes use of a random function that reevaluates the visibility of the
sphere for every frame. is is a great function to have, because one of the most dicult
things to do is to create what appears to be partly random movement. We then must do the
same thing to the other sphere.
Finally, Figures11.50, 11.51, and 11.52 show a sequence of three frames spread across
thirty frames of animation. We have ashing emergency lights, perhaps from an approach-
ing policecar.
Example 2: Our Squashing Ball
Earlier, we looked at using a Squash deformer to atten a ball when it hits the ground. You
might remember that we used the scale tool and keyframing to make the ball stretch out as
it went up.
We will do this again but in reverse, and not by using the scale tool. We will use
a squash deformer when the ball hits the oor, as we did before. But we will use an
expression to stretch the ball out as it comes down. e stretch expression is shown in
Figure11.53.
e results are shown in Figures11.54, 11.55, and 11.56.
More Maya Embedded Language (MEL)
Lets take a quick look at some other aspects
of MEL.
Useful MEL Variables
currentTime is a system variablethat con-
tains the current timestamp.
frameis a system variablethat holds the
current frame number. is is very useful,
since expressions get evaluated on every
frame.
FIGURE 11.51 Random render 2.FIGURE 11.50 Random render 1.
FIGURE 11.52 Random render 3.
322 3D Animation for the Raw Beginner Using Maya
User-Defined Variables
Variables created by the programmer always have a dollar sign ($) in the front, for exam-
ple,int $buzzint;.
Aer the $ there has to be a character, and not a number.
Another example of a user-dened variable:oat $buzzarray[] = {1.1, 32.2, 23.3, 14.4,
45.6};
One more example:matrix $buzzmatrix[9] [2] ;
Local Variables
Here are two local variables:
{int $kingint = 1; int $buzzint = 0; if ($kingint = 1) print ($buzzint);};
e curly brackets mark the scoping of the two variables.
Global Variables
is program will print the same result as the one above, but it contains a global and a
local variable:
global int $kingint = 1; proc buzzproc() {int $buzzint = 0; if ($kingint = 1) print
$buzzint;} buzzproc();
FIGURE 11.53 Scale attribute expression.
Specialized Animation Techniques 323
Control Structures
Last, we note that MEL has a handful of control structures. Here is an example:
global int $kingint = 1; proc buzzproc() {int $buzzint = 0; while ($buzzint < 3) {print
$buzzint; $buzzint = $buzzint – 1;};} buzzproc();
Note that this program will run forever.
FIGURE 11.55 e second ball dropping render.FIGURE 11.54 e rst ball dropping render.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.93.210