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, we use a balloon model created by Zygote Media to demonstrate 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 image from book Balloon and pump.max file from the Chap 32 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 image from book Track View-Curve Editor. Navigate the balloon object's tracks until you find the Push Value track (found under Objects image from book b3 image from book Modified Object image from book Push image from book Push Value). Select the Push Value track, and click the Assign Controller button (or select it from the right-click popup menu). From the list of controllers, select Float Expression and click OK.

    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 32.41 shows the balloon as it is being inflated.

image from book
Figure 32.41: A balloon being inflated using an Expression controller to control the Push modifier

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.

Tutorial: Controlling a stoplight

In this example, we use the if function to turn the colors of a sphere on and off to simulate a traffic light. We accomplish this task by applying the Expression controller to the Diffuse color track. The goal is to show the color green for the first third of the animation, yellow for the second third, and red for the last third.

To change the colors of stoplight spheres using the Expression controller, follow these steps:

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

    This file includes a simple stoplight created using primitives. One of the spheres moves between the three light positions and has had a green material applied to it.

  2. Open the Track View-Curve Editor, and locate and select the Diffuse Color track, which you can find under Objects image from book Sphere03 image from book Material #1 image from book Shader Basic Parameters tracks. Click the Assign Controller button, and double-click the Point3 Expression selection.

    This assigns the Point3 Expression controller to the Diffuse Color track.

  3. Open the Expression Controller dialog box by right-clicking the Diffuse Color track and selecting Properties from the pop-up menu.

  4. In the Expression pane, enter the following:

          [if(NT>=.33,255,0), if(NT<.66,255,0), 0] 

    Then click the Evaluate button, and close the Expression Controller dialog box.

Click the Play Animation button to see the results. Figure 32.42 shows the stoplight alongside the Dope Sheet for this stoplight.

image from book
Figure 32.42: The Expression controller animates the diffuse color for this object.

Before leaving this example, let's examine the expression. The expression works with a Point3 number that includes the values of red, green, and blue. The first Point3 value represents red. Because yellow, in the RGB color system, is composed of equal parts of red and green, we want red to be visible for the last two-thirds of the time. To do this, we make the expression include the following statement:

      if (NT >= .33, 255, 0) 

This basically says that if the Normalized Time falls in the last two-thirds of the time, then set the red value to 255; if it does not, then set red to 0.

The second Point3 value is green, which appears for the first third of the animation and along with red for the second third to make yellow. So the following expression needs to go where the green value would be located:

      if (NT < .66, 255, 0) 

This expression says that if the Normalized Time is less than two-thirds of the time, then set the green value to its maximum; if it isn't, then set its value to 0.

The third Point3 value is for blue. Blue doesn't appear at all in green, yellow, or red, so its value is set to 0 for the entire animation.

The completed expression for the entire animation (which you entered in Step 4 of the tutorial) looks like this:

      [if (NT >= .33, 255, 0), if (NT < .66, 255, 0), 0] 




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