Exporting animated models from 3ds Max
Diagram 1-1
Prepping to Export
Before exporting a model, some quality checks should be made to ensure fewer problems with the geometry.
It is important to note that we work in centimeters, therefore creating or scaling objects to scale in cm is the best way to get a properly scaled end result. Object transforms should be reset before exporting as well; you will want to have all your objects at 100% of XYZ scale.
Placing the objects pivot point at (0,0,0) is a good idea, as well as assuming that the pivot point will be the center point of contact with the game world. In this example of the windmill, I have placed the pivot at the center, bottom of the model and reset all the transforms.
Exporting models that contain multiple objects is fine (just as the windmill does), however if you experience problems with sub-objects not being where they should be, you should check the individual object transforms, as this is often the cause of the problem.
Materials
Multi-sub materials work fine, but each surface should be explicitly defined in its name box as shown. In this example the full name for some of the materials is not visible without scrolling.
Diagram 1-2
Note that a model may not have more than 24 sub-materials.
This particular example model has eleven sub-materials; this is an uncommon occurrence, as it is common that a model have only a few sub-materials. While it is not necessary for the name field to be the same name as the sub-object field, it is often helpful, as is naming the name and sub-object field to be the same as the shader that has been defined in engine. The name field is used during the export process, and ultimately is what the model’s surfaces are defined as.
Note that a single material may not have more than 1000 texture vertices assigned to it.
An example of this rule is a model of something large and detailed like a train engine. The train engine may have a single monolithic texture map that is laid out for skinning the entire model, but the model itself is 2500 polys. With this high poly count it is likely the train’s texture UVs exceed 1000, and therefore the material definition must be broken up into separate materials for the sole purpose of properly compiling the model.
Ultimately what this means is you would need to select half of the surfaces of the train and assign them to material ID 1, then select the remaining train surfaces and assign them to material ID 2. You would then need to create two materials that basically point to the same texture, but have their own unique sub-material name. So if material ID 1 points to train_skin_1 (which ultimately points to the texture train1.tga), then material ID 2 should point to train_skin_2 (which also points to the texture train1.tga). Depending upon the complexity of the model, and the potential surfaces a single texture needs to cover, you may have to create several ‘aliases’ for the same texture. Later in the shader definition of the tiki file, you can point these two surfaces to the same shader, there is no need for multiple versions of the same shader ingame.
Exporting
The file skelout.dle should be placed in your /3dsmax42/Plugins folder. If Max is open, you’ll need to shut it down and restart. When the plugin is installed, open the model you wish to export. Go to File|Export and you will be presented with a dialog that looks like this:
Diagram 1-3
Choose the MOHTA Skeleton export as shown above, and just type in the name of the file you wish to export. In this example, I am exporting windmill.skl.
After typing in a filename and hitting enter, you will see this dialog:
Diagram 1-4
It’s simple, Start defines the starting frame, and Stop defines the ending frame. Frame rate and Sample rate can be adjusted but it’s unnecessary in most cases, so leave them at 30 for most instances. After hitting OK the file will be exported to the location you specified. This file is an ASCII file that can be adjusted by hand if need be. It is often convenient to adjust material names in the .SKL file if they aren’t properly defined within Max.
Before this asset is game ready we will need to compile the ASCII file to a Binary with the included tool skl_2_skx.exe. I’ve included a batch file that will process a baseframe and an animation.
rem ===Compile Baseframe===
skl_2_skx windmill -baseframe -nolod
rem ===Compile Animations===
skl_2_skx windmill_still
skl_2_skx windmill_turn
There are many arguments for the skl_2_skx tool, but to have a functioning model you must create a baseframe for it. The baseframe contains Geometry, UV and Material information. It is important that you always re-export and recompile your baseframe when your model changes structurally (updated UVs, changed Material ID’s, updated geometry).
The first command line will create a compiled binary named windmill.skd the second and third command lines (without any arguments) are setup for creating animations. In this example the files windmill_still.skc and windmill_turn.skc will be generated.
Tiki Files
Continuing with the windmill example, we have the following tiki file. Each line is commented to indicate its necessity.
//token to identify the file as a TIKI
TIKI
//setup section of the tiki, where scale, baseframe,
//path and materials are setup
Setup
{
//everything in the game world should be scaled to
//0.54 for the cm conversion
scale 0.54
//path that points to where the models data files are located
path models/animate/windmill
//skelmodel allows you to specify what file is the model //baseframe
skelmodel windmill.skd
//surface definintion (defined in max’s material setup)
//and which shader the game should use for that surface
surface wm_thatch_1 shader wm_thatch_1
surface wm_shadow_1 shader wm_shadow_1
surface wm_wind_blade shader wm_wind_blade
surface wm_Wood_Beam_1 shader wm_Wood_Beam_1
surface wm_brick_3_bot shader wm_brick_3_bot
surface wm_door_wood_2_bot shader wm_door_wood_2_bot
surface wm_door_wood_2_top shader wm_door_wood_2_top
surface wm_window_old shader wm_window_old
surface wm_windmill_sail shader wm_windmill_sail
surface wm_side1 shader wm_side1
surface wm_wind shader wm_wind
}
//init section is not needed for this particular tiki, but is usually used to //define such things as particle systems that are used with this model
init
{
}
//Animation Section
//NOTE! You absolutely must have an idle animation or the tiki will not //work in game. Even if the animation is a single frame animation that //appears to do nothing.
//Animations are named with aliases, then we point to the file that //contains the actual animation. You can create several aliases that //point to the same animation file if necessary.
//The client section I have within the ‘turn’ animation has sound //attached to it that will play on the animation’s 230th frame. There are //other valid commands that you can setup for use within the client //section of an animation. There are also other options for controlling //when the event occurs such as replacing the explicit frame 230 with a //command like ‘first’, ‘last’, ‘entry’, or any other valid frame number. //Refer to the client command list and tiki documentation for more //information.
animations
{
idle windmill_still.skc
turn windmill_turn.skc
{
client
{
230 sound safe_open
}
}
}
It should be noted that the normal file structure for a tiki file is that the .TIK file resides in a directory above the directory that contains the data. For example, our windmill.tik file should reside in:
/models/animate
Whereas our actual data files (.skd, and .skc) for the model should reside in:
/models/animate/windmill
Seeing it ingame
After prepping, exporting, compiling, and setting up your tiki, textures and shaders you should be ready to view your model ingame. Load up the game with the command line arguments:
Moh_spearhead.exe +set cheats 1 +set developer 1 +set thereisnomonkey 1
Choose any level you see fit for viewing the model, and then pull down the console (tilde key), type in the command pushmenu animate2. The following dialog will be produced:
Diagram 1-5
Click the spawn button in this dialog and browse to your newly created tiki file. Your model should appear in game. You can then click the PrevAnim and NextAnim buttons to view the animations that have been set up in the tiki.
If the model is textured in gray, or with weird colors, you probably have a mismatch in your surface definitions, your shader setup, or your texture files just can’t be found. Check the surface definition throughout your chain of files to verify things are as they should be.