Chapter 33. Animating with the Expression Controller and Wiring Parameters

Expressions are looks that you make in the mirror when you're trying to wake up, but in Max they are a series of equations that define how an object acts. Max expressions can be as simple as adding two numbers together or as complex as several lines of MAXScript. But expressions enable you to create customized animated reactions.

Although Max expressions can be used with any Max spinner, they are mainly used within MAXScript scripts or in the Expression controller. The Expression controller is a specialized controller that lets you control the object's behavior using scripted expressions.

This chapter then looks at a unique way to drive animations based on object parameters. Parameters of one object can be wired to parameters of another object so that when one parameter changes, the wired parameter changes with it. For example, you can wire the On/Off parameter of a light to the movement of a switch. All parameters that can be animated can be wired.

As long as you are working with parameters, Max includes several helpful tools for viewing and working with the available parameters including the Parameter Collector. If the Parameter Collector doesn't gather the exact parameters that you need, you can create your own custom parameters also.

Working with Expressions in Spinners

Although much of this chapter focuses on using the Expression controller, the Expression Controller Interface isn't the only place where you can play with expressions. Expressions can also be entered into spinner controls using the Numerical Expression Evaluator, shown in Figure 33.1. This simple dialog box is accessed by selecting a spinner and pressing Ctrl+N.

Note

Another place that commonly uses expressions is the Parameter Wiring dialog box, which is covered later in this chapter.

The Numerical Expression Evaluator dialog box lets you enter expressions for a spinner.

Figure 33.1. The Numerical Expression Evaluator dialog box lets you enter expressions for a spinner.

To use this evaluator, just type the expression in the field; the result is displayed in the result field. The result field is updated as you type the expression. If you make a mistake, the Result is blanked out. The Paste button places the result value in the spinner, and the Cancel button closes the dialog box without a change.

Tip

You can enter a relative value in a spinner by typing the letter R and a value. For example, if the Segments value of a sphere object is 32, then typing R20 changes the value to 52 and R-20 changes the value to 12.

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.

Note

Although it is not as powerful as the Script controller, the Expression controller is much faster than the Script controller because it doesn't require any compile time.

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 to the Position, Rotation, and Scale tracks using the Motion panel or the Track View or you can apply a controller by right-clicking on a track in the Track View and selecting the Assign Controller option. 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 33.2, includes four separate panes used to display a list of Scalar and Vector variables, build an expression, and enter a description of the expression.

You can use the Expression controller to build expressions and define their results.

Figure 33.2. 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 33.3, where you can select the specific controller track for the variable, such as the position of an object.

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.

The Track View Pick dialog box displays all the tracks for the scene. Tracks that you can select are displayed in black.

Figure 33.3. The Track View Pick dialog box displays all the tracks for the scene. Tracks that you can select are displayed in black.

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 33.4, 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.

The Function List dialog box lets you view all the available functions that you can use in an expression.

Figure 33.4. The Function List dialog box lets you view all the available functions that you can use in an expression.

Tip

One way to learn the syntax for different expressions is to enable the MacroRecorder in the MAXScript Listener window and look in the upper pane while performing a task in the viewports.

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 33.5. 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.

The Expression Debug window offers a way to test the expression before applying it.

Figure 33.5. 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.

Warning

If you load a saved expression into the Expression Controller dialog box, you need to reassign all variables before you can use the loaded expression.

Tutorial: Creating following eyes

As a quick example, you'll 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 you show it with the Float Expression controller.

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

  1. Open the Following eyes.max file from the Chap 33 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 33.6, and click OK.

    Select the Position track for the Sphere01 object in the Track View Pick dialog box.

    Figure 33.6. 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 33.7 shows the resulting face.

The Expression controller was used to animate the eyes following the ball in this example.

Figure 33.7. The Expression controller was used to animate the eyes following the ball in this example.

Using Expression Controllers

