Tutorial 8: Working with Crowd Animation

Lesson 5: Using Crowd with Animated Non-Biped Objects

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.

Assigning behaviors

  1. 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.

  2. Select the crowd object and in the Modify panel> Setup rollout add a Space Warp behavior.

  3. 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.

  4. Add an Avoid behavior.

  5. In the Avoid Behavior rollout, click Multiple Selection to the right of the None button.

  6. In the Select dialog, select all of the delegates and click Select.

    This sets the delegates to avoid each other.

  7. Open the Behavior Assignments dialog.

    The delegates have already been grouped into a team (Team0).

  8. Assign both behaviors to the team and close the dialog.

  9. 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

  1. 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.

  2. In the General group, turn off Constrain to XY Plane.

  3. Turn on SET for Constrain to XY Plane.

    You can also vary the delegates' speeds.

  4. 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.

  5. 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.

  6. Click the Apply Edit button to close the dialog and apply your changes to all specified delegates.

  7. 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.

  1. 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.

  2. 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

  1. Select the crowd object and click Scatter to open the Scatter Object dialog.

  2. Specify Eagle as the object to clone

    How Many is already set to 5.

  3. 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.

  4. Click Generate Clones and then click OK to exit the dialog.

  5. 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.

  6. Click Objects/Delegate Associations to open its dialog.

  7. Click the Add button under the Objects list and select the five eagle clones: Eagle01 through Eagle05.

  8. 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.

  9. Click Align Objects with Delegates.

    In the viewports, the eagle clones line up with the delegates. But they're not linked yet.

  10. 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.

  11. 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:

Defining states

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.

  1. Click the State tab and click New State. Name the state Flap.

  2. Click Add Clip and choose the Flap clip.

  3. Click Edit Properties.

    You'll use the States dialog to apply the Flap state when the delegate moves upwards.

  4. 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.

  5. Set Min to 1.

    The bird will flap its wings whenever its pitch is between 1 through 180 degrees (when it's flying upwards).

  6. Click Exit to close the States dialog.

  7. Add a second state and call it Glide.

  8. 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.

  1. Click the Synthesis tab.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  1. Open Track View.

  2. In the hierarchy pane on the left side, expand Global Tracks, expand Block Control, and expand Global Motion Clip::Eagle.

  3. 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.

  4. Expand a master motion clips to see the Flap and Glide slave tracks. Expand a slave track to see its keys.

  5. Close Track View.

Modifying the clips

Examine the global object's animation to see how to fix the synthesis.

  1. 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.

  2. Move the time slider back to frame 0 and turn on Key mode.

  3. 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.

  4. 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.

  5. With the master eagle still selected, find the key at frame 205 of the track bar (the mini-track view below the viewports).

  6. Drag the key from frame 205 to frame 211.

    It helps to watch the status bar text while you do this.

  7. Drag the next key from frame 228 to frame 212.

    The key icon will overlap the icon of the key at frame 211.

  8. Drag the next key from frame 253 to frame 219.

  9. 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.

  10. In the Crowd Global Clip Controllers rollout, click the Eagle list item, and then click the Edit button.

  11. In the Global Motion Clips group, choose the Flap list item, and then, in the From Global Object group, click Modify.

  12. Set the End parameter to 42 and click OK.

  13. Modify the Glide clip to extend from frame 211 to frame 220.

Redoing the synthesis

  1. 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.

  2. Click Synthesize All to apply the new clip lengths to the states.

  3. 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.

  1. Use Select by Name to select all the delegates and the Eagle object.

  2. 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.