Creating a Simple 3D Game with XNA/Armatures and Animations
Creating an ArmatureEdit
In order to create 3D animation in Blender, the first step is to create an armature, more or less a bone structure, for your model. Creating one will let you animate the movements between your bones, which will then move the vertices connected to them. This tutorial will cover the process of making and moving a set of bones created and attached to the fish made in the previous tutorials.
First of all, move your cursor to the tip of the tail fin inside the body (the easiest way to do this is to select the vertice on the end, push space, and select 'Transform'/'Snap'/'Cursor to selection') and add a new armature by moving back into object mode, and hitting space, and selecting 'Add'/'Armature'. This should give a single bone relative to the current camera position.
Rotate this bone by 90 degrees so it moves along the fishes body. Most of the same manipulations which was covered earlier in these tutorials for models (rotate, scale, extrude etc.) will work here. Enter edit mode with the armature selected. and extrude your now rotated bone to the side fins by selecting the circle connected to the thinnest part of the triangle and hitting 'E'. Move it along until it is about half way through.
Using this technique, create bones which lead along the back and side fins, with a bone leading parallel across the rest of the body.
To finish off the bone structure, create two bones off of the end closest to the face, each parallel to the mouth and about the length of each end of the mouth. Then select only the new tow, and hit 'Alt-P'. This will allow you to disconnect the bones from the parent, so they can now be moved slightly down to match the position of the mouth as below, while still being part of the original armature.
Finally, connect your bones to your model using the following process. Select each of the models, and the same way you set up the subsurf modifiers, add an armature modifier. Enter the name of your armature (which appears on the bottom left when the armature is selected) and ensure that the 'Envelopes' option is deselected, and 'Vert groups' are selected. This changes how the armature effects the model, but for the purposes of the rest of the tutorial, we will need to use 'Vert groups'
Select the armature in object mode, and enter pose mode. Later this will allow you move your bones around and see the effect on the model, but for now just select one of the bones, and then go back to object mode and select the model you want to connect it to. Enter weight paint mode, and then you should see your chosen model surrounded by blue, and your cursor should turn into a little paint brush. In this mode, you 'paint' the sections of the model which you want to be covered by that bone. Various options at the bottom can be changed to modify how it can be painted, and for now I would recommend you deselect the 'soft' button to speed up the process. Do this for all of the related bones to your model. To test out this effect and ensure it is working by re-entering pose mode, and moving the model around.
Now its ready for some animations.
Animating your modelEdit
The basic principle of the animation we will be creating is to set different locations for the bones at separated points of time on at different animation frames (keyframes), and then have Blender (and later XNA) calculate the positions in between those two on these times. Imagine it as being similar to directing a film, where you would tell the actors the positions to move between, without having to worry about every step they make.
Split up your screen into two windows as previously, and place the left window into 'Action Editor' mode.
Now to start with, we will create a simple swimming animation.
Select the browse choices button on the right window, and select add new, and call it 'Swim'.
Next, move the bones in pose mode so that they look like the body of a fish distorted, as if swimming. I did this by moving the bone closest to the head and one connected to the tail by 10 degrees in alternate directions on the X axis, and the fins by 10 on the Z axis. Then select all the bones modified for the animation and hit I and select 'Rot'. This will create a rotation key at frame 1 for your project, which you should see on your action editor on the left.
Move the animation 5 frames on by clicking on frame 5 on the action editor, and move all of the bones you just moved in the opposite direction to create the next stage of movement. Press I, and save these key frames the same way.
Finally to complete this animation, do the same process as before, which should move the bones back into their original position (alternatively, you can select the initial keyframes and duplicate them by hitting 'Shift-D'). Then click 'View' on the bottom of the right window, and select 'Preview range from action length' which will set the animation length to between the first and last keyframe. Select 'Play back animation' in the same menu, and you should see a swimming Fish.
Next, following a similar process and with the 'Swim' still selected, select 'ADD NEW' and modify the two bones connected to the mouth to form a one frame 'Smile' and 'Frown' animation (if stretching the term a little) which will be used in the XNA game late into the development when we start adding NPCs.