Manipulating Objects in Scene

Maybe the most important MAXScript feature is the ability to manipulate objects in the scene, making it easier to create animations.

In this exercise, you will use a simple eye model, which will be animated using MAXScript.

The eye is a simple sphere, with a multi-sub material applied. The eyelid and the base were modeled with MeshSmooth. Several dummies were created to help the eye animation.

First, you will make a script to adjust the eye's rotation.

  • Start a new script and type:
    utility control "Eye Control"
    (
    )

In this utility, you will use a Slider to control the rotation of the eye, to the left and to the right. You will limit the rotation in 45º to for each side.

  • In the utility, type:
    slider eyeh "Horizontal Movement" range:[-45,45,0]

You will now define the action that will take place when the user moves this slider. Basically, the slider value indicates the Z rotation of the object (eye). To indicate it's the eye object that is being rotated, you will use $eye, where eye is the exact name of the object in the scene.

  • Type:
    on eyeh changed val do $eye.rotation.z_rotation = val

Using Evaluate, execute the script and see how it works. Now you will see the first problem in this script. You cannot move it back to zero. You will solve it creating a reset button.

  • Type, below the slider:
    button reseth "Reset"
    on reseth pressed do
    (
    $eye.rotation.z_rotation = 0
    eyeh.value = 0
    )

You now created an option that will return the eye to the original position.

Repeat all the steps above, specifying the rotation around the X axis, so that the eye will be rotated vertically.

  • Type:
    slider eyev "Vertical Movement" range:[-45,45,0]
    button resetv "Reset"
    on resetv pressed do
    (
    $eye.rotation.x_rotation = 0
    eyev.value = 0
    )
    on eyev changed val do $eye.rotation.x_rotation = val

Pay attention to the X rotation value, cause a 0º rotation will make the eye look upwards, instead of looking ahead. You will then need to add 90º to the rotation, so it's done correctly.

Now, to better organize the script:

slider eyeh "Horizontal Movement" range:[-45,45,0]
button reseth "Reset"
slider eyev "Vertical Movement" range:[-45,45,0]
button resetv "Reset"
on eyeh changed val do $eye.rotation.z_rotation = val
on eyev changed val do $eye.rotation.x_rotation = val + 90
on reseth pressed do
(
$eye.rotation.z_rotation = 0
eyeh.value = 0
)
on resetv pressed do
(
$eye.rotation.x_rotation = 90
eyev.value = 0
)
To create an animation, simply move the slider to the frame you want, turn on Animate, and play with the script.

Execute the Eye03.ms script and notice the eyelid movement options.

Open the file Script_eye2.MAX and execute Eye04.ms, which now controls the movement of each eye independently.

Alexander Esppeschit Bicalho © 1999