To double-check, just click anywhere in a blank space in a frame view to make sure that no objects are selected, choose the head joint toensure it is selected, and then click the SelAssi
Trang 15 Adjust the mesh rotations to match the pose in Figure 14.78 You want the ter slightly bent at the knees, with his left arm slightly bent beside him and theright arm bent up at 90 degrees Starting with the base node and moving on to thepelvis, hips, and shoulders (in that order), adjust the joints of the skeleton.
charac-Remember to rotate hip, knee, elbow, and shoulder joints to move the joints at theextremities Pay particular attention to the placement of the pelvis, lower spine,and hip nodes The pelvis should be well below the level of the hip nodes, and theyshould be just a tad higher than the lower spine
Rigging: Attaching the Skeleton
Now we have the skeleton built, the nodes have been named, and the bones are alignedinto a pose we like Next we are going to attach our model to the skeleton That way, whenthe skeleton is manipulated, the mesh of the model will follow suit It is during this stepthat you might be inclined to thank me for insisting that you retain mesh groups for thedifferent model components like arms and feet and so on!
Rigging the Head
We'll begin with the head, just to get a feel for the rigging operation
1 In the Joints tab in the toolbox, choose the joint (or node) named "head" Makesure it appears highlighted in red in the wire-frame views
2 Switch to the Groups tab and choose the head mesh It should appear highlighted
in red, as you already know
3 Switch back to the Joints tab and click Assign Now the head mesh is assigned to
the head node To double-check, just click anywhere in a blank space in a frame view to make sure that no objects are selected, choose the head joint toensure it is selected, and then click the SelAssigned (Select Assigned) button Thehead mesh should appear highlighted If not, go back and repeat these three steps
wire-Figure 14.78 The pose-adjusted skeleton.
Trang 2Aw shucks, there it is—the head is now rigged! Of course, that's not the end of the story.There is still the rest of the model.
There's also the issue of what to do when a bone is rigged wrong Sometimes it's a trivialfix, and other times you might have to rerig the whole model Or you might have to rig amodel by attaching a node to just a few vertices rather than a whole mesh or submesh
That can get very, um, fiddly—I guess that would be a reasonable description.
Part of the simplicity in rigging this model comes from the technique we used; buildingfrom primitives allows us to easily define meshes and submeshes We'll use a "one nodeper mesh" rule of thumb It can get trickier using other techniques, but sometimes thoseother techniques might be more appropriate for the model you want to build It's a judg-ment call, as everything important tends to be There is one exception—as there alwaysis—to the "one node per mesh" rule that we'll get out of the way next
Rigging the Torso
Okay, so the head was a cakewalk It wasn't even necessary to show any pictures for you to
be able to follow along How about the torso then—duck soup again, no?
Well, yes…I mean no, actually No duck soup for this one!
The head mesh is attached to the head node, and that is fine Tilting or rotating the headnode will indeed move the head in the manner we want There really isn't a whole lot tochoose from The neck is more a part of the spine than the head The camera and mount1
nodes aren't even related to the skeleton They are special nodes that will have a different
role to play in Torque, which we'll cover later So that leaves the head node to control thehead mesh
The torso, though, has at least five nodes that it might be attached to But which should itbe? Let's eliminate the neck node for now That leaves the spine nodes or the pelvis node
Actually we can use more than one node for a mesh giving different parts of the mesh to
different nodes When we built the torso mesh, we actually combined two primitivestogether, remember that? One was the chest cylinder, and the other was the abdomencylinder We could have left them as two separate submeshes, but I wanted to show youhow to join them together We can still use them as if they were two separate meshes, byassigning their respective vertices to different nodes
If you look at the nodes, you'll see that the pelvis node is pretty well the obvious date to control the abdomen part of the mesh The upper spine node, although probablynot as obvious, is likely the best candidate for the other node, because it exists in circum-stances similar to the pelvis—there are limbs attached So we'll go with these two and seehow that works out
Trang 3candi-What this will mean in terms of animation is that we can have the vertices that areattached to one node move in one way, while the vertices attached to the other node movedifferently Or not It all depends on how you rig it.
None of this is strictly necessary The animations we are going to create don't actually require
the torso mesh be given more than one node, but it's a good thing to learn, so we'll do it
1 To get started with rigging the torso, let's tidy up the ol' drawing board a bit byhiding all the meshes except the torso mesh If you've forgotten how, just go to theGroups tab of the toolbox, choose each mesh, and click Hide Unfortunately, wecan't selectively hide parts of the skeleton It's either all or nothing when it comes
to the bones
2 Choose the pelvis node in the Joints tab
3 Switch to the Model tab and set the Select tool to Vertex mode Then select the tices that are the abdomen You can use either the Front view or the Side view Fig-ure 14.79 shows the vertices to select
ver-4 Back in the Joints tab, click Assign Now the vertices are attached to the pelvisnode
5 Now choose the upper spine node, and then select the vertices for it, using Figure14.80 as a guide
6 Click Assign in the Joints tab, and that should do it
7 Double-check to make sure you didn't overlook any of the vertices by choosingeach node in turn, clicking the SelAssigned button, and looking to see whichvertices for that node might
have been missed If you didmiss any, you can simply selectthe node, select the vertices, andthen click Assign to add them tothe nodes list
There, that's the torso It might not haveseemed so difficult a task to you, but to
me it was a nightmare! Well, maybe notthat bad, but it shows you the kinds ofdecisions you will have to make whenrigging your models What goes whereand how best will it work?
Now that we have a few nodes rigged,let's take a look and see what theyactually do
Figure 14.79 The abdomen vertices.
Figure 14.80 The chest vertices.
Trang 41 If you don't have a button at the lower right called "Anim," then choose Window,Show Keyframer, and make sure there is a check mark there.
2 Click Anim to activate the Keyframer
3 Using the Select tool in the Joint mode, select the pelvis joint (or you can use theJoints tab to do the selection)
4 Use the Rotate tool in freeform mode in the Right Side view You will recall thatfreeform rotation is a simple matter of selecting the Rotate tool, then clicking inthe wire-frame view, and dragging the cursor left and right
Now what you should be seeing is the entire torso, plus the head, rotate around the pelvis.You should also see some strange things as well The arm, leg, foot, and hand meshes don'tmove That's because they aren't rigged yet
But notice that the leg bones are rotating when you rotate the pelvis Aha! I don't knowabout you, but when I bend over, my legs don't move back Well, not unless I'm floating
in water, of course So the pelvis node, while it seems to be an obvious candidate for ing your character at the waist, looks to not be the right one
bend-So go back, right now, and change it It's simply the same procedure I showed you for thepelvis, except you do it for the lower spine node Make sure to click the Anim button totake it out of the Keyframer first, or you won't be able to make the changes I'll wait
Musical Interlude.
There you are Now that that's done, go back into the Keyframer as I showed you before,and check the rotation of the lower spine node
Another Musical Interlude.
Good! So everything should be working as expected now The torso and the head meshesbend over in unison, and all the bones attached above the lower spine bend in unison, as
shown in Figure 14.81 As you've probablydeduced, it is now a reasonably minormatter to rig the rest of the nodes UseTable 14.2 to guide you in your rigging.You just need to match a mesh to a node,attach it, and move on I'm enjoying themusic here, so you go ahead and do therest of the rigging, and I'll sit back andrelax.…
Yet Another Musical Interlude.
Great! With that done, let's move on
Figure 14.81 Bending at the lower spine.
Trang 5Idle Animation
The idle animation is the one used by Torque when the character is just standing there,doing nothing in particular In some games you will see some pretty complex idle anima-tion where the character scratches himself in rather inconvenient locations, looks around,scuffs his feet, and so on We're just going to do a basic breathing sequence so that you'llknow that the character is alive The name for the idle animation in Torque is root
Even with a basic animation, the watchword is subtlety Don't overdo it.
1 Make sure the Keyframer is enabled by clicking the Anim button in the lower-rightcorner
2 Set the number of frames in the Keyframer to 30 Do this in the right-hand editbox in the lower-right corner of the Keyframer (see Figure 14.82)
3 Move the slider to the 1st frame
Table 14.2 Hero Rigging
UpperSpine Torso—chest-area vertices LowerSpine Torso—abdomen-area vertices LShoulder LArm
RShoulder RArm LElbow LHand RElbow RHand LHip LThigh RHip RThigh LKnee LFoot RKnee RFoot
Figure 14.82 The Keyframer control panel.
Trang 64 Choose Animate, Set Keyframe This indicates that this particular frame is a keyframe.
5 Move the slider to the 15th frame
6 Take note of the angle of the elbows and hands
7 Select the midspine node and rotate it 5 degrees around the X-axis
8 Rotate each of the elbows in the opposite direction by about 5 degrees to placethem back where they were before
9 Choose Animate, Set Keyframe to set the keyframe attribute for this frame
10 Move the slider back to the 2nd frame
11 Choose Animate, Copy Keyframes
12 Move the slider to the 30th frame
13 Choose Animate, Paste Keyframes
14 Save your work!
Figure 14.83 shows the subtle pose difference between the 1st and the 15th frames Nowyou can test your animation by clicking the Play button on the Keyframer controls ThePlay button is the one that looks like a single arrow pointing to the right
As long as the Play button is down, the animation will loop If you find it runs too fast,you can change the FPS number in the Preferences dialog box to a lower value to slow theanimation
Notice that when the animation is actually running, that subtle pose change becomesquite noticeable
t i p
An excellent tool called characterFX is useful for creating animations, and it works well with Shape Unfortunately, for logistical reasons it could not be included with the tools on the compan-ion CD However, it does a great job of streamlining the process and is flexible, so a quick Googlesearch for it on the Internet might be worth your while!
Milk-Run Animation
The run animation is the staple of first-personshooters Run and shoot, run and shoot OurHero character has a somewhat awkward lowerbody, which will tend to make any animation
of him running look a bit goofy Well, we'llturn that into a feature and capitalize on thatgoofiness
Figure 14.83 The difference in poses.
Trang 71 Set the Keyframer to 120 frames Additional frames will be added after the 30 youstarted with for the idle animation.
2 Move the slider to frame 31
3 Make sure that Operate on Selected Joints Only in the Animate menu is enabled
4 Rotate the right hip joint slightly and then choose Animate, Set Keyframe Thepose should be similar to the resting pose The reason why we touched that hipjoint at all is to ensure that there is at least one joint in the frame that was affected
so that a keyframe will be made You should have a pose much like that shown inFigure 14.84
5 Move the slider to frame 40
6 In the Right Side view, select the Base joint, andmove it forward by one grid square and upabout three-quarters of a grid square, as shown
in Figure 14.85 This movement of the basejoint moves the entire model—it's a transfor-mation across the ground This transformation
is necessary in order to notify the TorqueEngine that the model is moving and how fast it
is moving It doesn't need to be precise, but itdoes need to be there
7 Select the right hip, and then in the Side viewrotate it so that the leg moves forward
8 Rotate the right knee forward as well, until theleg matches the configuration in Figure 14.85
9 Repeat the rotations for the left leg and move itbackward In order to get things looking right,you might have to adjust the joint positionsslightly by moving them, but not by much
10 Rotate the left arm using the left shoulder nodeand the left elbow node, swinging the hand for-ward until it is approximately opposite the rightleg, as shown in Figure 14.85
11 Set frame 40 to be a keyframe
12 Move the slider to frame 50 Use Figure 14.86 asthe guide for this frame
13 Move the base node one more grid square to theright, but this time move it back down to theground level
Figure 14.84 Frame 31.
Figure 14.85 Frame 40.
Figure 14.86 Frame 50.
Trang 814 Move all of your legs and joints back to approximately the same configuration as
in frame 31
15 Swing the left arm down to the side of the model
16 Set this frame (50) to be a keyframe
17 Move to frame 60 Use Figure 14.87 as the guide for this frame
18 Pose frame 60 the same as frame 40, except swing the legs in the opposite tions
direc-19 Swing the left arm back and rotate the elbow so that the left hand comes up lel to the ground
paral-20 Set this frame to be a keyframe
21 Move to frame 70 Use Figure 14.88 as the guide for this frame
22 Swing the arms and legs back to roughly the pose they had in frame 31
23 Set this frame to be a keyframe Use the Play Forward button to watch the tion If the animation seems to be too fast or too slow, change the FPS setting inthe Preferences dialog box until it seems right, and take note of the value you use.Now you have probably noticed that although we set the pose in only five frames, the pro-
anima-gram automatically interpolated, or figured out, what the in-between frames should look
like Torque does the same thing for us when we usethe model in-game This is goodness That's as much
of the run animation as we're going to do here, but youshould practice working with this for a while The firstplace you should start is to set the keyframe exactly inthe middle of the ones we've already set—at frames 35,
45, 55, and 65—and adjust the leg positions to get abetter animation from the legs
Don't try too hard to make the animation look natural
though—he's a goofy character and should have that
sort of goofy, cartoonlike appearance when running
Head Animation
This is the animation that Torque automaticallyinvokes when it needs to know how far your charac-ter is looking up or down So basically this anima-tion's purpose is to define limits or a boundary andnot so much the movement However, if your charac-ter's facial or head shape would change when looking
up or down, then you would create a more complexhead animation
Figure 14.88 Frame 70.
Figure 14.87 Frame 60.
Trang 9That being said, it is really quite quickly dealt with.
1 Move to frame 71
2 In the Right Side view, rotate the head joint until the head is looking up at themaximum angle you want to allow You may also need to move the head back abit
3 Make this a keyframe
4 Move to frame 72
5 Rotate the head joint until the head is pointed down at the maximum angle youwant to allow You may also need to move the head forward a bit
6 Make this a keyframe also
7 Save your work! There, you are done That's the entire animation sequence! Checkyour frames against Figure 14.89 to make sure you got it all right
Headside Animation
In the same way that the head animation defines the limits for the up and down motionperformed by Torque, the headside animation provides the limits for the left and rightmotion This is most visible from the third-person perspective when in the game
Do the same thing you did for the head animation, but use frame 73 for the left turn andframe 74 for the right turn Make each of these frames a keyframe, and save your workwhen you finish
Look Animation
The look animation is basically another movement-limiting animation that defines howthe character's arms will be posed when he is looking up or down Again, it is a simpletwo-frame animation that doesn't require us to go into in detail now Use frame 75 for thedown "look," or aim Make sure you have both arms positioned sensibly Use frame 76 forthe up aim Set both as keyframes and save your work again
Death Animation
As you saw earlier, there are many possible ways to die Torque supports 11 "standard"
death animations, but you can easilyadd more by writing a minor codechange into the scripts
We'll cover only one death animationhere We'll have the character collapsebackward and fall to the ground on hisback with his feet tossing into the airand back down again Figure 14.89 Head sequence frames.
Trang 101 Move to frame 81 and set the pose back to resemble the resting pose as closely asyou can, without spending too much time on it.
2 Set this frame to be a keyframe
3 Move to frame 90 and rotate the arms and hands to match You can have the acter's head pop off temporarily, like I do, or leave it on but thrown back It's yourmodel! Let Figure 14.90 guide you
char-4 Set frame 90 to be a keyframe
5 Move to frame 100
6 In the Side view, drag the base node backward several grid squares
7 Continue to rotate and move the arms and legs, and rotate the body around thepelvis node to make the body tipped past the horizontal with the bottom of thetorso higher than the top, as shown in Figure 14.91
8 If you haven't guessed it by now, make this frame a keyframe!
9 Move to frame 110
10 The body is hitting the ground, withsome momentum still in the legs.Align the bottom of the torso (which
is actually the character's back) evenwith the ground Rotate the legs andknees to fling the feet up over thebody, and rotate the arms to flingthem away from the body, as shown
in Figure 14.92 By now the basenode should be eight or nine gridsquares behind the origin along theZ-axis, as seen in the Side view
11 Yup, this is another keyframe Goahead, make its day
12 Now for the final resting position.Move to frame 120
13 Lay the body out, flat against theground Also, move the base nodeone or two more grid squares fartherback, to cause the body to slide alongthe ground Lay the arms flat to thesides, the feet and legs down on theground and spread somewhat Tiltthe head back As you can see in Fig-ure 14.93, he's dead, Jim
Figure 14.90 Frame 90.
Figure 14.91 Frame 100.
Trang 1114 Keyframe him, Dano! (Okay, that's
an obscure reference, I'll admit
Indulge me!)
15 Save your work!
Well, that's the lot of them Enough mations to give you what you really need
ani-to know ani-to get moving on animating forTorque in MilkShape There's still more
to cover—we're not quite out of thewoods yet Now we have to tell Torquehow to find the animations
The Animation Sequence Materials
The Torque Engine needs to know wherethe various animations can be found, howlong they run, what type they are, andhow fast they should be run We do thisusing a technique called the AnimationSequence Materials
The general approach is that we create aspecial material, and embedded in thename of that material are the Torquename for the animation sequence, itsdesired playback frame rate, which framesbelong to which sequences (inclusive from start to end), and whether the sequence cycles(loops) or plays once per invocation
You need to go to the Materials tab of the toolbox and create six new materials—one foreach animation sequence Table 14.3 lists the material names you need to use The text in
the "Sequence Material Name" column must all be included in the name, exactly as
shown These special materials tell the Torque DTS Exporter program what special ation to perform on the model as it creates the DTS formatted file for use in Torque
oper-Note that some of the Sequence Material Names don't include some of the option tings If you leave them out, the defaults are used A little later in this chapter you'll findmore detail about the exporter
set-Finally, there is one more special material we need to make, in order to set the global scale
We built this model on a large scale so we could use the Snap To Grid function withoutseeing our vertices snapped way out of line Now, when we export the model, we will need
to have it scaled down Add a material and name it "opt:scale=0.02" This will shrink themodel to one-twentieth its created size, which is about right for our needs
Figure 14.92 Frame 110.
Figure 14.93 Frame 120.
Trang 12Exporting the Model for Torque
In the next section of this chapter, we will look at the Torque DTS Exporter for MilkShape,but for now we'll just use it in a fundamental way to get our model to work in Torque
1 After saving your work, choose File, Export, Torque Game Engine DTS You willsee the Torque Game Engine (DTS) Exporter dialog box appear
2 We're going to take the defaults, but we should make sure they are correct Youwant to have Export animation and Export material information selected, andCollision Mesh should be set to None (Torque handles player collision internally).Click OK when ready
3 Save your DTS file as C:\3DGPAi1\resources\ch14\myhero.dts
That was pretty painless Now let's make sure the model works! We'll dust off the oldTorque Show Tool we used in Chapter 9 and check out the model
1 In Windows Explorer browse your way to C:\3DGPAi1 and launch the Show BookModels shortcut
2 Click Load Shape
3 Find RESOURCES/CH14/myhero.dts, choose it, and click Load
4 The model should appear in the center of the screen, facing away from you
5 Use the navigation keys (described in Chapter 9 in Table 9.1) to rotate the modeland bring it closer to you You should notice that it is already performing the idleanimation (root)
6 Click Thread Control A window will appear on your screen, probably at the lowerright Drag it to the upper-left corner, or wherever is most convenient
7 Click Run in the Sequences list The character should start the run sequence
8 Check out the other sequences, but remember, the ones that don't cycle are going
to run just once and will stay at the last frame You can use the Transitions button
to adjust the transition speeds so that you can check to see if you are getting yourdesired results
Table 14.3 Animation Sequence Material NamesTorque Sequence Name Sequence Material Name
root seq:root=1-30,fps=10,cyclic run seq:run=31-70,fps=15,cyclic head seq:head=71-72
headside seq:headside=73-74 look seq:look=75-76,fps=15 die1 seq:die1=80-120
Trang 139 If necessary, go back to your model in MilkShape and make adjustments to youranimations, and then come back here to check them out.
Good job! The rule of thumb is, if it works in the Show Tool, it will work in the game,because the Torque Engine is behind both
You now have an animated Hero character to use in your game! And it really isn't that ficult If you are even a halfway decent artist and have a good eye, I'm sure your model andanimations are much better than mine
dif-The next section provides some detail into the workings of the DTS Exporter for theTorque Engine With its help, you should take some time to fiddle with settings and dif-ferent animations and add your own animation sequences
The Torque DTS Exporter for MilkShape
The Torque DTS Exporter is included in your C:\3DGPAi1\resources\tools directory and
is called ms2dtsexporter.dll Copy this file into your MilkShape directory, C:\ProgramFiles\MilkShape 3D 1.6.6, and then restart MilkShape The name of the MilkShape folderchanges from version to version, so watch out for that The exporter shows up under theFile, Export menu
The Torque Game Engine (DTS) Exporter Dialog Box
The Torque Game Engine (DTS) Exporter dialog box (see Figure 14.94) has three groups
of options, none of which normally need to be set Option settings are not saved, so yourarely use this dialog box for more than just a means to double-check your option values
The recommended approach is to set options using special materials
Collision Mesh
The exporter allows you tocreate as many collisionmeshes as you want Eachcollision mesh must benamed "Collision"; if youhave three collision meshes,they will all be named
"Collision" If you do nothave a collision meshdefined, you may have theexporter create one for you
as either a box or a cylinder Figure 14.94 Torque Game Engine (DTS) Exporter dialog box.
Trang 14You can also manually select an existing mesh Player-characters don't need a collisionmesh at all.
Select the Create a visible copy of the collision mesh check box to make the mesh visible
as well as collidable
Animation Settings
The Animation Settings group displays the global values for the Animations
■ Frames per second This field indicates at what speed the Torque Engine should
play at the animations This field can be set using an Export Options material andapplies globally to all animation sequences This does not affect the number ofkeyframes; it simply sets the rate at which they will be played
■ Export animation If the shape is animated, but no animation sequence has been
defined for it, then this field contains the name that will be assigned to it Thesequence will cover the full timeline This feature is useful for simple models with
a single animation sequence
Other Settings
The Other Settings group contains miscellaneous settings values
■ Global scale factor The global scale factor is the amount by which the shape is
scaled when it is exported The default scale factor is 0.1, but this field can bechanged to any value set using an Export Options material
■ Minimum visible size (pixels) If the projected screen size of the bounding radius
of the shape drops to the minimum visible size, the shape will no longer render.This is normally used to switch between different detail levels, and it's recom-mended that you leave this at the default value: 0
■ Export material information You may disable the exporting of material
informa-tion (not recommended) by clearing the Export material informainforma-tion check box
Trang 15Export Options
Materials with special names can be used to set several export options These materials areignored during export and are solely used to set options
Option materials are named as follows:
opt: option, option,
All other properties of the material are ignored Table 14.4 lists the available options
There may be more than one option material If the same options are set on multiplematerials, then the last one in the material list is the value used Here are a couple exam-ples of valid material names:
opt: fps=10, cyclic opt: scale=0.1
Material Option Flags
Material attributes can be set using the MilkShape Shininess and Translucency sliders aswell as by embedding additional flags in the material name
Environment mapping can be controlled for the model by use of the Shininess slider—it'sthe one on the left-hand side Setting the slider to any value but 0 will enable environmentmapping for the texture Note that the texture you are using must have an alpha channel,which will be used to control the per-pixel shininess of the texture Any value of the slid-
er other than 1.0 or 0.0 will be ignored
You can enable translucency by setting the MilkShape Translucency slider—this is theslider on the right-hand side Setting the slider to any value other than 1.0, which is to thefar right, will enable translucency for the texture The texture you are using must have an
Table 14.4 Export Options
scale=n The global shape scale factor, where n is a floating point value The default scale
value is 0.1.
size=n The global minimum visible pixel size The default is 0.
fps=n The global default frames per second value for animations Each animation
sequence may set this value, but if it's not defined by the sequence, this default value is used.
cyclic The global default animation looping flag Each animation sequence may set this
value, but if it's not defined by the sequence, this default value is used.