You can use expressions to control the transforms of objects. You can access these transforms from the Track View or from the Motion panel. You can also use expressions to control object parameters such as a box's length or material properties such as the amount of illumination applied to a material. You can access all these parameters from the Track View.

Animating transforms with the Expression controller

After you assign a controller to a transform track, the Expression pane in the Expression Controller dialog box includes the current values of the selected object. Position transforms display the X, Y, and Z coordinates of the object; Rotation transforms display the rotation value in radians; and Scale transforms display values describing the relative scaling values for each axis.

Note

Radians are another way to measure angles. A full revolution equals 360 degrees, which equates to 2 × pi radians. The Expression dialog box includes the degToRad and radToDeg functions to convert back and forth between these two measurement systems.

Animating parameters with the Float Expression controller

To assign the Float Expression controller, select an object with a parameter or Modifier applied and open the Track View. Find the track for the parameter that you want to change, and click the Assign Controller button. Select the Float Controller from the list, and click OK.

Note

The actual controller type depends on the parameter selected. Many parameters use float expressions, but some use Transform controllers.

After you assign the Expression controller, the Expression Controller dialog box opens, or you can open it by right-clicking the track and selecting Properties from the pop-up menu to load the dialog box. Within this dialog box, the Expression pane includes the current value of the selected parameter.

Tutorial: Inflating a balloon

The Push Modifier mimics filling a balloon with air by pushing all its vertices outward. In this tutorial, you'll use a balloon model created by Zygote Media to see how you can use the Float Expression controller to control the parameters of a modifier.

To inflate a balloon using the Float Expression controller, follow these steps:

  1. Open the Balloon and pump.max file from the Chap 33 directory on the DVD.

    This file includes a pump created from primitives and the balloon model with the Push modifier applied.

  2. Next, open the Track View by choosing Graph Editors

    Tutorial: Inflating a balloon

    The Expression Controller dialog box opens.

  3. In the Expression pane, you should see a single scalar value of 0. Modify the expression to read like this:

    2 * NT

    Click the Debug button to see the value results. With the Expression Debug window open, drag the Time Slider and notice that the balloon inflates.

Note

If you use a parameter such as Radius as part of an Expression, then the parameter is unavailable in the Modify panel if you try to change it by hand.

Figure 33.8 shows the balloon as it is being inflated.

Animating materials with the Expression controller

You can locate the material's parameter in the Track View and assign the Expression controller to it to control material parameters. Some of these parameters are scalar values, but any material parameter set with a color swatch has a Point3 return type.

When using material parameters and color values, be sure not to combine them in expressions with vector values.

A balloon being inflated using an Expression controller to control the Push modifier

Figure 33.8. A balloon being inflated using an Expression controller to control the Push modifier

Wiring Parameters

When parameters are wired together, the value of one parameter controls the value of the parameter to which it is wired. This is a powerful animation technique that lets a change in one part of the scene control another aspect of the scene. Another way to use wired parameters is to create custom animation controls such as a slider that dims a light source that animators can use as needed.

Using the Parameter Wiring dialog box

You can access the Parameter Wiring dialog box in several places. The Animation

Using the Parameter Wiring dialog box

You can also wire parameters by right-clicking the quadmenu and selecting Wire Parameters. The Wire Parameters option is disabled if multiple objects are selected.

The Parameter Wiring dialog box (Alt+5), shown in Figure 33.9, displays two tree lists containing all the available parameters. This tree list looks very similar to the Track View and lets you connect parameters in either direction or to each other. If you used the Wire Parameters feature to open the Parameter Wiring dialog box, then the parameter for each object is already selected and highlighted in yellow.

The Parameter Wiring dialog box can work with expressions.

Figure 33.9. The Parameter Wiring dialog box can work with expressions.

