Basic Animation Exporting
In this tutorial we are going to animate the crate/box object created in the previous tutorial to demonstrate the process of importing a basic animated model into 0 A.D. This example can be extended to work with more complex models.
Since this process is not extremely straightforward, I will preface this tutorial with some information about the game's 3D engine regarding animations.
(Note: this tutorial is fairly verbose and in-depth. If you already have a rigged model in Blender and some knowledge about the game's art folder (where to put textures…), I recommend you skip straight to the end).
Animations in 0 A.D.
Animations in 0 A.D. rely on three types of files:
- Meshes: those are the basic files that define how an object will look like in-game, such as the crate object in the Basic3DImplementation tutorial. Meshes also contain the "Armature", that is the bones that will be animated.
- Animations: obviously, those files define animations. Each file can only define one animation.
- Skeletons: those define "Skeletons", an in-game concept that defines hierarchical relations between bones. You might think that this is redundant with the armature information in the Model files, and in fact it is. However, they are used to parse animations more easily. Each skeleton can be reused by many different models and animations, which adds a layer of abstraction on top of the 3D meshes.
Using skeletons for animations makes the process a little tricky, so this tutorial will begin by explaining how to animate an object in Blender, then how to export it so that it works in 0 A.D.
With that in mind, let's start.
- STEP 1 Open Blender, and open your file from the Basic3DImplementation tutorial.
- STEP 2 Press space and type in "Armature" in the search box that comes up, and press enter. (This will activate the first option that Blender finds)
- STEP 3 Find Properties panel. If you can't find it, then set one of your panels (other than the 3D View) to the Properties panel.
- STEP 4 Select "Object Data" in the tab bar on the Properties panel.
- STEP 4 Check X-Ray in the "Display" box. This will allow you to see the bones through the mesh so you can manipulate the bones even when the bones are enveloped by the mesh they deform.
- STEP 5 Select the mesh and then the armature in that order, and press Ctrl+P. Blender will give you 6 options of how the mesh should interact with the rig. Rigs for 0 A.D. should use vertex groups (which allow you to select exactly which vertices move with which bones) so the deformations can be made to look as natural as possible. (Bone envelopes, which are basically automatic groups, often will make the deformation look totally wrong.)
- STEP 6 Select the mesh and go into edit mode using the menu on the left side of the bar along the bottom of the 3D View, or by pressing Tab.
- STEP 7 In the "Vertex Groups" box in the Object Data panel, you should see a vertex group called "Bone" selected. This vertex group corresponds to the bone in the armature. To make that bone move all the vertices in the cube, select all the vertices of the cube using the A key with your mouse over the 3D View, then press the "Assign" button under the list of vertex groups. Note here that you can change the name of the bone (this will matter for exportation in 0 A.D.)
- STEP 8 Exit edit mode using the menu or by pressing Tab, then select the armature. Go into "Pose Mode" using the same menu. This will allow you to move the bone around and have the cube move with it while animating.
- STEP 9 Select the bone. Press G to move it around, and R to rotate it. When you have it in the position you want it in, left-click to set its location. To to move it or rotate it around only one axis, use this panel: to add the "widgets" to your 3D view that let you.
If you want to cancel the transform, right-click or press Esc. After setting its location, press I and select one of the options. The one I use is LocRotScale, which means it'll make a keyframe which includes the location change, the rotation change, and the scale change. 0 A.D. doesn't actually support scale, though.
- STEP 10 Use the left and right arrow keys to change which frame you're working on. When you've changed the frame to the one you want to add a keyframe, repeat step 9. You can tell which frame you're on by this number:
To play back your animation, press Alt+A. To change the length of the animation, go into the "Render" panel in the Properties panel and look at the Frame Range in the Dimensions section.
Exporting the animated Model into 0 A.D.
- STEP 1 To export your model into 0 A.D. and for it to load without issues, your armature needs to conform to a Skeleton file. Therefore, the first step will be finding a proper Skeleton file for your armature or, if there is none, to create a new one.
- STEP 1-A: using an existing skeleton Skeletons are defined in
binaries\data\mods\public\art\skeletons. Go there and open rowing_boat.xml (why? Because it's one of the smallest files).
You will notice two main blocks: one defined by
<standart_skeleton>and one by
<skeleton>. This is because there is a default skeleton and we can define subsets from that (this helps support different 3D softwares).
<skeletons> <standard_skeleton title="Rowing Boat" id="rowingboat"> <bone name="RowingBoatBone"> <bone name="RightRow"></bone> <bone name="LeftRow"></bone> </bone> </standard_skeleton> <skeleton title="Rowing Boat" target="rowingboat"> <identifier> <root>RowingBoat</root> </identifier> <bone name="RowingBoatBone"><target>RowingBoatBone</target> <bone name="RightRow"><target>RightRow</target></bone> <bone name="LeftRow"><target>LeftRow</target></bone> </bone> </skeleton> </skeletons>
As you can see, there are also
<bone>blocks, which are hierarchically defined in <standard_skeleton> (RowingBoatBone is the parent of RightRow and LeftRow ).
If you want to use this skeleton, you thus need an armature named "RowingBoat" (as per the "identifier" block) which has a main bone named RowingBoatBone (see step 7 above on how to rename bones), and two bones RightRow and LeftRow , both having RowingBoatBone as their parent (see step TODO). If such a scheme makes sense for your model (for example if you're making a new rowing boat), you can then use this skeleton by naming your bones appropriately.
- STEP 1-B: creating a new skeleton Since our model is a crate, it doesn't make sense to use any existing skeleton. Thus, we will create our own. For that, the first step will be to rename our object. In the top-right corner of Blender, you should see a list of objects in your scene, including one that looks like a little man (probably named Armature). Double-click on this one and rename it "CrateBox", as per here (the scene is different so there are other objects here).
Then copy one (whichever you like) of the files in binaries\data\mods\public\art\skeletons and name it "crateBox.xml". Then open this file in NotePad++. Erase everything and copy the following, then save the file:
<skeletons> <standard_skeleton title="CrateBox" id="cratebox"> <bone name="CrateBox"></bone> </standard_skeleton> <skeleton title="Rowing Boat" target="rowingboat"> <identifier> <root>CrateBox</root> </identifier> <bone name="CrateBox"><target>CrateBox</target></bone> </skeleton> </skeletons>
- STEP 2 : Now that our model and armature have been made usable in 0 A.D. (either by conforming to an existing skeleton or creating a new one), we will export the model. Right click on the crate so it's the only selected element, then go to File->export->collada.dae in the menubar.
- STEP 3 You can now choose where to save your files and what name to give it. This is not important for putting the model in 0 A.D., but it's generally good practice to follow the game's existing methods (usually a model is named civ_name where "civ" is the shortcut for the civilization's name (cf brit for britons) and where name is fairly descriptive). For exporting, you should use the following settings (the important part is here is that you can only export one model with its armature at most):
- STEP 4 You now have your crate box file saved somewhere. For the sake of simplicity, I recommend you first follow the guidelines in Basic3DImplementation, section "Actor File Setup". This means you need to put your .dae file in
Go to "crate_test.xml" in
binaries\data\mods\public\art\actors\props\special\eyecandyand change the code so it now looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <actor version="1"> <castshadow/> <group> <variant frequency="100" name="Base"> <animations> <animation file="mechanical/crate_animation.dae" name="Idle" speed="10"/> </animations> <mesh>props/wrld_crate_test.dae</mesh> <textures><texture file="props/crate_test.png" name="baseTex"/></textures> </variant> </group> </actor>
- STEP 5 Once you have saved the actor file with the changes, make a copy of your .dae file for the rigged crate and name it "crate_animation.dae". Move this file to
- STEP 6 At this point, you should have created 4 files: an actor file, a texture for your model, your rigged model, and your animation file. You can then launch 0 A.D., open the scenario editor, go to the object tab and you should be able to find your crate in the list (you need to select Actor(All) for this to work). If you place a few boxes, you should see them animated.
- Your model needs to be rigged with an armature using vertex groups.
- Your armature needs to follow the guidelines of a skeleton file in
binaries\data\mods\public\art\skeletons. You must name your bones accordingly if you use an existing one, or create a new one that will fit the scheme of your armature (note: as of now, I'm not sure if the hierarchical relations must be followed or not, I'd assume yes). Note that this also means you must name your "armature" object according to what is defined as the "Identifier" in the skeleton.
- You can only export one model and its armature at a time (see step 3 above). Your model needs to be exported with the animation if you want it to be animated, but the "native" animation it is exported with doesn't matter.
- You can only export one animation at a time. The animation itself is every key: setting a start frame and an end frame in Blender does nothing (note: apparently, needs checking).
- Your actor needs to have the proper definitions for all your animations.