Torque Game EngineTorque Game Engine Documentation
Version 1.3.x

Character Basics

This section will provide a general overview of how to prepare characters for Torque.

General Information

General Information

Deformable meshes are supported by the exporter and the Torque Game Engine through the use skeletal animations. The vertices of the mesh are assigned weights to the skeletal nodes (joints), and the transforms of the skeletal nodes then deform the mesh in real time.

Because building characters or other shapes using skeletons is a very deep subject matter, this section of the documentation will only go over how to setup and export completed skeletal animations.

The File Pack contains a complete project directory called simpleBox that you may use during this tutorial.

simpleBox Setup

  1. Set the project to simpleBox (File > Project > Set) from the File Pack.
  2. Open simpleBox_start.mb and examine the file.

    simpleBox is a very basic animated character. The mesh is just a box that has been resized and triangulated. There are 5 joints in the hierarchy. And the mesh is bound to the joints with a smooth skin. The joints have all been renamed to make it easier to identify them in Outliner and HyperGraph.

    
									Shaded

    
									Wire Frame
  3. Open either Outliner or HyperGraph and examine the scene structure.

    
									Hyper Graph

    Notice that the child of start01 is root_JNT, the parent joint of the skeleton. simpleBox's mesh is at the scene's root level instead of being in the DTS hierarchy. This is the way skinned meshes work with the Torque Game Engine. Any mesh that is smooth skinned to a skeleton must be at the scene root level and not embedded in the DTS hierarchy.

    Several things still need to be added to complete the scene.

    First, create a bounding box and constrain it to move with simpleBox.

  4. Create a bounding box. Ignore any warnings that you may see.
  5. Select root_JNT, then shift-select bounds.
  6. Go to Constrain > Parent options box.
  7. Make sure that Translate Z is the only option checked. Leave the weight at 1.
  8. Click the Add button.

    
									Parent Constrain

    Now, when simpleBox moves forward or backwards, bounds will follow accordingly. Vertical and side-to-side movements as well as rotations are ignored, because the parent constraint is only operating on Translate Z.

    Next, scale the bounding box to contain simpleBox's animations and freeze its scale transforms to avoid errors when exporting.

  9. Scrub through the timeline and adjust the scale of the bounding box so that simpleBox remains completely contained within it during all animations. You may use these values: scaleX = 1.55, scaleY = 6.4, scaleZ = 1.55.

    
									Bounds
  10. With bounds selected, go to Modify > Freeze Transformations options box.
  11. Uncheck Translate and Rotate. Scale should be the only option checked.

    
									Freeze Transform
  12. Click the Freeze Transform button.

    Freeze Transformations makes the the current transformations on the selected objects to be the objects' zero position. Only the scale attributes need to be frozen, because the translate attributes are being controlled by the parent constraint, and the rotate attributes must remain where they are so that the shape is oriented correctly in the Torque Game Engine.

  13. Save the Maya scene file as mySimpleBox.mb.

simpleBox Animation Setup

Now that simpleBox is animated and the DTS hierarchy is setup, the shape needs to be prepared for exporting animations.

There are two methods for doing this:

The first method is to create multiple sequence nodes in the Maya scene file, name each sequence accordingly, and set the start and end frames to match the frames during which each animation occurs. Then, the entire scene can be exported as a single DTS file. This method is fairly simple, but it does not allow for customization of export options for each individual sequence.

The second method is to save each of the animations as individual Maya scene files. Each Maya file with animation will have a single sequence node corresponding with the desired animation. The Maya file with the base shape will contain all of the meshes and nodes but will not have any sequence nodes. Each file will be exported individually: the base shape will be exported as a DTS file, and the animations will each be exported as DSQ files. All of the files will then be merged together in the engine using a .CS script file.

This method is obviously more complex, but it does allow for a greater degree of customization. For example, you could create a character's upper body motions (e.g. aim, look, shoot, etc.) and lower body motions (e.g. walk, run, sidestep, etc.) as separate Maya scene files. Then you could use a configuration (.CFG) file to specify exactly which nodes export for each DSQ file. These DSQs can then be played back on separate threads in the engine and combined to create a wide variety of movement combinations. You can read more on configuration files, threads, and sequences in the Maya2DTS General Reference.

This tutorial will use the second method. You will create and export separate DTS and DSQ files, create a .CS script, and then view the animations in the ShowTool. Configuration files will not be used for this tutorial. Consult the Maya2DTS General Reference for more information.

