8
356 Chapter 12: Animation
Script Controller
Maintoolbar>CurveEditor(Open)>Selectatrackinthe
Track View hierarchy. > Track View menu bar > Controller
menu>Assign>Script
Graph Editors > Track View - Curve Editor > Select a track
in the Track View hierarchy. > Track View 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
•
Tr ansform Script (page 2–364)
matrix3 PRS
controller
The Script controllers work similarly to
Expression
controllers (page 2–315)
.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 M AXScript
language, including loops, scripted functions,
and path names.
• Almost any prop erty of any object in a scene
can be used to help compute controller
values, including mesh vertices, values of
properties at arbitrary fr ame times, and
other non-animatable properties that are not
accessible in Expression controllers.
• They can use M AXScript 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 S cripts
3ds Max interprets the text you type into the
Script text box as the body of a MAXScript block
expression. You can type 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 can declare loca l variables that are visible
only w ithin 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 ti me slider or increment ing frame time
if an animation is playing, or a rendering is under
way. In the case 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 time” expressions) yield the correct
values for the current controller evaluation time.
Thismeansyoudon’thavetodoanythingspecial
in your scripts to work at the correct time. You
can access the evaluation time with 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.
Assign Nodes and Tracks to Variables
When you need to refer to no des in your scene
or to animation tracks, it is recommended that