Santos
6th Dec 10, 5:41 PM
Santos Tools 2 - Tutorial 3 - Exporting Animation
"Talk to the hand!"
In this tutorial I'm going to show, how to export a single animation for existing model.
Here's what you need:
Dawn of War II (:p)
Santos Tools 2 (http://forums.relicnews.com/showthread.php?244744)
3D Studio MAX 8-12
Havok Content Tools v5.5.0 or v6.6.0
Havok Content Tools are available for free via Try Havok (http://software.intel.com/sites/havok/) program. Currently versions 5.5.0 and 6.6.0 are supported. Other versions may be supported in the future.
Step 1: Convert animation to custom format
We start with exporting terminator's idle animation to Santos Tools 2 custom animation format, as scripts can't import HKX files directly. To do this, launch Model Editor and open terminator model. Go to Animations tab, right click melee_powerfist_range_pistol\fb_idle_stand_01 animation, click Export and select output directory. Program will export selected animation to a file with ANIM extension.
Step 2: Import model into MAX
Launch MAX, go to Utilities tab and select Santos Tools 2 from the drop down list. Expand Import rollout and turn on Save Scene under import options (you can also turn off marker import as we won't need them). To import model, click Import Model button, select terminator model file and output directory where reference file will be stored. When import is complete you should have reference file already loaded into MAX.
Step 3: Find out which bones are missing
Here's the tricky part. Havok animations are stored in HKX files. Every HKX file contains it's own skeleton. This skeleton may or may not differ from skeleton in main reference file. Usually it will have some extra bones for various weapons and accessories. In order to export animation properly we need to figure out which bones are missing and create a reference file with full skeleton.
The easiest way to do this, is to import terminator's idle animation with Quick Import button on Animations rollout. Quick Import will import animation into current scene (it assumes you already have reference file loaded). When import is complete open MAXScript Listener (F11) and look for warnings about missing bones:
"WARNING: Bone 'bip01 r powerfist hand' is missing!"
"WARNING: Bone 'bip01 r powerfist finger0' is missing!"
"WARNING: Bone 'bip01 r powerfist finger01' is missing!"
"WARNING: Bone 'bip01 r powerfist finger02' is missing!"
"WARNING: Bone 'bip01 r powerfist finger1' is missing!"
"WARNING: Bone 'bip01 r powerfist finger11' is missing!"
"WARNING: Bone 'bip01 r powerfist finger12' is missing!"
"WARNING: Bone 'bip01 r powerfist finger2' is missing!"
"WARNING: Bone 'bip01 r powerfist finger21' is missing!"
"WARNING: Bone 'bip01 r powerfist finger22' is missing!"
"WARNING: Bone 'bone_missile_launcher_casing' is missing!"
"WARNING: Bone 'bone_missile_launcher_missiles' is missing!"Step 4: Import missing bones
Now that we know which bones are missing, we need to import them into our reference file. The names of the bones should give some hint about their source. In our case these would be the following two models:
art\race_marine\troops_wargear\weapons_melee\terminator_powerfist\terminator_powerfist.model
art\race_marine\troops_wargear\weapons_ranged\missile_launcher_terminator\missile_launcher_terminator.model
Load reference file again, leave only Bones checked in import options, uncheck Reset Scene and make sure Merge is checked. Now import both models by clicking Import Model and selecting appropriate file. Imported bones will be merged into terminator skeleton so you will have full skeleton in the scene. Save the scene into melee_powerfist_range_pistol.max (name doesn't really matter but it's good to use names that make sense).
Step 5: Import meshes (optional)
Since we're going to animate this skeleton it would be nice to have some meshes for reference. Fortunately exporter will ignore anything that is not bone or animation, so we can import some wargear into the scene, for example:
troops_wargear\armour\terminator_armour_common\terminator_armour_common.model
troops_wargear\heads\terminator\terminator_head.model
troops_wargear\weapons_melee\terminator_powerfist\terminator_powerfist.model
troops_wargear\weapons_ranged\storm bolter\storm_bolter.model
Check Meshes, Materials and Bones import options before importing. When complete save entire scene.
Tip: You may notice that imported skeleton looks somewhat ugly with some bones being way to big. To fix this select these bones, set coordinate system to Local, go to Hierarchy tab and select Move/Rotate/Scale->Affect Object Only. Now you can scale the bones without distorting the mesh.Step 6: Import animation
Now we need to import terminator's idle animation again, this time by clicking Import Animation button. As Quick Import, this function assumes reference file is already loaded but it will save imported animation into MAX scene along with helper files containing list of rig bones and bone tracks. Load melee_powerfist_range_pistol.max before importing if it's not already opened. When asked to provide output directory you can select Animations created by the importer when importing model.
Step 7: Animate!
At this point we need to modify imported animation or create one from scratch. Note that importer sets a key for every bone in every frame, you may want to remove some of those when editing animation.
For the sake of this tutorial, I've made a silly animation with the classic Terminator 3 movie "Talk to the hand!" scene:
http://img140.imageshack.us/img140/1846/termieanim.gif
Step 8: Export animation
Ok, now we can finally export our new animation. There are two buttons in Export section of Animations rollout, that handle exporting single animation: Export Animation and Quick Export. The difference between the two is that Export Animation will launch Havok Content Tools dialog, where you can edit export settings and view export log. It is advised to use Export Animation button when exporting animation for the first time, as it allows to see if everything went right.
No matter which button you choose several thing will happen. Firstly you will be prompted to select output HKX file. Secondly script will create custom configuration file with settings that "work". This file will be deleted after export. Note that to export animation properly two additional files are required: RIG file that contains list of bones in the skeleton and TRACKS file which tells the exporter which bones are used in the animation. Since we're using imported animation, these files will be created for us by importer. You should be able to locate these files (fb_idle_stand_01.rig and fb_idle_stand_01.tracks) in the same directory as imported animation scene file. It is not necessary to modify them unless adding new bones.
Let's click Export Animation than and after that Run Configuration button in Havok Content Tools dialog. Make sure to check export log for any warnings or errors.
See Appendix A for more details about Havok Content Tools dialog.
Step 9: Convert animation
Dawn of War 2 uses Havok version 4.5.1. Havok is now available for free, however the lowest version available is 5.5.0, which naturally won't do any good as game will just refuse to load files with newer version. Havok is backwards compatible but it doesn't work the other way around.
Fortunately I was able to create a crude converter for Havok animations. Currently it supports only Havok version 6.6.0 but this may change in the future. To convert exported animation you don't have to do anything special, as conversion happens automatically when importing animation into Model Editor.
Note that if conversion fails, application is likely to crash. This is pretty unfortunate but I can't find the way to fix it at the moment.
Step 10: Replace animation in container
This is the final step of this tutorial. In order for the game to be able to load our new animation we need to replace existing fb_idle_stand_01 animation in model's animation container (terminator.hkanim).
Launch Model Editor again, load terminator model and go to Animations page. Right click melee_powerfist_range_pistol folder, choose Import from the context menu and select HKX file exported in step 8. If animation with the same name already exists in the container, as it is in this case, it will simply be replaced.
Last thing to do is to save entire animation container. To do this click Pack button on Animations page and save file as terminator.hkanim. Note that animation container is also saved automatically when saving entire model.
At this point your new animation should be working in game! :jump:
http://img84.imageshack.us/img84/4940/termieingame.png
Appendix A
When writing scripts I was trying to simplify the whole animation exporting process, however it might be good to understand what's going on behind the scenes. This section of the tutorial will explain the settings used for exporting animations.
When you use Export Animation button, Havok Content Tools dialog is launched. Now one thing to understand about files created by this tools, is that they can contain other things than animations as well (meshes, materials, physics etc.). So in order to get only the stuff we want, we need to create a set of Filters. After some trial and error I was able to create a set of Filters that exports animations properly:
http://img232.imageshack.us/img232/3299/filters.png
Note that these filters can be set up from configuration file. You can find the default configuration file called default.hko in Scripts\SantosTools2 folder inside your MAX root directory.
So, let's see what each of these does:
Transform Scene
This filter will transform contents of the scene from MAX coordinate system to DirectX coordinate system. First filter of this kind just sets transforms to identity. The second changes transformation matrix to this:
http://img213.imageshack.us/img213/9048/matrixphttp://img213.imageshack.us/img213/9048/matrixpn.png
Create Skeletons
Here we need to tell the exporter which bones to use as animation's skeleton. Usually all bones in the scene should be here, there are exceptions however.
When exporting animation with my script, this filter will use RIG file containing list of bones in the skeleton.
Create Animations
This filter is similar to previous one, except here we define which bones are used in animation. Usually the list will be the same as skeleton. For some special animations like aims, it might be just one or two bones.
When exporting animation with my script, this filter will use TRACKS file containing list of bone tracks.
Delta Compression
This filter compresses animation before export. The compression type here is Delta Compression which basically stores only changes between frames. I seem to be using the same settings here as in original animations, however if I reexport existing animation it usually ends up being around twice as large. I have no idea what Relic did here to get such small file sizes. Feel free to play around with these settings.
Prune Types
This filter will remove all meshes and other items (like camera, lights) from the scene, leaving only skeleton, animation and some environment data.
Write to Platform
The final filter will save the animation to HKX file.
"Talk to the hand!"
In this tutorial I'm going to show, how to export a single animation for existing model.
Here's what you need:
Dawn of War II (:p)
Santos Tools 2 (http://forums.relicnews.com/showthread.php?244744)
3D Studio MAX 8-12
Havok Content Tools v5.5.0 or v6.6.0
Havok Content Tools are available for free via Try Havok (http://software.intel.com/sites/havok/) program. Currently versions 5.5.0 and 6.6.0 are supported. Other versions may be supported in the future.
Step 1: Convert animation to custom format
We start with exporting terminator's idle animation to Santos Tools 2 custom animation format, as scripts can't import HKX files directly. To do this, launch Model Editor and open terminator model. Go to Animations tab, right click melee_powerfist_range_pistol\fb_idle_stand_01 animation, click Export and select output directory. Program will export selected animation to a file with ANIM extension.
Step 2: Import model into MAX
Launch MAX, go to Utilities tab and select Santos Tools 2 from the drop down list. Expand Import rollout and turn on Save Scene under import options (you can also turn off marker import as we won't need them). To import model, click Import Model button, select terminator model file and output directory where reference file will be stored. When import is complete you should have reference file already loaded into MAX.
Step 3: Find out which bones are missing
Here's the tricky part. Havok animations are stored in HKX files. Every HKX file contains it's own skeleton. This skeleton may or may not differ from skeleton in main reference file. Usually it will have some extra bones for various weapons and accessories. In order to export animation properly we need to figure out which bones are missing and create a reference file with full skeleton.
The easiest way to do this, is to import terminator's idle animation with Quick Import button on Animations rollout. Quick Import will import animation into current scene (it assumes you already have reference file loaded). When import is complete open MAXScript Listener (F11) and look for warnings about missing bones:
"WARNING: Bone 'bip01 r powerfist hand' is missing!"
"WARNING: Bone 'bip01 r powerfist finger0' is missing!"
"WARNING: Bone 'bip01 r powerfist finger01' is missing!"
"WARNING: Bone 'bip01 r powerfist finger02' is missing!"
"WARNING: Bone 'bip01 r powerfist finger1' is missing!"
"WARNING: Bone 'bip01 r powerfist finger11' is missing!"
"WARNING: Bone 'bip01 r powerfist finger12' is missing!"
"WARNING: Bone 'bip01 r powerfist finger2' is missing!"
"WARNING: Bone 'bip01 r powerfist finger21' is missing!"
"WARNING: Bone 'bip01 r powerfist finger22' is missing!"
"WARNING: Bone 'bone_missile_launcher_casing' is missing!"
"WARNING: Bone 'bone_missile_launcher_missiles' is missing!"Step 4: Import missing bones
Now that we know which bones are missing, we need to import them into our reference file. The names of the bones should give some hint about their source. In our case these would be the following two models:
art\race_marine\troops_wargear\weapons_melee\terminator_powerfist\terminator_powerfist.model
art\race_marine\troops_wargear\weapons_ranged\missile_launcher_terminator\missile_launcher_terminator.model
Load reference file again, leave only Bones checked in import options, uncheck Reset Scene and make sure Merge is checked. Now import both models by clicking Import Model and selecting appropriate file. Imported bones will be merged into terminator skeleton so you will have full skeleton in the scene. Save the scene into melee_powerfist_range_pistol.max (name doesn't really matter but it's good to use names that make sense).
Step 5: Import meshes (optional)
Since we're going to animate this skeleton it would be nice to have some meshes for reference. Fortunately exporter will ignore anything that is not bone or animation, so we can import some wargear into the scene, for example:
troops_wargear\armour\terminator_armour_common\terminator_armour_common.model
troops_wargear\heads\terminator\terminator_head.model
troops_wargear\weapons_melee\terminator_powerfist\terminator_powerfist.model
troops_wargear\weapons_ranged\storm bolter\storm_bolter.model
Check Meshes, Materials and Bones import options before importing. When complete save entire scene.
Tip: You may notice that imported skeleton looks somewhat ugly with some bones being way to big. To fix this select these bones, set coordinate system to Local, go to Hierarchy tab and select Move/Rotate/Scale->Affect Object Only. Now you can scale the bones without distorting the mesh.Step 6: Import animation
Now we need to import terminator's idle animation again, this time by clicking Import Animation button. As Quick Import, this function assumes reference file is already loaded but it will save imported animation into MAX scene along with helper files containing list of rig bones and bone tracks. Load melee_powerfist_range_pistol.max before importing if it's not already opened. When asked to provide output directory you can select Animations created by the importer when importing model.
Step 7: Animate!
At this point we need to modify imported animation or create one from scratch. Note that importer sets a key for every bone in every frame, you may want to remove some of those when editing animation.
For the sake of this tutorial, I've made a silly animation with the classic Terminator 3 movie "Talk to the hand!" scene:
http://img140.imageshack.us/img140/1846/termieanim.gif
Step 8: Export animation
Ok, now we can finally export our new animation. There are two buttons in Export section of Animations rollout, that handle exporting single animation: Export Animation and Quick Export. The difference between the two is that Export Animation will launch Havok Content Tools dialog, where you can edit export settings and view export log. It is advised to use Export Animation button when exporting animation for the first time, as it allows to see if everything went right.
No matter which button you choose several thing will happen. Firstly you will be prompted to select output HKX file. Secondly script will create custom configuration file with settings that "work". This file will be deleted after export. Note that to export animation properly two additional files are required: RIG file that contains list of bones in the skeleton and TRACKS file which tells the exporter which bones are used in the animation. Since we're using imported animation, these files will be created for us by importer. You should be able to locate these files (fb_idle_stand_01.rig and fb_idle_stand_01.tracks) in the same directory as imported animation scene file. It is not necessary to modify them unless adding new bones.
Let's click Export Animation than and after that Run Configuration button in Havok Content Tools dialog. Make sure to check export log for any warnings or errors.
See Appendix A for more details about Havok Content Tools dialog.
Step 9: Convert animation
Dawn of War 2 uses Havok version 4.5.1. Havok is now available for free, however the lowest version available is 5.5.0, which naturally won't do any good as game will just refuse to load files with newer version. Havok is backwards compatible but it doesn't work the other way around.
Fortunately I was able to create a crude converter for Havok animations. Currently it supports only Havok version 6.6.0 but this may change in the future. To convert exported animation you don't have to do anything special, as conversion happens automatically when importing animation into Model Editor.
Note that if conversion fails, application is likely to crash. This is pretty unfortunate but I can't find the way to fix it at the moment.
Step 10: Replace animation in container
This is the final step of this tutorial. In order for the game to be able to load our new animation we need to replace existing fb_idle_stand_01 animation in model's animation container (terminator.hkanim).
Launch Model Editor again, load terminator model and go to Animations page. Right click melee_powerfist_range_pistol folder, choose Import from the context menu and select HKX file exported in step 8. If animation with the same name already exists in the container, as it is in this case, it will simply be replaced.
Last thing to do is to save entire animation container. To do this click Pack button on Animations page and save file as terminator.hkanim. Note that animation container is also saved automatically when saving entire model.
At this point your new animation should be working in game! :jump:
http://img84.imageshack.us/img84/4940/termieingame.png
Appendix A
When writing scripts I was trying to simplify the whole animation exporting process, however it might be good to understand what's going on behind the scenes. This section of the tutorial will explain the settings used for exporting animations.
When you use Export Animation button, Havok Content Tools dialog is launched. Now one thing to understand about files created by this tools, is that they can contain other things than animations as well (meshes, materials, physics etc.). So in order to get only the stuff we want, we need to create a set of Filters. After some trial and error I was able to create a set of Filters that exports animations properly:
http://img232.imageshack.us/img232/3299/filters.png
Note that these filters can be set up from configuration file. You can find the default configuration file called default.hko in Scripts\SantosTools2 folder inside your MAX root directory.
So, let's see what each of these does:
Transform Scene
This filter will transform contents of the scene from MAX coordinate system to DirectX coordinate system. First filter of this kind just sets transforms to identity. The second changes transformation matrix to this:
http://img213.imageshack.us/img213/9048/matrixphttp://img213.imageshack.us/img213/9048/matrixpn.png
Create Skeletons
Here we need to tell the exporter which bones to use as animation's skeleton. Usually all bones in the scene should be here, there are exceptions however.
When exporting animation with my script, this filter will use RIG file containing list of bones in the skeleton.
Create Animations
This filter is similar to previous one, except here we define which bones are used in animation. Usually the list will be the same as skeleton. For some special animations like aims, it might be just one or two bones.
When exporting animation with my script, this filter will use TRACKS file containing list of bone tracks.
Delta Compression
This filter compresses animation before export. The compression type here is Delta Compression which basically stores only changes between frames. I seem to be using the same settings here as in original animations, however if I reexport existing animation it usually ends up being around twice as large. I have no idea what Relic did here to get such small file sizes. Feel free to play around with these settings.
Prune Types
This filter will remove all meshes and other items (like camera, lights) from the scene, leaving only skeleton, animation and some environment data.
Write to Platform
The final filter will save the animation to HKX file.