Section III: Animation Setup


General Information:

There are a couple of ways that you can get animation into the game. You can animate all of the sequences in one file and export it as a DTS (as was done in the Simple Shape tutorial) or, you can have every sequence in its own 3DSMAX file, export them as DSQ files and merge them in at runtime with a .CS file. Having the base mesh and skeleton in one max file and having each sequence contained in its own Max file is the preferred way to do it as it gives more explicit control of the nodes being exported and allows more control of the character. For simple shapes with only a few animations, putting the sequences in the main 3DSMAX file will work fine. For characters, save each sequence in it's own file and export the sequences as DSQs.


Threads:

To fully understand the animation system in the engine, one must realize that several animations (called threads in the engine) can be played concurrently, at different speeds in both directions, and can control different parts of the hierarchy.

If two threads try to control the same node, the sequence priority (covered in the Sequence Object Parameters section) will determine which thread controls a particular node.

In practice, the best way to go about doing things is to export different types of animation to control different parts of the character, and then have them hooked up to different controls. In the game, you can look around while running. Instead of having a run-look -left, run -look-middle, run-look-right, there is a run animation, and a look animation that are being played at the same time. In this way, you can get a great deal of flexibility out of very few animations.

The Look animations are controlled by the mouse (running on one thread) while movement is controlled on another thread which is controlling the lower body animations (forward, back, side). Celebration and death animations control the whole body and are played on the same thread as the body movement animations.

Viewing multiple threads is the ShowTool will be covered in greater detail in the ShowTool section.


Blend Animations:

There are special sequences that can be marked 'blend'. These allow additive animation on the node structure of the shape. These will not conflict with other threads, and can be played on top of the node animation contained in other threads.

Blend animations are relative. Blends only read the changes that occur over the course of the animation and not the absolute position of the nodes.

This means that if a node is transformed by a blend animation, it includes only the transform information for that node, and it will add that transformation on top of the existing position in the base shape(the DTS).

This can be somewhat confusing, so I will attempt to explain it in greater detail.

Blend animations add additional animation on top of other animations. If a sequence is a blend, the transforms will be added on top of the other animations already playing in the engine on a node by node basis. The animation values only are added.

In the following diagram, figure 1 represents the position of the the animated nodes in the DSQ file. Figure two is the animation that was applied. In figure 2, The top bone has rotated about 30 degrees.

In figure 3, we have the same bone structure as it exists in the DTS shape. The blend animation is applied, and the node rotates about 30 degrees, as shown in figure 4.

This is what you would expect to happen. The root position of the bones in the DSQ and the DTS shape are identical, so the animation applied appears to directly animate the nodes. This is not what is happening, and this is usually where people get confused.

In figure 5, we show the bone structure of a DTS shape where the root does not match the root position of the blend DSQ. In figure 6, we see the blend animation from figure 1 applied to a DTS shape with a different root position.

The blend animation did not alter the position of the whole chain. Instead, it only added the rotation value to the animated bone.

This is not a bug, this is the way it was designed to work. The values are added to the present state of the chain on a node by node basis.

Bear in mind that a blend can be played as a normal sequence, or it can be played on top of other sequences. When another sequence is playing, it will alter the root position, and the blend will be applied on top of that.

If you try to do a blend sequence where the root position is different than the 'normal' root (in the default root animation), you might expect that the blend will blend it to the new root (the position the character is positioned in during the blend animation). But it doesn't work this way. Since nothing would actually be animating, it doesn't move the bones to the new position. What is contained in the blend sequence is only transform offsets from the blend sequence root position.

It is a good idea not to have a different root position in your 'normal' animations and your blends, as they can easily get out of sync.


Sequences types used by the the default game character:

What follows is a listing of the different types of animations that were used to create the default player character.

Normal Full Body:

These animations are what you would consider to be 'normal' animations, with all the nodes exporting and controlling the entire skeleton.

Lower Body Only:

These animations are exported with a .CFG file that isolates the nodes in the lower body of the character.

