Tuesday, 30 November 2010

Blender 2.5 to XNA 4 animated FBX models

The following post is out of date because as from Blender 2.56 the scripts mentioned are all shipped with Blender. See the following post for more up to date information:
http://blog.diabolicalgame.co.uk/2011/07/exporting-animated-models-from-blender.html


==


Following on from my previous post on this subject I have managed to create an FBX exporter script for Blender 2.55 Beta that works with keyframe animations and imports in to XNA 4.0.

Due to the limitations with the Autodesk FBX importer that ships with XNA 4.0 the animations need to be loaded individually from separate FBX files but there are simple solutions available to work with that.  Details and other links are in the Instructions with each of the following projects:

The package with several XNA FBX exporters for Blender 2.5 can be downloaded from:
http://code.google.com/p/blender-to-xna/
The most recent instructions are on the Blender Wiki:
http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/File_I-O/Blender-toXNA

An XNA model viewer that has an option to load FBX files as separate animations:
https://code.google.com/p/take-extractor/

The XNA TakeExtractor project also demonstrates how to rotate models and their animations within the pipeline.  That is useful for adjusting Blender models which face Z up to XNA's default which is Y up.  Use a rotation while loading of X = 90, Y = 0, Z = 180.   I think that ends up facing backwards because that is how my entire game appears to work and there is too much code for me to bother to change it!

Friday, 26 November 2010

Blender 2.5 to XNA 4 animated model pipeline

See the future linked post for more up to date information:
http://blog.diabolicalgame.co.uk/2011/07/exporting-animated-models-from-blender.html

The following is a bit out of date. If you want to know how to get models from Blender to XNA read the above linked post not this one.

==

It's been a while since I posted because I have been struggling with a problem since I finished the conversion to XNA 4.

As mentioned in my previous post, animated models from Blender would no longer display properly in XNA.  If I had imported the animation in XNA 3.1 they would still work in 4.0 but when I tried to save new animations from the models using XNA 4, the animations were distorted.

I tried fixing the FBX exporter from Blender but the FBX file format is not documented making it difficult.  To cut a long story short I have ended up with a solution that uses separate files for the animations.

The model, bones and bind pose are loaded in to XNA using FBX.  Each animation is exported from Blender as a list of bone transform matrices.  Those can then be imported in to XNA and converted to the AnimationClip format used by the Microsoft Skinning Sample.  Edit:  I now have FBX working see my next post.

The process takes a few steps but works with the models I have been using.  It needs more testing with other models.


The package with several exporters for Blender 2.5 can be downloaded from:
http://code.google.com/p/blender-to-xna/
The most recent instructions are on the Blender Wiki:
http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/File_I-O/Blender-toXNA

The XNA sample and model viewer demonstrating how to import the animations can be downloaded from:
https://code.google.com/p/take-extractor/

Both are on Google Code, if the links do not initially work, wait an hour and try again.  Google appear to have frequent outages but none so far have lasted longer than an hour.
There are still several limitations with the pipeline some are the same limitations as with earlier versions of XNA and Blender:

- All parts (Blender Objects) of a model must have the same centre (Origin, ideally at Zero)
- All parts of the model must have a scale of 1.0
- Every vertex must be weight painted or added to the bone vertex group for animation.
- The model has to be loaded in XNA before the animations can be converted to AnimationClip format.

At the moment the animations cannot be rotated in the content pipeline! [Fixed, see future posts]  My next job is to work out the maths to rotate the animations as they are imported.

==

Please make sure you read my future posts. I have done a lot more work to get it all working properly.

Monday, 15 November 2010

Dude for Blender

I have converted the Dude from the Microsoft XNA Skinning Sample in to Blender format. The transfer is not ideal but is enough to provide a starting point.


Dude in Blender
I have added an armature (bones) for animation and a test action called 'Walk'. This is for my own purposes but may be useful to others. It gives an idea of scale and a suitable mesh quality for use in games. Please note that my test animation is very poor.

Download Model

Dude for Blender (9.5Mb) March 2009 (Imperial scale)
Test Dude Animations (8.5Mb) November 2010 (Metric scale)