9
Script Controller 373
you use the Scr ipt controller variable toolset to
create variables to assign to any particular node or
controller track. This way, if you decide to later on
rename your scene objects, the scr ipt controllers
usingtheseobjectsarepreservedbecausethe
variables maintain the link to the nodes.
Otherwise, if you assign, for example, a node to
a variable manually in the dialog’s Expression
window, that link b ecomes broken as soon as you
rename that particular node.
Note: It is especially important to assign nodes and
tracks to variables with the corresponding buttons
when using XRef scenes and object s.
Procedure
Ex ampl e: To k eep an object centered rela tiv e to
other objects in the s cene dur ing a n ani mation:
1.
Name the object that should remain centered
foo and assign a Script controller to its Position
track.
2. Enter foo in the Name field and click Create.
The new variable is automatically added to the
Va r i a b l e s l i s t .
3. With the variable highlighted, click Assign
Node.
The Track View Pick dialog opens, listing the
contents of your scene.
4. Expand the Objects hierarchy u ntil you locate
foo.HighlightitandclickOK.
The foo node is assigned to your var iable.
5. Enter the following script in the Script
Controller dialog’s Expression window:
local p os=[0,0,0]
for o i n object s w here o != foo do
pos += o.pos
pos / (objects.count - 1)
This script computes the average position of
all objects, except the cu rrent one (written as
foo here) by setting up a local, iterating over
all objects except foo, accumulating a total
position vector, and computing the a verage
in the last line, which is the final result of the
script.
Interf ace
Assigning a Script controller automatically opens
aScriptControllerdialogwhereyoucanentera
script. You can open the dialog subsequently by
right-clicking the track on the Motion panel or in
the Track View hierarchy and choosing Properties,
or clicking the Properties button on the Track
View toolbar .
Tip: You can resize the dialog by dragging an edge
or a corner.
Create Variable group
Name—Lets you enter and edit the name of user
variables.
Cr e a te—Createsavariableandaddsittothe
Var i a b l e s l i s t .
Delete—Removes the highlighted v ariable from
the Variables list. You can also delete a variable by
tying its name into the Name field and click Delete.
Rename—Renames the highlighted variable.
Variable Parameters group
Tick Offset—Specifies a time offset in ticks for the
cur rent variable. When the script is evaluated, the
variable’s value is set from the current time plus
the Tick Offset value.