9

372 Chapter 12: Animation
Script Controller
Maintoolbar>CurveEditor(Open)>Selectatrackinthe
Track View hierarchy. > Track View menu bar > Controller
menu>Assign>Script
Graph Editors > Track V iew - Curve Editor > Select a track
in the Track View hierarchy. > Track V iew menu bar >
Controller menu > Assign > Script
The following Script controllers are available in
the software:
Float Script - float controller
Position Script - position Point3 controller
Point3 Script - Point3 controller
Rotation Script - rotation Quaternion controller
Scale Script - scale Point3 controller
Transform Script (page 2–379)
matrix3 PRS
controller
The Script controllers work similarly to Expression
controllers (page 2–320).TheyprovideaScript
Controller dialog where a script can be entered
for computing the controller value. The primary
advantages of Script controllers are:
They can use all the features of the MAXSc ript
language, including loops, scripted functions,
and path names.
Almost any property of any object in a scene
can be used to help compute controller
values, including mesh vertices, values of
properties at arbitrary frame times, and
other non-animatable properties that are not
accessible in E xpression controllers.
They can use MAXScript global variables
to communicate and coordinate with other
controllersandscriptsinthesoftware.
Refer to the MA XScr ipt Reference for a complete
explanation of this scripting language.
Writing Controller Scr ipts
3ds Max interprets the text you type into the
Script text box as the body of a MAXScript block
expression. You can ty p e as many expressions
as you want on as many lines as you want, and
they are evaluated in turn. The value of the last
expression is taken as the controller value. This
valuemustyieldtherighttypeforthecontroller:
Float for float, Point3 for position, Quat for
rotation, and so on.
Because the text is inside a block expression,
you c an declare local variables that are visible
only within the script and are temporary for one
evaluation. You can also declare or access global
var iables that are shared with all other scripts
in MAXScript and hold their values from one
evaluation to the next.
Acontrollerisalwaysevaluatedby3dsMaxwith
respect to a specific animation time. This might be
the current t i me slider or incrementing frame time
if an animation is playing, or a rendering is under
way. In the c ase of Script controllers, the time
being evaluated is used to establish an automatic
"attime"contextaroundthecontrollerscript,
so any properties you access (outside of other
explicit “at t ime expressions) yield the correct
values for the current controller evaluation time.
Thismeansyoudonthavetodoanythingspecial
in your scripts to work at the correct time. You
can access the evaluation time w ith the standard
MAXScript variable, currentTime. You can also
reference scene property values at other times by
using "at time" expressions in your scripts, as in
regular MAXScript programming.
Ass ign Nodes a nd Tra ck s to V ar i ab les
When you need to refer to nodes in your scene
or to animation tracks, it is recommended that