OGRE maxscripts

## 3dsmax skeleton and mesh export

Here are 3dsmax4/5 scripts which export meshes and skeletons.

### Tutorials

- you can find a mesh tutorial here.
- you can find a skeleton tutorial here.

### XMLConverter (OgreXMLConverter)

3ds scripts write .xml files. So, in order to have .mesh and .skeleton files, XMLConverter.exe should be used. It's in Tools/XMLConverter/bin/debug directory.

#### Issues

XMLConverter doesn't find the skeleton file when you try to convert your mesh file even if it has been created. So there is an eror message, but don't care: it works well when an OGRE application uses it.

### Scripts Features

- exports meshes.
- exports bones, vertex assignements and bones animation, using the skin modifier.
- deals with Physique modifier and Biped.
- exports multi-sub object and Standard materials.

### How to use the script

- Exporting Meshes:
  - You can choose to export colour information and/or texture information.
    CAUTION: Colour information is not complete. This information is not used during rendering and values exported are just RGBA (25500255 = 255 0 0 255)
  - You are able to export meshes which are made up of several submeshes. Behaviour is unknown if different submeshes are linked to a skeleton (it has not been tested but should works).
- Exporting skeletons:
  - There is sometimes a problem with mapping. Try to had a UVW map modifier.
  - CAUTION: Always create new bones as children of another AND don't unlink and re-link a bone. For example, if you have created a leg, copy all the bones and then use position controller in a track view to move it and so get the other leg.
  - AND : Don't use mirror when you create your bones because results are strange.
  - Biped If you move or rotate the biped rootObject during your animation, add keys to the pelvis too at the same frames
- Exporting materials:
  - Only Multi-Sub Object materials can be exported.
  - Press the pick button, choose your material (for example from mtlEditor section), and choose "Instance" in order to avoid garabages.

### Troubleshooting

[Thanks to gfactor for these tips]

1. If the XML converter complains about missing bones, then the bones probably do not have any vertices assiged to it, and the converter 'optimises' it by simply not exporting them. So make sure all bones have at least one vertex weight.
2. If the XML converter complains about Bip01 missing, then you will probably need to convert your Physiqued biped to a Skinned biped. Don't ask me why but once we did this our models exported without problems. The really weird thing is that one of our models exported fine about 2 months ago (physiqued) but then failed to work again until we converted it to skinnned... weird. The good news is that there is a max plugin that does this, which can be found at http://sparks.discreet.com/downloads/
3. If you have a mesh with multiple animations, all the animations MUST be based on the same pose because all Ogre does when animating is rotate the bones based on the binding pose (does not store positions). The easiest way we've managed to do this is to simply export say... an idle animation as our first animation (using that pose as the base skeleton file), then for each additional animation we import frame 0 of Idle into max and start animating our actual animation from frame 1 onwards. When you export the animation.... export from frame 1 onwards (do not export frame 0). This ensures that all animations will be rotated from the same reference pose. Then simply edit the XML files and cut / paste all additional animations into the idle.skeleton file
4. Animations can do weird things unless you flatten the footsteps (creating a key frame for every frame)
5. If the XML converter says that it cannot find the *.skeleton file you are trying to convert (despite well.... the skeleton file being there) then the XML file is corrupt. One of our programmers looked through the XML file and found multiple <animations> tags (note: not <animation>) which of course is bad.
6. If you get a weird error that actually breaks in the comments of the Max Script when exporting...

       " Type error: Call needs function or class, got: undefined "

   then the object you are exporting (the body...not the bones) has spaces in its name. For example.... enemy_NPC will export... but enemy NPC will cause the above error. As far as I can tell... bone names with spaces are fine... but the actual mesh must NOT have spaces in it.

If you want to know a little more about how scripts have been written...