= Basic Animation Exporting = [[TOC]] In this tutorial we are going to animate the crate/box object created in the previous [http://trac.wildfiregames.com/wiki/Basic3DImplementation 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.[[BR]](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.[[BR]]With that in mind, let's start. == 3D Animation == * '''STEP 1''' Open Blender, and open your file from the [[Basic3DImplementation]] tutorial. [[Image(http://i.imgur.com/cI4zu.png)]] * '''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) [[Image(http://i.imgur.com/8NEl9.png)]] * '''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. [[Image(http://i.imgur.com/DWqrv.png)]] * '''STEP 4''' Select "Object Data" in the tab bar on the Properties panel. [[Image(http://i.imgur.com/FOyUC.png)]] * '''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. [[Image(http://i.imgur.com/w7xVK.png)]] [[Image(http://i.imgur.com/b2HnP.png)]] * '''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.) [[Image(http://i.imgur.com/2kcr8.png)]] * '''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. [[Image(http://i.imgur.com/7VpDq.png)]] * '''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.) [[Image(http://i.imgur.com/aCqKh.png)]] [[Image(http://i.imgur.com/cDbq4.png)]] * '''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. [[Image(http://i.imgur.com/HqHs3.png)]] * '''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: [[Image(http://i.imgur.com/6p1Pj.png)]] 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. [[Image(http://i.imgur.com/T7eqN.png)]] [[Image(http://i.imgur.com/XkDI2.png)]] * '''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: [[Image(http://i.imgur.com/G5pdr.png)]] 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. [[Image(http://i.imgur.com/SNOas.png)]] [[Image(http://i.imgur.com/jirAX.png)]] == 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).[[BR]]You will notice two main blocks: one defined by `` and one by ``. This is because there is a default skeleton and we can define subsets from that (this helps support different 3D softwares). {{{ #!xml RowingBoat RowingBoatBone RightRow LeftRow }}} As you can see, there are also `` blocks, which are hierarchically defined in (RowingBoatBone is the parent of RightRow and LeftRow ).[[BR]] 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.[[BR]] * '''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). [[Image(http://i.imgur.com/zeaLw5L.png)]] [[BR]] 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: {{{ #!xml CrateBox CrateBox }}} * '''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. [[Image(http://i.imgur.com/VbBJeZI.jpg)]] [[BR]] * '''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): [[Image(http://i.imgur.com/nERDoNY.png)]] [[BR]] * '''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 `art\meshes\props\`.[[BR]]Go to "crate_test.xml" in `binaries\data\mods\public\art\actors\props\special\eyecandy` and change the code so it now looks like this: {{{ #!xml props/wrld_crate_test.dae }}} * '''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 `art\animation\mechanical.` * '''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. [[Image(http://i.imgur.com/QVJLMyM.png)]] [[BR]] = Short summary = * 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.