Because simplyBox is already animated, continue working with mySimpleBox.mb from the previous section.

  1. Examine the animations closely and take note of the frames on which each motion begins and ends.

    Table 7.1. 

    AnimationstartFrameendFrame
    bend side to side060
    jump forward6180
    look right to left91120
    jump up130150
    bend front and back150170
    bend front and back175210

    Because all of the animations were created in the same file, there are some "transition" frames that may look odd. Those frames can be ignored.

  2. Create a sequence node named Sequence_bendSide.
  3. Set startFrame to 0 and endFrame to 60
  4. Save the Maya scene file as mySimpleBox_bendSide.mb.

    Since the sequence node has already been created, and there should be only one sequence node per animation file, simply rename the existing sequence node and adjust the start and end frames.

  5. Rename Sequence_bendSide to Sequence_jumpForward.
  6. Change startFrame to 61 and endFrame to 80.
  7. Save the Maya scene file as mySimpleBox_jumpForward.mb.
  8. Repeat the previous steps for the remaining animations. You may use the following settings:

    Table 7.2. 

    Maya file nameSequence namestartFrameendFrame
    mySimpleBox_bendSide.mbSequence_bendSide060
    mySimpleBox_jumpForward.mbSequence_jumpForward6180
    mySimpleBox_look.mbSequence_look91120
    mySimpleBox_jumpUp.mbSequence_jumpUp130150
    mySimpleBox_bendFrontBack.mbSequence_bendFrontBack150170
    mySimpleBox_fallBack.mbSequence_fallBack175210

As you work through the files, make sure that there is only one sequence node per Maya file. Also make sure that you do not change the DTS hierarchy.

Exporting simpleBox's Animations

Now that all of the animation files are properly setup, it is time to export everything.

First, make sure that export directories have been specified for both DTS and DSQ files.

  1. Go to File > Project > Edit Current....
  2. Scroll down in the project window to the Data Transfer Location section. Make sure that exportDTS is set to dts and exportDSQ is set to dsq. Click the Accept button to close the window.

    Based on these settings, DTS files will be exported to the dts directory, and DSQ files will be exported to the dsq directory. Both of those directories are inside the main simpleBox project directory.

  3. Open mySimpleBox.mb.
  4. Click Export Shape in the dtsUtility window.
  5. The export is complete when you see the message "Export complete." in the command feedback area.
  6. Open mySimpleBox_bendSide.mb.
  7. Click Export Sequence in the dtsUtility window.
  8. During the export process, you will see the bendSide animation playback in the viewpanel. The export is complete when you see the message "Export complete." in the command feedback area.
  9. Export the rest of the animation files.
  10. Open an explorer window and navigate to the simpleBox project directory. Inside the dts directory, you should find mySimpleBox.dts along with dump.dmp. Inside the dsq directory, you should find mySimpleBox_bendFrontBack.dsq, mySimpleBox_bendSide.dsq, mySimpleBox_fallBack.dsq, mySimpleBox_jumpForward.dsq, mySimpleBox_jumpUp.dsq, mySimpleBox_look.dsq, and dump.dmp.
  11. Copy all of the DTS and DSQ files as well as the texture file into a shape directory in the Torque project. If you are using the demo, you can place files in demo\data\shapes inside the Torque example directory.

Writing the .CS File

Shapes consisting of multiple files must be merged together in the engine using a .CS script file.

To create a .CS file:

  1. Open a new document using a text editor (Notepad or Wordpad will work fine).
  2. Enter the following lines:

    datablock TSShapeConstructor(mySimpleBoxDTS)
    {
    
         baseShape = "./mySimpleBox.dts";
    
         sequence0 = "./mySimpleBox_bendFrontBack.dsq bendFrontBack";
    
         sequence1 = "./mySimpleBox_bendSide.dsq bendSide";
    
         sequence2 = "./mySimpleBox_look.dsq look";
    
         sequence3 = "./mySimpleBox_jumpForward.dsq jumpForward";
    
         sequence4 = "./mySimpleBox_jumpUp.dsq jumpUp";
    
         sequence5 = "./mySimpleBox_fallBack.dsq fallBack";
    
    };
    		            
  3. Save the file as mySimpleBox.cs in the same location as the shapes DTS and DSQ files.

The first line of the .CS files constructs the shape in the engine. Then the base shape (the DTS file) is added. Then all of sequences are added. Each sequence has an index number and a name associated with it. Animations are called by index number in the engine. The sequence names are visible in the Thread Control section of the ShowTool.

Viewing simpleBox in the ShowTool

Make sure the DTS file, all DSQ files, the .CS file, and the texture file are located in a shape directory inside the Torque project.

  1. Launch the ShowTool.
  2. Click the Load Shape button.
  3. Open mySimpleBox.dts from the shape list.

    simpleBox will load and the first animation on the list (bendFrontBack) will be playing.

    
									Bend Front to Back
  4. Click the Thread Control button.

    The Thread Control window allows you to playback and test all of the animations in your shape. The sequences list displays each animation for your shape using the name and order that was designated in the .CS file.

    
									Thread Control

You can view all of the shape's animations by clicking through the list of sequences. You can start and stop the animation as needed, scrub through the animation using the slider, and view different transition methods. You can also create addition threads to layer animations.

Even though this was a very simple character, the overall concepts will apply to practically any character you create in Maya. Be sure to read through the Maya2DTS Reference Guide for more detailed information about creating shapes and animations for Torque.