The three arrow buttons between the two tree lists let you specify the connection direction. These buttons connect the parameter in one pane to the selected parameter in the opposite pane. The direction determines whether the parameter in the left pane controls the parameter in the right pane, or vice versa. You can also select the top bidirectional button to make the parameters mutually affect each other. Below each tree list is a text area where you can enter an expression. An expression is a mathematical statement that follows a specific syntax for defining how one parameter controls the other. These expressions can be any valid expression that is accepted in the Animation Controller dialog box or in MAXScript.

Note

You can learn more about creating and using expressions in Chapter 21, "Animating with Constraints and Controllers."

After an expression is entered, click the Connect button to complete the wiring. Based on the connection direction, the Master radio button indicates which object controls the other. You can also use this dialog box to disconnect existing wired parameters. You can use the icon buttons at the top of the dialog box, shown in Table 33.1, to Show All Tracks, to find the next wired parameter, and to refresh the tree view.

Table 33.1. Parameter Wiring Dialog Box Icons

Button

Description

Parameter Wiring Dialog Box Icons

Show All Tracks

Parameter Wiring Dialog Box Icons

Next Wired Parameter

Parameter Wiring Dialog Box Icons

Refresh Tree View

After the wiring is completed, the Parameter Wiring dialog box remains open. You can try out the wiring by moving the master object. If the results aren't what you wanted, you can edit the expression and click the Update button (the Connect button changes to an Update button).

Note

When you select objects to be wired, the order in which the objects are selected doesn't matter because in the Parameter Wiring dialog box, you can select the direction of control.

Once you've made a connection in the Parameter Wiring dialog box, the track name for the controlling object turns green and the track name of the object being controlled turns red. If you make a bi-directional connection, then both tracks turn green.

Manipulator helpers

To create general-use controls that can be wired to control various properties, Max includes three manipulator helpers. These helpers are Cone Angle, Plane Angle, and Slider. They are available as a subcategory under the Helpers category of the Create panel or in the Create

Manipulator helpers

For the Cone Angle helper, you can set the Angle, Distance, and Aspect settings. The default cone is a circle, but you can make it a square. The Plane Angle helper includes settings for Angle, Distance, and Size.

You can name the Slider helper. This name appears in the viewports above the slider object. You can also set a default value along with maximum and minimum values. To position the object, you can set the X Position, Y Position, and Width settings. You can also set a snap value for the slider.

Once created, you can use these manipulator helpers when the Select and Manipulate button on the main toolbar is enabled (this button must be disabled before the manipulator helpers can be created). The advantage of these helpers is in wiring parameters to be controlled using the helpers.

Tutorial: Controlling a crocodile's bite

One way to use manipulator helpers and wired parameters is to control within limits certain parameters that can be animated. This gives your animation team controls they can use to quickly build animation sequences. In this example, you use a slider to control a crocodile's jaw movement.

To create a slider to control a crocodile's bite, follow these steps:

  1. Open the Biting crocodile.max file from the Chap 33 directory on the DVD.

    This file includes a crocodile model created by Viewpoint Datalabs. For this model, the head, eyes, and upper teeth have been joined into a single object, and the pivot point for this object has been moved to where the jaw hinges.

  2. Select Create

    Tutorial: Controlling a crocodile's bite
  3. With the Slider selected, choose Animation

    Tutorial: Controlling a crocodile's bite

    The Parameter Wiring dialog box appears.

  4. In the Parameter Wiring dialog box, click the direction arrow that points from the Slider to the head so that the slider is set to control the head. Then click the Connect button and drag the Slider.

    Note

    Before you can drag the slider, you need to enable the Select and Manipulate button in the main toolbar.

    The crocodile's jaw spins around erratically. This happens because the rotation values are in radians and you need them in degrees.

  5. In the expression text area under the head object, enter the expression degToRad(value) and click the Update button. The drag the Slider again.

    Now the values are in degrees and the range is correct, but the croc's upper jaw rotates unrealistically through the bottom jaw. This can be fixed by multiplying by a negative 1.

  6. In the expression text area under the head object, update the expression to be −1*degToRad(value) and click the Update button.

  7. Click the Select and Manipulate button on the main toolbar, and drag the slider to the right.

    The crocodile's mouth opens.

Figure 33.10 shows the crocodile biting using the slider control.

A slider control is wired to open the crocodile's mouth.

Figure 33.10. A slider control is wired to open the crocodile's mouth.

Collecting Parameters

To help in organizing the various parameters that you use to animate a scene, you can use the Parameter Collector to gather all custom and animated parameters used in the scene. The Parameter Editor can be used to create custom attributes and parameters, but the custom attributes are attached to the specific object or element that was selected when the attribute was created. This can make finding the custom attributes difficult, but Max includes another tool that you can use to collect all these custom attributes into a single location—the Parameter Collector.

Open the Parameter Collector dialog box, shown in Figure 33.11, with the Animation

Collecting Parameters
The Parameter Collector dialog box is used to gather several different parameters into a custom rollout.

Figure 33.11. The Parameter Collector dialog box is used to gather several different parameters into a custom rollout.

Table 33.2. Parameter Collector Toolbar Buttons

Toolbar Button

Name

Description

Parameter Collector Toolbar Buttons

Collection Name

Enters a name for the current collection or selects an existing collection.

Parameter Collector Toolbar Buttons

New Collection

Creates a new collection of parameters.

Parameter Collector Toolbar Buttons

Duplicate Collection

Creates a copy of the existing collection.

Parameter Collector Toolbar Buttons

Delete Collection

Deletes the current collection.

Parameter Collector Toolbar Buttons

Multiple Edits

Toggle button that allows multiple parameters to be changed at once when enabled.

Parameter Collector Toolbar Buttons

Absolute/Relative

Toggle button that maintains the current value in Absolute mode and resets the value to 0 when the mouse is released in Relative mode.

Parameter Collector Toolbar Buttons

Key Selected

Creates a key for the selected parameters when the Auto Key mode is enabled.

Parameter Collector Toolbar Buttons

Reset Selected

Sets the selected parameter values to 0.

Parameter Collector Toolbar Buttons

Move Parameters Down

Moves the selected parameters downward in the rollout order.

Parameter Collector Toolbar Buttons

Move Parameters Up

Moves the selected parameters upward in the rollout order.

Parameter Collector Toolbar Buttons

Add to Selected Rollout

Opens a Track View Pick dialog box where you can select the parameter to add to the selected rollout.

Parameter Collector Toolbar Buttons

Add to New Rollout

Opens a Track View Pick dialog box where you can select the parameter to add to a new rollout.

Parameter Collector Toolbar Buttons

Delete Selected

Deletes the selected parameters.

Parameter Collector Toolbar Buttons

Delete All

Deletes all parameters in the current collection.

Parameter Collector Toolbar Buttons

Properties

Opens the Key Info dialog box for the selected parameter if a key is set. This button is found to the right of a parameter.

Within the Parameter Collection dialog box, you can create and name new rollouts, add parameters to these rollouts using a Track View Pick dialog box, and save multiple rollouts into collections that can be recalled.

Collections are named by typing a new name in the drop-down list located in the upper-left corner of the interface. This drop-down list holds all available collections. The Collection menu (or the toolbar buttons) may be used to create, rename, duplicate, or delete a collection.

A Parameter Collection can include multiple rollouts. The current active rollout is marked with a yellow bar directly under the rollout title and with brackets that surround the rollout name. Using the Rollout menu (or the toolbar buttons) you can create a new rollout or rename, reorder, or delete existing rollouts.

Parameters are added to the rollouts using the Parameters

Parameter Collector Toolbar Buttons

If multiple parameters are selected, then you can change the values for all selected parameters at the same time by enabling the Edit

Parameter Collector Toolbar Buttons

Warning

Multiple parameters' values can be changed together only if they are of the same type.