Blends:

These animations are blend animations that are designed to be played on top of the movement animations and exist in the same directory as the full body animations (using the same .CFG) but are set to blend in the sequence helper.

Not that these are done by using one animation that goes from one extreme to the other with the blend reference being the center position of the animation. The sequence is usually initialized in to start in the middle and play either forward or backward from this state by the engine, which is determining the position of the animation from the user input (mouse look)


The .CS script file:

At runtime, the DTS and DSQ shapes are merged together to create a new shape that contains the mesh and all it's associated data (mountpoints, etc…) and the animations. This is done by including a .CS file for the shape in the directory with the DTS and DSQ file. The .CS file for the shape should be the same as the DTS.

player.dts has player.cs, etc

An example player.cs is located in the documentation file pack.

To construct a shape in engine, you start off with this at the beginning of the file:

datablock TSShapeConstructor(PlayerDTS)

This tells the engine the name of the shape it is constructing and is called in the engine.

After that, the shape and animations are added like this.

{
   baseShape = "./player.DTS";
   sequence0 = "player_root.DSQ  root";
   sequence1 = "player_forward.DSQ  run";
   sequence2 = "player_back.DSQ  back";
   sequence3 = "player_side.DSQ  side";
   sequence4 = "player_lookde.DSQ  look";
   sequence5 = "player_head.DSQ  head";
   sequence6 = "player_fall.DSQ  fall";
   sequence7 = "player_land.DSQ  land";
   sequence8 = "player_jump.  jump";
};         

The Base shape is added, and then all the sequences are added to the shape and given a number. All the numbersequnces reference a file. Names can be associated with the animations. You can see these names in the ShowTool in 'thread' control.

So, Sequence 0 is created in the shape, it uses the 'player_root.DSQ, which is named root.

Note that animations are called by name in the engine, the sequence numbers are ignored. If you use the same animations and names that are used in the demo, your character will work without any changes to the code. Also, if you call your player 'player' you will not have to alter any other scripts to get it to load as the player character.


The ShowTool Revisited:

If you did everything correctly, your player shape will load in the ShowTool, and it should be animating using sequence0 from your .CS.

If you are using a .CS, a 'new' shape is created by merging the DTS shape with the DSQ files specified in the .CS file. If the DSQ files contain nodes that are not in the DTS, they will not load. Warning messages will be generated in the console (press the ~ key to get the console) and can assist you in tracking down any problems with your shapes and animations.

If you did not make a .CS file, you can manually load animation sequences into the shape. As long as the DTS contains the nodes that are in the DSQ, it will load. It is important to note that the nodes are looked up by name, so if the naming convention matches in all your characters, you will be able to load animations across shapes. If, for example, you had a horse and a human, and they both have skeletons with the same naming convention, you will be able to load the horse animations into the human file and vice-versa. It will not resize the length of the bones in the DTS, it will only apply the rotation data to the skeleton in the DTS. It probably won't look very pretty, but it works.


Triggers:

Triggers can be added to sequence helper objects by using the "Trigger" track in the sequence helper's track view.

You can have up to 32 triggers (1-32) which are turned on by adding a keyframe with the appropriate trigger number as a value and turned off by adding another keyframe with negative value on the trigger number that you assigned on the first trigger keyframe.

If you like, you can only turn them on (and assume that the programmer will turn them off as they are read). As an example, the easiest way to deal with footsteps is to have one trigger for each foot (1=left, 2=right, say). You may have an application where you want to know when the foot is supposed to be on the ground. In that case you would turn on the "foot on ground" state when it first contacts the ground and turn it off when the foot leaves. Thus each foot would have 2 trigger keys: a + one when the foot hits the ground and a - one when it leaves. Add the values and keyframes in the 'trigger' track in the track view of the sequence helper.

If you want your character to leave footprints, all you have to do is go to the trigger track of the appropriate sequence and add a trigger key and a value. In the default Torque engine,1 = left foot, 2 = right foot.


Dropping the Character in the Game as A Player: