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

Previous Table of Contents Next


You can also delete all key information in an interval, using DELETETIME. Besides #incleft and #incright, you can use #noslide, which will delete the keys but maintain the remaining keys in their position. If #noslide is not specified, all remaining keys to the right of the deleted interval will be slid to the left, filling the gap.

Let’s create a Macro Script that will reverse the time of all objects in the scene. This will allow us to render the animation directly, without needing to use the Video Post or any editing software to reverse it. Open the reverse_keys.ms file from the CD, or start a new script and type all the commands in LISTING 16.1.


LISTING 16.1:The Reverse Keys script (reverse_keys.ms)
 macroscript Reverse_Time category:”Tools” tooltip:”Reverse Time”
 (
 objtracks = objects as array
 count = 1
 while count <= objtracks.count do
 (
 n = objtracks[count].numsubs
 for i in 1 to n do append objtracks objtracks[count][i]
 count += 1
 )
 revtracks = #()
 for i in 1 to objtracks.count do
 (
 if objtracks[i].controller != undefined and objtracks[i].numsubs == 0 \
 and objtracks[i].isanimated then append revtracks objtracks[i]
 )
 for i in 1 to revtracks.count do
 (
 reversetime revtracks[i] animationrange #incleft #incright
 )
 )


(Once again we point out: the backslash at the end of a printed line means that statement continues on the next line.) This script creates an array of all objects and appends all subanims to it. Then it creates another array, using only the tracks that have a controller assigned, are animated, and have no subanims. This array will contain all the controllers that will be reversed; the reversal happens in the last loop.


NOTE This script may not work correctly with expression controllers, script controllers, TCB rotations, and reactors, because of the way their keyframes and parameters are stored.

Reducing Keys

You can also reduce keys using MAXScript. This is done using REDUCEKEYS, which reduces the keys in a given controller, based on a specified threshold. It can reduce keys in the active animation range or in a specified interval. For instance, to reduce the keys in the previous sphere example, you would use reducekeys s.scale.controller 3 1, where 3 is the threshold of the reduction and 1 is the frame step that will be used to sample the reduction.

Hands-on MAXScript: A Collapse Position Floater

Let’s create a script that collapses all position controllers, substituting for them with a Bezier controller, and reducing keys through a specified threshold (the interface for this script is illustrated in Figure 16.2).


FIGURE 16.2  The Collapse Position floater

Open the collapse_position.ms script from the CD-ROM that accompanies this book, or start a new script and type all the commands in LISTING 16.2.


LISTING 16.2:The Collapse Position script (collapse_position.ms)
 rollout collapsePRS_rollout “Parameters”
 (
 pickbutton sel “Select Object” width:120
 spinner sample “Interval (frames): “ enabled:false range:[0,10,1]
 checkbox reduce “Reduce Keys” enabled:false
 spinner threshold “Threshold: “ enabled:false range:[0,10000,3]
 button apply “Apply Reduction” width:120 enabled:false
 button go “Start” width:160 enabled:false
 on sel picked obj do
 (
 sel.text = obj.name
 s_obj = obj
 p = s_obj.position.isanimated
 apply.enabled = false
 if p then go.enabled = reduce.enabled = sample.enabled = true
 )
 on reduce changed state do
 (
 threshold.enabled = state
 if go.enabled == false then apply.enabled = state
 )
 on go pressed do
 (
 values = #()
 num_steps = (animationrange.end - animationrange.start) / sample.value
 num_steps = (num_steps as integer)/160
 for i in 1 to num_steps do
 (
 f = (i*sample.value) as time
 at time f append values s_obj.position.controller.value
 )
 s_obj.position.controller = bezier_position()
 for i in 1 to num_steps do
 (
 f = (i*sample.value) as time
 animate on
 (
 at time f s_obj.position = values[i]
 )
 )
 if reduce.checked == true then apply.enabled = true
 go.enabled = false
 )
 on apply pressed do
 (
 reducekeys s_obj.position.controller threshold.value \
 (sample.value as time)
 )
 )
 try (closerolloutfloater collapsePRS_floater) catch()
 collapsePRS_floater = newrolloutfloater “Collapse Position” 210 210
 addrollout collapsePRS_rollout collapsePRS_floater


Once you evaluate this script, a floater appears, with a pickbutton to select an object. As soon as the user selects the object, the script will test to see if this object has position animation. If it does, all UIs will be enabled, and the user will be able to start the script.


Previous Table of Contents Next

© 2000, Frol (selection, edition, publication)

 
Rambler's Top100