Expression Controller

The Expression controller lets you use mathematical expressions to control these animation aspects: object parameters such as length, width, and height; and transform and modifier values such as an object's position coordinates.

Interface Procedures

You can constrain values by basing them on the controller values of other objects in the scene.

An expression is a mathematical function that returns a value. 3ds Max evaluates the expression once for each frame of an animation, generating values that can change from frame to frame.

You can assign expressions to the following kinds of scene elements:

Scene element Controller
Creation parameters Any numeric creation parameter
Transforms Position [X, Y, Z]

X Rotation

Y Rotation

Z Rotation

Scale [X%, Y%, Z%]

Modifiers Any numeric modifier parameter (including creation parameters)
Materials Colors [R, G, B]

Any numeric material parameter

Note: Expression controllers work only with the individual XYZ components of Euler rotation. You can't assign an expression to TCB Rotation or other kinds of rotation controllers.

Procedures

To assign a constant value to a variable:

  1. Highlight the variable name in the Scalars or Vectors list.
  2. Click Assign To Constant.

    3ds Max opens a new dialog.

  3. On the dialog, enter the new value (or, in the case of a vector, values) for the constant, and then click OK.

To assign a controller to a variable:

  1. Highlight the variable name in the Scalars or Vectors list.
  2. Click Assign To Controller.

    3ds Max opens the Track View Pick subdialog, showing the track hierarchy. The dialog display is similar to the Track View hierarchy.

  3. Highlight the track for the variable to use, and then click OK.

Example: To create an expression that moves a sphere in a precise circle:

  1. Create a sphere with Radius=15.0.

    You'll use Track View to create the Expression controller.

  2. In the active viewport, right-click the sphere and click Curve Editor.
  3. In the Hierarchy list, scroll down to the Objects branch and, if necessary, expand the Sphere01 branch so the sphere's Position track is visible. Click the Position label to highlight it.
  4. In the Hierarchy list, right-click the Position label and then click Assign Controller.

    3ds Max opens the Assign Controller dialog.

  5. Choose Position Expression from the list of controller types, then click OK.

    3ds Max opens the Expression Controller dialog.

  6. Replace the default expression by typing the following position expression in the Expression field:

    [100*cos(360*NT), 100*sin(360*NT), 0]

    The expression specifies a circular path for the sphere. NT is a variable that means "normalized time." Movement based on NT happens exactly once per the active time segment, regardless of how many frames are in the animation.

  7. Click Evaluate.
  8. Play the animation. The sphere moves in a circle about the world origin (0,0,0). The radius of the circular path is 100 units.

Example continued: To change the radius of the circle:

    The two 100s in the position expression from the previous procedure specify the radius. To adjust the radius of the circle's path, create a symbolic variable to represent the radius. The variable has a constant value that is easy to edit.

  1. Reopen Track View and the Expression Controller dialog if necessary.
  2. In the Name field of the Expression Controller dialog, type radius Make sure Scalar is chosen, and then click Create.

    The variable name "radius" appears in the Scalars list of the dialog.

  3. Click Assign To Constant.

    3ds Max opens a dialog titled "radius".

  4. Enter 150 in the Value field, and then click OK.

    The radius variable is now 150.

    Next you'll use the new variable in the expression.

Example continued: To replace the literal value with the variable name:

  1. In the Expression field, change 100 to radius in both places. The expression should now look like this:

    [ radius*cos(360*NT), radius*sin(360*NT), 0]

  2. Click Evaluate.
  3. Play the animation. The sphere moves in a circle about the world origin (0,0,0). The radius of the circular path is 150 units.

Example continued: To make the sphere rotate about a box:

  1. Create a box about 40 units square, and animate its position over three or four keyframes.
  2. Select the sphere.
  3. In the Name field of the Expression Controller dialog, enter boxposn. Choose Vector, and then click Create.

    The name "boxposn" is displayed in the Vectors list in the lower-left area of the dialog.

    Variable names are case sensitive; the variable name should be lower case.

  4. Click Assign to Controller.

    The Track View Pick dialog is displayed. It shows the object hierarchy as it appears in the left side of Track View-Dope Sheet.

  5. In the Hierarchy list, highlight the Position controller for Box01 and then click OK.
  6. In the Expression field, add boxposn as an offset:

    [radius * cos(360*NT), radius * sin(360*NT), 0]+boxposn.

  7. Click Evaluate, and then click Close.

    Play the animation again. The sphere moves in a circle around the box and follows the box wherever it moves.

Interface

Tip: You can resize the dialog by dragging an edge or a corner.

Create Variables group

Name
The variable name.
Scalar/Vector
Choose the type of variable to create.
Create
Creates the variable and adds it to the appropriate list.

You must enter a name and specify a type before clicking Create.

Delete
Deletes the highlighted variable in the Scalars or Vectors list.
Rename
Renames the highlighted variable in the Scalars or Vectors list.

First highlight the variable in the list; this places the name in the Name field. Edit the name in the Name field, and then click Rename; the new name replaces the previous one in the list.

Variable Parameters group

Tick Offset
Contains an offset value. A tick is 1/4800 of a second. If a variable has a non-zero tick offset, that value is added to the current time.
Scalars list
Lists the scalar variables you've created. The following pre-defined constant variables are available in every expression controller and cannot be deleted or renamed:
  • F the current time in frames
  • NT the normalized time
  • S the current time in seconds
  • T the current time in ticks
Vectors list
Lists the vector variables you've created.
Assign to Constant
Opens a dialog that lets you assign a constant to the highlighted variable.

Constant assignment for a scalar variable

Constant assignment for a vector variable

Assign to Controller
Opens a Track View Pick dialog that lets you assign a controller to the highlighted variable. The controller's value is taken at the current time plus the variable's Tick Offset.
Expression window
Enter the expression to evaluate. The expression must be a valid mathematical expression. The result is either a three-value vector for a vector expression (position, scale, or point3) or a scalar value for a float expression.
Description window
Enter optional text do document the expression. For example, you can describe user-defined variables.
Function List
Displays a list of Expression controller functions.

In the list, p, q, and r represent scalar values or scalar expressions; V and W represent vector values or vector expressions.

Save
Saves an expression. Expressions are saved as files with a ..xpr file name extension.
Load
Loads an expression.

A saved expression does not include variable definitions or values. After loading the expression, you need to redefine them.

Debug
Displays the Expression Debug window.

This window shows the values of all variables, and the value of the expression. When you change the variables or move the time slider, the Debug window automatically updates so you can interactively view what's happening with the expression. The values for frames (F), normalized time (NT), secs (S), and ticks (T) are also displayed.

Evaluate
Evaluate the expression for each frame in the animation.

There is no explicit assignment (= or := operator) as in a conventional programming language; the assignment is implicit and takes place over time.

If the expression has a syntax error, an error message is displayed. The error message is the first part of the expression itself. The last character in the error message is the point of the error. This is usually where the error actually is, unless the problem is that opening and closing parentheses (or the braces for vectors) don't match. In this case, evaluation can proceed further before the error is detected.

Close
Closes the Expression Controller dialog.