At the bottom of the Edit menu is the Edit Notes menu command. Using this menu command, you can change the parameter's name, link it to a URL, and type some notes about how this parameter works.

The Parameter Collector dialog box can also be used to create animation keys. To create a key for the selected parameters, you'll need to enable the Auto Key button and then select the Parameters

Parameter Collector Toolbar Buttons

Using the Collection

Parameter Collector Toolbar Buttons

Adding Custom Parameters

Another useful way to expand the number of parameters is to create custom parameters. These custom parameters can define some aspect of the scene that makes sense to you. For example, if you create a model of a bicycle, you can define a custom parameter for the pedal rotation. You can add your own custom parameters using the Parameter Editor dialog box, shown in Figure 33.12. You can open this modeless panel by choosing Animation

Adding Custom Parameters
You can use the Parameter Editor dialog box to create custom parameters.

Figure 33.12. You can use the Parameter Editor dialog box to create custom parameters.

The Add to Type drop-down list at the top of the Attribute rollout in the Parameter Editor dialog box lets you select where the custom attribute shows up. Custom attributes can be created for an object, for the selected modifier, for the object's material, or for any track found in the Track View. The Pick Explicit Track button opens a dialog box where you can select a specific track.

The Add button creates the custom attribute and adds it to a rollout named Custom Attributes for the specified element. If the specified element is selected, you can click the Edit/Delete button to open the Edit Attributes/Parameters dialog box, shown in Figure 33.13. All custom attributes associated with the selected element are displayed.

Note

Custom attributes show up in a rollout named Custom Attributes positioned beneath all the other rollouts, but if you add the Attribute Holder modifier to the object before creating the new attribute, then the Custom Attributes rollout appears under the Attribute Holder modifier.

The Edit Attributes/Parameters dialog box lets you edit or delete custom attributes.

Figure 33.13. The Edit Attributes/Parameters dialog box lets you edit or delete custom attributes.

The Edit Attributes/Parameters dialog lets you select and reorder the custom attributes within their rollout. Selecting a custom attribute also loads its settings into the Parameter Editor where they can be changed.

The Parameter Type drop-down list lets you choose the parameter format. Possibilities include Angle, Array, Boolean (true or false), Color, Float (a decimal-point number), fRGBA, Integer, Material, Node, Percent, String, TextureMap, and WorldUnits. The UI Type drop-down list defines how the parameter is displayed in the rollout. How the parameter looks depends on the type of parameter. Float and integer values can be spinners or sliders, Boolean values can be check boxes or radio buttons, array values are drop-down lists, nodes are pick buttons (allowing you to select an object in the viewports), color and RGB values are color pickers, and texture maps are map buttons. You can also name the parameter.

The Options rollout changes depending on which parameter type was selected. These rollouts contain settings for the interface's Width, value ranges, default values, Alignment (left, right, or center), and list items.

The Testing Attribute rollout shows what the interface element will look like and lets you change the attribute to see how the custom parameter works.

The value of custom attributes becomes apparent when you start wiring parameters.

Summary

This chapter covered the basics of using the Expression controller. Using mathematical formulas to control the animation of an object's transformation and parameters offers lots of power. You also can use the values of one object to control another object.

Along with the Expression controller, the ability to wire parameters together in the Parameter Wire dialog box opens up a whole new way to control objects. This chapter also covered how you can create new parameters with the Parameter Collector dialog box. All of these tools give you lots of control over the scene using parameters and expressions. In this chapter, you accomplished the following:

  • Practiced building expressions in the Expression Controller dialog box

  • Learned about expressions and what they can do

  • Reviewed the available operators, variables, and functions

  • Tried out examples of controlling object transformations and parameters

  • Created and wired parameters

  • Gathered and edited several parameters at once with the Parameter Collector

  • Created custom parameters with the Parameter Editor

In the next chapter, you learn to use the Track View to display and manage all the details of the current scene.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.3.72