Extensions:2.6/Py/Scripts/Import-Export/Blender-toXNA

提供: wiki
移動先: 案内検索
Blender to XNA
Export animated FBX models to XNA 4
UI location Export
Usage Export animated models in Autodesk FBX format files for use with XNA
Version 1.1 Author(s) John C Brown (JCBDigger) @MistyManor plus others
Blender shipped with 2.56 to 2.58 from 2.59 onwards the official FBX exporter supports XNA License GNU General Public License (GPL)


Executable information
File name io_export_anim_mesh_xna
Current version download None. The current version is included with the Blender distribution. Versions 2.56 to 2.58 include a Blender To XNA addin on the user preferences menu. From 2.59 onwards the official FBX exporter supports XNA.


Links http://blog.diabolicalgame.co.uk/2011/07/before-animating-with-blender.html

http://www.mistymanor.co.uk/

Release Log Dev:2.5/Py/Scripts/File_I-O/Blender-toXNA



Blender 2.5 to XNA 4

From Blender version 2.59 the official FBX exporter supports exporting to XNA.

See the new wiki page: Extensions:2.5/Py/Scripts/Import-Export/Autodesk_FBX


Previous Version Addon

For versions 2.56 to 2.58 of Blender a separate addon shipped with the distribution. That addon was required to be enabled to export Autodesk FBX files in a format suitable for Microsoft XNA 4.0

To enable the scripts that ship with the older versions of Blender go to the File->User Preferences menu. Select the 'Addons' tab, find the script from the list and enable it by puting a tick (check) in the small box.

If you wanted that to start every time you started Blender you needed to press 'Save Default'. If you have a model file open that also gets saved as part of the default!

The scripts were export scripts and were available on the File -> Export menu.

Summary

The Autodesk FBX importer included with XNA 4.0 has a slightly stricter requirement for the file format compared to the previous version and introduced the limitation that only one animation can be loaded from each FBX file.

These exporter scripts output in the correct format and let you export the currently selected action as the animation take in the FBX file. That lets you save individual files for each animation.

Typical usage:

  • Export the Model Only as an FBX.
  • Export each Blender action as an FBX animation in to separate files.
  • Load the model in to XNA and merge the animations. See Shawn Hargreaves blog on how to merge animations or use my 3D Model Prep model viewer for testing.

Instructions

If the scripts are installed and enabled you will have 3 new menu items on the Export menu in Blender. XNA FBX Model only, XNA FBX Animations only and XNA FBX Animated Model.

The XNA FBX Model only exports the model with armature (if present) but only in the rest pose. No animations. This produces the smallest file size compatible with being animated in XNA.

The XNA FBX Animations only option can be used to export each animation one at a time. In pose mode in Blender select whichever action you want to export. Then select the Export -> XNA FBX Animations only from the menu and save that selected action. Repeat selecting an action and exporting it for each animation you want to use in XNA. This option produces a much smaller FBX file size because it does not contain any of the model data.

The XNA FBX Animated Model option produces a complete FBX file with the model meshes and the animation take(s) all in one file.

Limitations

For models and animations to work when imported in to XNA they must be created a particular way:

  • All the model objects (meshes) and the armature must be centred at the same location, ideally zero (X = 0.0, Y = 0.0, Z = 0.0 in the Object properties.) Set the locations to zero in Object mode and make all changes in EDIT mode.
  • All the model objects must have a scale of 1.0 (one.) Set all the scales to 1.0 in Object mode then do all changes in EDIT mode.
  • The model objects must not use rotation. Set all the rotations to 0.0 in Object mode then do all changes in EDIT mode.
  • Every vertex must be weight painted or added manually to a bone vertex group. Any loan vertex will cause an error when importing in to XNA. To check you have bone weights for all vertices pull the model about in POSE mode. Any un-weighted points will be left behind when posing the armature.
  • The XNA model class only supports UV wrapped textures. Blender's shading only work in Blender not in XNA.
  • The FBX exporters only support keyframe animations from Blender Actions and will not work with Blender's curves.
  • In XNA set the 'Content Processor' for the FBX model. If you want to use animations this must be the 'SkinnedModelProcessor' or whatever your processor name is - this is the most common oversight.

There is no need to apply the armature modifier before exporting. Some people say you must not apply the modifier but I have not had that problem. The armature modifier is required within Blender to be able to create animations but is not required for the export.

XNA Resources

Within your XNA game code content pipeline you will need to use a Skinned model processor either from a Microsoft sample or your own. You will need a way to merge or add individual animations to your animation player. The following demonstrate several methods:

Shawn Hargreaves blog on how to merge animations in XNA: http://blogs.msdn.com/b/shawnhar/archive/2010/06/18/merging-animation-files.aspx

3D Model Preparation project which lets you load a model and then load individual animations from FBX files: http://code.google.com/p/3d-model-prep/ The code and download section also includes some XNA classes which help rotate models and animations while they are being processed by the XNA pipeline and to import FBX files with multiple takes.

There are some additional details about setting up models for use with this exporter in my blog: http://blog.diabolicalgame.co.uk/2011/07/before-animating-with-blender.html

There is a discussion thread for this exporter on the XNA forums: http://forums.create.msdn.com/forums/p/68149/427961.aspx

History

XNA is the development framework Microsoft has created for independent and hobby developers to use for games. It is based on Microsoft .Net and C#.

Autodesk FBX is one of the file formats supported as standard for import in to the XNA framework.

Previous versions of Blender had a modified FBX exporter for them to be compatible with XNA. Changes to both Blender and XNA have made those versions no longer compatible. These scripts are variations based on that previous work and I would like to thank everyone who has contributed.

Acknowledgements
  • Convert 2.5x to XNA 4: John C Brown (JCBDigger) @MistyManor
  • Convert 2.4x to XNA 3: Fritz@triplebgames.com
  • Original FBX exporter: Campbell Barton (ideasman42)


Work In Progress

Unify the XNA FBX exporter with the original so that only one script has to be supported:


Installation of Updates

If you are not using the bundled script see the following for where and how to install scripts.