Tutorial 8: Working with Crowd Animation
character studio's Crowd animation system has a number of special features designed for applying behaviors to non-biped objects. In this lesson, you'll learn how to create a flock of birds that automatically flap their wings when they fly horizontally and upwards, and glide without flapping when they fly downwards.
You'll animate several delegates and link them with clones of an animated "global" object. Next, you'll use clip controllers to define clips from the global object's animation. You'll define "states" to specify which animation clip the clones should use, depending on their parent delegates' speed, acceleration, pitch, and so on. Crowd will blend the clips and synthesize an animation based on the clip and state information.
Load the file cs_tut08_lesson5.max in the cstudio\tutorials\tutorial_8 directory in your 3DS MAX path.
This file contains the basic setup for the birds scene. It contains a crowd object and a "flock" of five delegates in V formation, as well as a vector field surrounding a C-shaped "obstacle" object.
You'll set up a Space Warp behavior so the delegates fly around within the vector field and an Avoid behavior so they don't collide.
Select the crowd object and in the Modify panel> Setup rollout add a Space Warp behavior.
In the Space Warp Behavior rollout, click the None button and select the vector field object.
The vector field object is the gizmo shaped like two double-headed arrows in an X formation.
Now, any delegates using the Space Warp behavior will use the vector field to guide their motion.
Add an Avoid behavior.
In the Avoid Behavior rollout, click Multiple Selection to the right of the None button.
In the Select dialog, select all of the delegates and click Select.
This sets the delegates to avoid each other.
Open the Behavior Assignments dialog.
The delegates have already been grouped into a team (Team0).
Assign both behaviors to the team and close the dialog.
In the Solve rollout, click the Solve button.
You can stop the simulation at any time by pressing ESC. As Crowd solves the simulation, the delegates move around the obstacle object, roughly following its contours while remaining at their starting height. Some might fly away, which you'll solve with the next step.
To make the birds to fly up and down, you must allow the delegates to move out of the current XY plane.
Modifying the delegates
In the Setup rollout, click Multiple Delegate Editing.
The delegates have already been added to the Delegates to Edit list. You don't need to highlight them.
In the General group, turn off Constrain to XY Plane.
Turn on SET for Constrain to XY Plane.
You can also vary the delegates' speeds.
In the Speed group, to the right of Average Speed, turn on both Random and SET.
Turning on Random gives you access to both Average Speed settings.
Change the first Average Speed setting to 3.0.
Crowd will use random values between 3 and 5 units per frame for the delegates' speeds.
Click the Apply Edit button to close the dialog and apply your changes to all specified delegates.
Solve the simulation again. This time, be sure to let it finish.
The delegates move in three dimensions, soaring and then descending.
Revealing the eagle
You'll assign an animated bird object to each delegate.
Open the Display panel. On the Hide rollout, click Unhide All.
Only the Eagle object was hidden. If you haven't changed the Perspective view, you'll see it in that viewport. If you have, and the Eagle object is not visible, use Shift+Z to undo viewport changes.
Select the Eagle object and drag the time slider to see its animation.
The bird flaps its wings from frames 0 to 186 and then remains still. The last key frame is 288.
The bird is animated in place, so you can combine the delegates' motion with the bird's animation to create a convincing animation.
There are quite a few interim keyframes, even while the bird doesn't move, because Motion Clips uses interim frames to blend animation clips when it synthesizes an object's animation.
Assigning animated objects to delegates
Select the crowd object and click Scatter to open the Scatter Object dialog.
Specify Eagle as the object to clone
How Many is already set to 5.
Turn off Clone Controllers so the eagle's animation won't be replicated in the clones.
If you don't do this, the existing animation mixes with the synthesized new keyframes, which can create confusing and erroneous results.
Click Generate Clones and then click OK to exit the dialog.
Drag the time slider to see the non-animated clones superimposed over the original, animated eagle.
Next, you'll link the delegates with the eagle clones, repositioning the clones at the same time.
Click Objects/Delegate Associations to open its dialog.
Click the Add button under the Objects list and select the five eagle clones: Eagle01 through Eagle05.
Click the Add button under the Delegates list and select the five delegates.
The two lists appear in alphabetical order, indicating the order in which each delegate and eagle mesh are to be paired. You can change the order by highlighting list items and clicking the up and down arrows in between the two lists. In this case, it's not necessary.
Click Align Objects with Delegates.
In the viewports, the eagle clones line up with the delegates. But they're not linked yet.
Click the Link Objects to Delegates button and click OK to close the dialog.
This creates a parent-child hierarchy for each pair, with the delegate as the parent in each pair.
Drag the time slider to observe the eagle clones moving with the delegates.
The eagle clones remain in their initial, wings-raised animation position as they move.
Using Clip Controllers
You'll use Clip Controllers to apply the correct animation clips from the original eagle object to the clones. There are three clip controller types:
Global Clip Controllers: the objects from which the animation clips are derived, in this case, the Eagle object.
Master Clip Controllers: the block controllers that are created in Track View. There is one controller for each object to which the synthesized animation is applied. For more information, see the Block Controller topic in the 3D Studio MAX Online Reference.
Slave Clip Controllers: objects containing all animation tracks in each Master Clip controller. For more information, see the Slave Parameters Dialog topic in the 3D Studio MAX Online Reference.
In the Crowd Modify panel, scroll down to the Global Clip Controllers rollout at the bottom.
Click New and select the Eagle object.
In the Global Clip Controllers list, click the Eagle entry and click the Edit button to open the Synthesis Dialog.
The dialog's three tabbed panels let you set up the clip controllers in a logical workflow.
In the Motion Clips panel > From Global Object group, turn off all five check boxes.
These are useful only when you've animated the global object's position and rotation and want to incorporate this animation in the resulting states.
In the same group, click New to add a new clip with the default name MotionClip.
The MotionClip Parameters dialog defines animation clips from the global object. The current end frame is automatically set to the last key in the global object's animation.
Change Name to Flap, and set End to 186, the last frame of the flapping motion. Click OK.
Create a second clip called Glide, and set it to use frames 187 through 288. Click OK.
The clips use different colors so you can distinguish them in Track View.
You'll define two states to specify how a delegate moves at any given time. You can specify values or value ranges for one or more of these motion categories: speed, acceleration, pitch, pitch velocity, and heading velocity. You can also use MAXScript to define a state. As you define states, you assign clips to them. For example, if your animated object uses different motions for turning sideways or slowing down, you create a state for each one and assign it the appropriate motion clip.
Create one state for upward motion that uses the Flap clip, and a second state for downward motion that uses the Glide clip.
Click the State tab and click New State. Name the state Flap.
Click Add Clip and choose the Flap clip.
Click Edit Properties.
You'll use the States dialog to apply the Flap state when the delegate moves upwards.
Click the Pitch tab and turn on Use Pitch.
The Range settings become available. Use these to specify the range of pitches to activate this state.
Set Min to 1.
The bird will flap its wings whenever its pitch is between 1 through 180 degrees (when it's flying upwards).
Click Exit to close the States dialog.
Add a second state and call it Glide.
Assign it the Glide motion clip and set the Glide state to use a pitch range of -180 to 0.
The bird will stop flapping its wings whenever it's flying downward or level. You can also set different flapping rates for different pitches by creating more clips when you set up the global object.
Specifying master motion clips
This is the final part of the motion clip setup procedure. Here you specify the master motion clips, that is, the objects to which the synthesis is to be applied. You also blend the clips and synthesize the animation.
Click the Synthesis tab.
Click the New Master Motion Clip button and select the five eagle clones.
The global object doesn't appear in the Select dialog because you designated it as the object from which the clips are derived.
In the Synthesis Blend Parameters group, click Auto Blend All.
Auto Blend creates natural-looking transitions between the clips. To see an example of the results of Auto Blend, set From Clip to Glide and To Clip to Flap. The blend from gliding to flapping begins on the 80th frame of the Glide clip.
Click Synthesize All.
This generates the animations for the clones. You don't have to solve the crowd simulation unless you change delegate or behavior settings.
Turn off real-time animation playback in the Time Configuration dialog and play back the animation. Maximize the Perspective viewport and zoom in.
Although the birds should flap their wings only when they fly upward, and then stop flapping to glide downward, it isn't quite working that way. The problem is that the clips are too long for their matched states. For instance, a bird might fly upward for only 50 frames, but the animation clip for the Flap state is 187 frames long. You'll need to modify the clips.
Understanding Block and Slave controllers
Before you modify the clips, take a look at the "behind the scenes" results of the synthesis process; that is, the creation of block and slave controllers.
Open Track View.
In the hierarchy pane on the left side, expand Global Tracks, expand Block Control, and expand Global Motion Clip::Eagle.
Scroll down or expand the Track View window vertically so you can see a few of the Master Motion Clip items.
In the track hierarchy, the global motion clip from the Eagle object's animation is the parent to the master motion clips for the eagle clones. Each master motion clip is a different sequence of blocks, created during the synthesis process. The Flap and Glide blocks are each a different color.
Expand a master motion clips to see the Flap and Glide slave tracks. Expand a slave track to see its keys.
Close Track View.
Modifying the clips
Examine the global object's animation to see how to fix the synthesis.
Click the Eagle object and drag the time slider slowly.
The wing-flapping animation repeats four times. The clip needs only part of one cycle, though, because the clip controller can blend between the last frame of one cycle and the first of the next. The flap cycle should start with the wings all the way up and end with the wings slightly up.
Move the time slider back to frame 0 and turn on Key mode.
Click Next Key repeatedly while watching the eagle object. Stop at frame 48.
The wing-flapping animation returns to the initial wings-up position at frame 48.
Click Previous Key once.
The last key before the end of the flap cycle is 42. The Flap clip should go from frame 0 to frame 42.
The glide cycle is different. Because there's no actual animation, you must make the clip long enough to avoid generating too many keyframes (as the result of repeating a short clip many times to fill the state), while keeping it short enough to fit within the state length.
For this tutorial, you'll set a glide-cycle length of 10 frames. In your own animations, experiment to find a good length for different clips. Even with animation clips, such as the wing-flap cycle, you may need to scale the animation so the cycle doesn't exceed the shortest length of a state.
Clip controllers perform spline interpolation over the intersection of each pair of blocks using keys within the blocks. To avoid this interpolation altering the motion within the clip, insert additional keyframes near the ends of the motion. This makes the interpolation occur at the extremes of the clip, rather than over its entire length.
So, for the glide clip, you'll move some keys immediately inside each endpoint. These keys are of Bend modifiers applied to the wings, and have already been set to use linear interpolation.
With the master eagle still selected, find the key at frame 205 of the track bar (the mini-track view below the viewports).
Drag the key from frame 205 to frame 211.
It helps to watch the status bar text while you do this.
Drag the next key from frame 228 to frame 212.
The key icon will overlap the icon of the key at frame 211.
Drag the next key from frame 253 to frame 219.
Drag the next key from frame 270 to frame 220.
Enlarged view of track bar, showing keys at frames 211, 212, 219, and 220.
In the above illustration, the track bar has been "zoomed in" for illustrative purposes by shortening the active time segment. You'll see more overlap on your screen.
Now you have keys at frames 211 and 220 that define the clip ends, and keys immediately inside the ends that can be used for interpolation.
To change the clip lengths used for synthesis, edit the global clip controller.
In the Crowd Global Clip Controllers rollout, click the Eagle list item, and then click the Edit button.
In the Global Motion Clips group, choose the Flap list item, and then, in the From Global Object group, click Modify.
Set the End parameter to 42 and click OK.
Modify the Glide clip to extend from frame 211 to frame 220.
Redoing the synthesis
On the Synthesis tab, in the Synthesis Blend Parameters group, click Auto Blend All.
From Clip and To Clip now reflect the changed clip lengths. Also, after the Auto Blend, the Blend Start items change.
Click Synthesize All to apply the new clip lengths to the states.
Close the dialog and play the animation.
Hiding the global object and the delegates
At this point you can hide the global eagle object and the delegates. This lets you see the eagles without the delegates.
Use Select by Name to select all the delegates and the Eagle object.
On the Display panel, click Hide Selected to hide the delegates and global object.
In this tutorial you worked with a global object that was animated in place. All transformational animation was supplied by the crowd system. You can also derive delegate motion on the global object's transformational animation, if it exists.
The global object's animation wasn't ideal for the crowd simulation. You learned how to adapt an animation so it works better in a simulation.
Lesson 6: Creating a Crowd of Swimming Bipeds