Understanding the Expression Controller Interface


The term expression refers to a mathematical expression or simple formula that computes a value based on other values. These expressions can be simple, as with moving a bicycle based on the rotation of the pedals, or they can be complex, as with computing the sinusoidal translation of a boat on the sea as a function of the waves beneath it.

You can use almost any value as a variable in an expression, from object coordinates and modifier parameters to light and material settings. The results of the expression are computed for every frame and used to affect various parameters in the scene. You can include the number of frames and time variables in the expression to cause the animation results to repeat for the entire sequence.

Of all the controllers that are available, the Expression controller has limitless possibilities that could fill an entire book. This section covers the basics of building expressions and includes several examples.

The Expression controller is just one of the many controllers that are available for automating animations. This controller enables you to define how the object is transformed by means of a mathematical formula or expression, which you can apply to any of the object's tracks. It shows up in the controller list, based on the type of track to which it is assigned, as a Position Expression, Rotation Expression, Scale Expression, Float Expression, or Point3 Expression controller.

Before you can use the Expression controller on a track, you must assign it to a track. You can assign controllers using the Motion panel or the Track View. After you assign a controller, the Expression Controller dialog box immediately opens, or you can access this dialog box at any time by right-clicking the track and selecting Properties from the pop-up menu. For example, select an object in your scene, open the Motion panel, and select the Position track. Then click the Assign Controller button at the top of the Assign Controller rollout, and select Position Expression from the list of Controllers. This causes the Expression Controller dialog box to appear.

You can use this dialog box to define variables and write expressions. The dialog box, shown in Figure 32.35, includes four separate panes used to display a list of Scalar and Vector variables, build an expression, and enter a description of the expression.

image from book
Figure 32.35: You can use the Expression controller to build expressions and define their results.

Defining variables

Variables are placeholders for different values. For example, creating a variable for a sphere's radius called "r" would simplify an expression for doubling its size from "take the sphere's radius and multiply it by two," to simply "r times 2."

To add Variables to the list panes in the Expression Controller dialog box, type a name in the Name field, select the Scalar or Vector option type, and click the Create button; the new variable appears in the Scalars or Vectors list. To delete a variable, select it from the list and click the Delete button. The Tick Offset value is the time added to the current time and can be used to delay variables.

You can assign any new variable either to a constant or to a controller. Assigning a variable to a constant does the same thing as typing the constant's value in the expression. Constant variables are simply for convenience in writing expressions. The Assign to Controller button opens the Track View Pick dialog box, shown in Figure 32.36, where you can select the specific controller track for the variable, such as the position of an object.

image from book
Figure 32.36: The Track View Pick dialog box displays all the tracks for the scene. Tracks that you can select are displayed in black.

Assigning a variable to a controller enables you to animate the selected object based on other objects in the scene. To do this, create a variable and assign it to an animated track of another object. For example, if you create a Vector variable named boxPos and assign it to the Position track for a box object, then within the expression you can use this variable to base the motion of the assigned object on the box's position.

Building expressions

You can type expressions directly into the Expression pane of the Expression Controller dialog box. To use a named variable from one of the variable lists (Scalars or Vectors), type its name in the Expression pane. Predefined variables (presented later in the chapter) such as F and NT do not need to be defined in the variable panes. The Function List button opens a list of functions, shown in Figure 32.37, where you can view the functions that can be included in the expression. This list is for display only; you still need to type the function in the Expression pane.

image from book
Figure 32.37: The Function List dialog box lets you view all the available functions that you can use in an expression.

Note 

The Expression pane ignores any white space, so you can use line returns and spaces to make the expression easier to see and read.

Debugging and evaluating expressions

After typing an expression in the Expression pane, you can check the values of all variables at any frame by clicking the Debug button. This opens the Expression Debug window, shown in Figure 32.38. This window displays the values for all variables, as well as the return value. The values are automatically updated as you move the Time Slider.

image from book
Figure 32.38: The Expression Debug window offers a way to test the expression before applying it.

The Evaluate button in the Expression Controller dialog box commits the results of the expression to the current frame segment. If the expression contains an error, an alert dialog box warns you of the error. Replacing the controller with a different one can erase the animation resulting from an Expression controller.

Managing expressions

You can use the Save and Load button to save and recall expressions. Saved expressions are saved as files with an .XPR extension. Expression files do not save variable definitions.

Tutorial: Creating following eyes

As a quick example, we start with a simple expression. The Expression controller is very useful for setting the eye pupil objects to move along with the ball's motion. This same functionality can be accomplished using a manipulator and wiring the parameter, but we show it with the Float Expression controller.

To make eye pupil objects follow a moving ball object, follow these steps:

  1. Open the image from book Following eyes.max file from the Chap 32 directory on the DVD.

    This file includes a face taken from a Greek model made by Viewpoint Datalabs, along with a ball that is animated to move back and forth.

  2. Select the left eye pupil object named "pupil_l" (the right pupil has been linked to move with the left pupil), and open the Motion panel. Select the Position track, and click the Assign Controller button. Select the Position Expression controller, and click OK.

    The Expression Controller dialog box opens.

  3. Create a new vector variable named ballPos by typing its name in the Name field, selecting the Vector option, and clicking the Create button.

  4. With the ballPos variable selected, click the Assign to Controller button. In the Track View Pick dialog box, locate and select the Position track for the Sphere01 object, as shown in Figure 32.39, and click OK.

    image from book
    Figure 32.39: Select the Position track for the Sphere01 object in the Track View Pick dialog box.

  5. In the Expression pane, erase the existing expression and type the following:

          [ -3.1 + ballPos.x/20, -2.9, 41.0 ] 

    Then click the Debug button. The Expression Debug window appears, in which you can see the variable values change as items in the scene change. With the expression complete, you can drag the Time Slider back and forth and watch the pupil follow the ball from side to side. If you're happy with the motion, click the Evaluate button and then the Close button to exit the interface.

This is a simple example, but it demonstrates what is possible. Figure 32.40 shows the resulting face.

image from book
Figure 32.40: The Expression controller was used to animate the eyes following the ball in this example.




3ds Max 9 Bible
3ds Max 9 Bible
ISBN: 0470100893
EAN: 2147483647
Year: 2007
Pages: 383

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net