Титульная страница
ISO 9000 ISO 14000
GMP Consulting
 
Mastering 3D Studio MAX R3

Previous Table of Contents Next


When Start is pressed, the script reads the position of the object at times that will depend on the interval specified by the user. After reading all these values, the script will assign a Bezier controller to the position and assign all these values to the corresponding times.

If the user chooses to reduce the keys, they will be able to specify the threshold. When the user presses Apply Reduction, the keyframe reduction will be calculated.

Try this script on an object with a noise controller assigned to the Position, and notice the results.


NOTE You will find another script called collapse_PRS.ms on the CD that accompanies this book. This script will do the same thing as collapse_position.ms, but will allow the user to pick the Position, Rotation, or Scale controllers.

Hands-on MAX: Expression Controller

Expressions aren’t scripts, but they are very useful and sometimes easier to use than scripts. Expression controllers allow the user to assign math formulas to any parameter. These math formulas can depend on any other object’s parameters; for instance, you can change an object’s color depending on another object’s position. We’ll illustrate both expression controllers and script controllers so you can see the advantages of each.

You can assign an expression controller to any parameter in MAX. To do so, select the parameter in the Motion tab or in the Track View and assign a float, position, scale, or point3 expression to it.

Right-click the Track View and select Properties as in Figure 16.3. This will open the Expression Controller dialog box (Figure 16.4). It’s a modeless dialog, which means you can manipulate objects and properties in the scene while still accessing this dialog. You cannot close the Track View.


FIGURE 16.3  Defining the position expression


FIGURE 16.4  Expression controller dialog box

To define an expression, you need to know how you want the object to behave. For instance, let’s create an expression using a previously modeled example. Open the file wheel_expression.max from the CD. It contains a box and a cylinder, which is attached to the box. What you want is to have the wheel rotating according to the box movement. Let’s do an expression for it:

1.  Open the Track View and locate the Wheel’s Rotation track.
2.  Change the rotation controller to Euler XYZ.
3.  Expand the Rotation and select Y Rotation.
4.  Assign a Float Expression to the rotation.
5.  Right-click the Track View and select Properties.
6.  Type Car in the Name field, select Vector, and click Create. This creates a variable that will be defined by the car’s position. The wheel rotation will be based in this variable.
7.  Select Car from the Vectors list and click Assign to Controller.
8.  In the Track View, select Car Ø Transform Ø Position.
9.  Create a new Scalar variable named Radius.
10.  Select it and click Assign to Controller.
11.  Try to select Wheel Ø ModifiedObject Ø Object Ø Radius.

You will not be allowed select this property, because it needs to have a Bezier float controller assigned to it:

12.  Close the Expression dialog box.
13.  Assign a Bezier float controller to the Radius of the cylinder.
14.  Reopen the Expression dialog box and repeat steps 10 and 11.
15.  Now type the expression Car.x/Radius.

Car.x is the X position of the Car. Radius is the radius of the wheel. This expression will return the number of radians of the curve length, which will rotate the object accordingly. If it rotates in the wrong direction, just add a minus sign (-) to the expression. You can see the whole expression in Figure 16.5.


NOTE Rotations are always calculated in radians in an expression controller.

The file Wheel_expression_ready.max contains the finished expression and a small animation example. There’s another example, Bullet_expression.max, which shows an example of ballistics movement applied as an expression.


FIGURE 16.5  Car wheel expression

Script Controller

A script controller works the same way as an expression controller, with a small difference: it’s a script. There’s no need to learn new techniques or formulas—just write it as a regular script. Script controllers are very useful because you can access and modify any property in any object, not only in the local object. You can even call functions and read and write files from script controllers.

Creating Script Controllers

To create a script controller, use the same process as for an expression controller. Simply select any object track and assign a position, rotation, scale, float, or point3 script controller. Right-click the Track View and select Properties; this will display the Script Controller dialog box (Figure 16.6).

The script controller must return a result to the script, which is different from the scripts you’ve written, because so far you have always used variables to store values.

Let’s repeat the expression controller example, this time using a script. Open the file wheel_script.max from your CD and follow these steps:

1.  Locate the Rotation track of the wheel and assign an Euler XYZ controller to it.
2.  Locate the Y Rotation track and assign a float script controller to it.
3.  From the Track View shortcut menu, select Properties. In the Script area, type: $Car.pos.x/$Wheel.radius.
4.  Animate the car moving from left to right and notice the wheel animation.


FIGURE 16.6  Script Controller dialog window


NOTE The script controller does not update automatically in the screen when you change a parameter. Objects update when you move the Time Slider or when you change the current frame.

The file Wheel_script_ready.max contains the finished expression and a small animation example.


TIP To easily update the objects from the script controller, move to the next frame and move back to the current frame.


Previous Table of Contents Next

© 2000, Frol (selection, edition, publication)

 
Rambler's Top100