Table of Contents
- Rig setup
- 1 - Exporting the .DAE file with the mesh and armature
- 2 - Exporting the .DAE file animations
- 3 - Creating the XML file describing the skeleton
- Creating the actor file
This is a guide covering how to export and set up animation files from Blender3D into 0AD as well as some tips and general guidelines for get the animations working in 0 AD.
The guide assumes you're using a modern version of Blender (2.69 at the time of writing). It doesn't handle actual rigging or modeling, only exporting to 0 AD. It is easier to follow if you are used to Blender's dopesheet window.
Three types of files are needed for animations to work in 0 AD. These are:
- The "mesh and armature" file (COLLADA file).
- The file(s) with the different animations of the armature (COLLADA file(s))
- The XML file describing the armature (called skeleton in 0AD) with its bones names and hierarchy.
Once that is done, an actor XML file needs to be created to link the mesh with its animations, textures, etc.
Click to enlarge images.
Blender has many options and tools to make animation easier and improve the result automatically. However, much of that information is lost when exporting to COLLADA. Here are guidelines to keep in mind when configuring your rig to make animations for 0AD:
Use only one object and one armature.
A limitation of the game's engine is that COLLADA files with more than one mesh object will not load. It is recommended you work on only one object and its armature (you can use "only selected" when exporting, but this makes things easier). Note that this means that if you want prop points, they must be bones. Only non-rigged meshes can use empties.
Use "vertex groups" and not envelopes.
Avoid disabling "inherit rotation" in bones.
While it's a very nice blender feature, when exporting your animation the bones that have their inherit rotation checkbox disabled end up inheriting their parent's rotation, plus the extra rotation you add in the animation resulting in weird and undesired behaviors. There's a tricky workaround for this, which is creating a helper bone which the bone that you don't want to rotate will copy its rotation.
Make sure the rig have the correct scale, and has its scale applied before start animating.
Resizing your rig and/or mesh and applying its new scale before baking the animation may end up messing the animations you may already have, specially if you have any IK (Inverse Kinematics) setup in your rig. I recommend you avoid any scaling of the objects. If you have to scale, scale in edit mode. However, here's a workaround that may or may not work:
- Scale to the correct size the mesh+armature file and re-export it.
- Export the baked animation(s) to dae with their incorrect size, but correct animation.
- Import them back into blender, scale them correctly, and export them back without applying the scale one by one.
Export only baked animations with "Clear Constraints" or sampled animations.
Many constraints (IK constraints, bone constraints) are not exported to COLLADA. This means that your animation could look fine in Blender, but will be broken in-game. To avoid this, either sample your keyframes (add a keyframe to every frame) using shift-o in the dopeSheet editor, or bake your animations using "Clear Constraints".
Save your .blend file before exporting.
You will lose your rig constraints when baking the animation, and importing COLLADA back into blender loses information and is often broken. Because of this, if you want to tweak an animation, or use the same skeleton/rig to create a new one, the only way to do it right now is using the .blend file.
In this guide, we're going to set up the animations for a wild animal unit "Tiger" that will be controlled by the IA "Gaia".
1 - Exporting the .DAE file with the mesh and armature
In this step, we're going to use Blender3D to create the main file needed for the unit's animation.
This file tells the engine the relationship between the bones and the mesh. You will need a rigged mesh.
Before exporting the mesh and the armature, you should make sure that both objects are centered in the origin point of the scene and both object's origin points locations match. To move the object's origin points to the scene origin point (coordinates 0,0,0) first use "SHIFT+C" this will make your 3D cursor to center into the scene origin, then select the mesh and the skeleton with rightclick and shift rightclick and use "CTRL+ALT+SHIFT+C", in the pop-up menu select "Origin to 3D cursor".
Now make sure your skeleton is not using any action in the Action Editor (in Blender's dopesheet window) and move the timeline back to the first frame if it isn't there.
Also make sure your skeleton is in the default pose (also called resting pose). To do this, select the skeleton, use "CTRL+TAB" to enter pose mode, hit "A" to select all bones and use "ALT+G", "ALT+R" and "ALT+S" to reset the bone's position, rotation and scale, this will put the armature in it's resting pose.
Now we're ready to export the mesh and skeleton. In "Object Mode" select the mesh first with rightclick and then the armature with "shift+rightclick" (the order is important as the object needs to be highlighted, in light orange and not dark orange) then go to the menu in the top of the screen and use "File --> export -- > Collada (Default) (.dae)".
Navigate to the folder where you want the file to be created, name the file, and change the export settings so that they look like the screenshot below. You can use "Apply modifiers" safely as long as it doesn't apply the armature modifier, and you can use "Include Children" if you are using prop points.
Note: These "mesh+armature" files are stored in binaries/data/mods/public/art/meshes. There are subfolders, pick the most appropriate one.
2 - Exporting the .DAE file animations
In Blender3D, you have to use the "action editor" to create the different actions (or animations) that you want to export into 0AD to use them. These actions are usually: walk, run, idle, attack, and death, but you can make variations of each one or make more types of actions if desired (check existing actor files to know which). While this tutorial does not cover how to animate in Blender3D, there are links to existing tutorials at the bottom of this page.
2.1 - Baking the action to keyframes or sampling the keyframes.
Blender3D interpolates between keyframes. This behavior is not kept automatically when exporting to COLLADA, so you need to tell Blender how to properly export your animation. There are two ways to do this, one is baking animations, the other is sampling the animation. Baking creates keyframes only for bones that are actually animated. Sampling creates them for all bones.
The first step is selecting the action to bake in the action editor, and adjusting the "start frame" and "end frame" on the timeline to match the action's length.
To bake an action into keyframes, select the skeleton, enter in pose mode with "CTRL+TAB" and select all bones with "A". Once you have selected all bones, move the mouse cursor into the 3D viewport, hit "space" to bring the search option menu and type "bake action" then select "Bake Action" in the menu. A menu for the "Bake Action" option will emerge, uncheck "Only Selected" checkbox, !and check "Clear Constraints" checkbox (specially if you use IK and/or constraints) and click OK.
To sample the keyframes, simply select the keyframes you want to sample and go to "Key->Sample Keyframes" or use Shift-O. Blender will add smaller blue keyframes.
2.2- Exporting the animation .DAE file
This uses the same process as in point 1 above. Make sure you have only selected your mesh and its armature before exporting.
Repeat 2.1 and 2.2 for each animation of the unit and name them accordingly. A general convention in game is that animations are named "mesh_animationType.dae", but you are free not to follow it.
Animation files are stored in \0AD\binaries\data\mods\public\art\animation\ (there are subfolders, pick the most appropriate one)
Animation files in-game are independent from the mesh with which they are exported. This means that any two units that have the same skeleton can use the same animation. Note that this doesn't account for potential scale issues, since it is possible to have units with the same skeleton (bone hierarchy…) and different sizes.
3 - Creating the XML file describing the skeleton
0 AD needs a .XML file that describes the Blender armature, called a skeleton file. They are located in binaries/data/mods/public/art/skeletons.
The easiest way to set up one is to open an existing file and modify it with the information of the new skeleton you want to add and save it as a new file. You can open .XML files with any text editor software.
The easiest way to know your armature's hierarchy is to open the outliner window in Blender and expand the armature's content. Using a simpler shark example, this is what you would get:
You only need to defines bones that directly influence vertices. In the shark's case, the "Main", "Tail_ik" and "Head_ik" bones only affect other bone's positions, so you don't have to describe them.
Each child bone is defined inside the parent bone's balises (under its parent bone line before closing the parent's bone definition with "</bone>").
The "<identifier>" is the name of the armature in Blender.
If you have any bone name in the skeleton containing a dot "." or a space you have to use an underscore "_" in this file instead when writing the bone's name.
Skeletons files can appear to have redundant definition. This is because this architecture can be used to support models coming from different 3D rendering softwares with different names.
Once you have completed setting up the file, use "save as" and save the .xml file with an appropriate name in the folder specified at the beginning of this section.
Creating the actor file
Every unit (or entity) in 0 AD has it's own .XML file containing information that the engine can read. These files are called actors.
Some properties that contains these actor files are:
- Mesh: the mesh that will be displayed in the engine for that entity or unit.
- Prop(s): Actors can be used within other actors. They're called props. You need an "empty" object, or a helper bone with its name starting with "prop-" to specify where you want the actor to be shown in your main COLLADA file. "root" always exist and refers to the main object's center position.
- Variants : These are possible variants of a unit (used for unit diversity) as well as states that a unit may have.
- Texture(s): The texture or textures that the mesh will use.
- Animation(s): Animations that the unit or entity can use and the variant/state associated with that animation.
Animations in the actor files are normally specified just before the <mesh> tag in the following format:
The <animation> tags in this example include the location and filename of the animation (created in section 2), the name of the variant/state that will use that animation specified by "name=", and the speed at which the animation will play (see AnimationSync for more information as this value is not that trivial to understand).
Loading and hiding props during an animation
There are cases when you might want a prop to appear in the middle of an animation and not at the start (an archer's arrow…). To do this, you need to add a "load=X" parameter. X takes values between "0" (start of the animation) and "1" (end of the animation). Setting Load="0.5" means that at the middle of your animation, this prop will appear. Using "event=X" makes the prop disappear and works similarly. You will need to name your prop attachpoint "loaded-NAME".
You need specific variants for this to work. The "attack_ranged" variant below uses this example.
In this example the actor "arrow_back.xml" is going to be loaded at 16% of the duration of the build animation, and it will disappear at 84%. You specify where the prop actor will be placed with "attachpoint=" . The attachpoint value needs to be the name of a bone/empty object, whose name (in Blender) will be "prop-NAME".
Static meshes without skeleton should use empties parented to the mesh with the name prefix of "prop-". You can later use this empty location to spawn an actor on it's place when defining the props between the <prop> tags right after the <mesh> definition in the actor file. The props will inherit the empties rotation and position, but not scale.