Extensions:2.6/Py/Scripts/Import-Export/DirectX Exporter

提供: wiki
移動先: 案内検索
DirectX Exporter (.x)
Exports the current scene to the DirectX model format (.x)
UI location File > Export > DirectX (.x)
Version 3.1.0 Author(s) Chris Foster
Blender 2.77a License GPL

Executable information
File name __init__.py, export_x.py
Python modules io_scene_x
External Python Modules or dependencies math, os

Links https://projects.blender.org/tracker/index.php?func=detail&aid=22795


I started this project for Blender 2.49 with the intention of replacing the DirectX exporter that was shipped with Blender 2.4x because, as any Blender 2.4x user who's tried to get their models out of Blender 2.4x and into DirectX apps knows, it is very difficult to get working and often doesn't work at all. I hope this is a project the community will find useful.

After completing version 1.0 of my exporter for 2.49, I successfully ported the script into Python 3.1 using Blender 2.5's new API. All of the old functionality has been ported, and there's still more to come!

The script has come a long way, from being a tool I started out of necessity, to finding a place in the final release of Blender. I must say that I'm proud of my work and I hope that with your feedback, I can maintain its quality.

If you would like to find the old version of this script for Blender 2.49, follow the link at the bottom of this page. Maybe it can still be useful to some people.



To use, first enable the Add-On from the Add-Ons tab in the User Preferences window. Select File > Export > DirectX (.x) to start the exporter. From there, check the options you wish to use for export, choose a file path, and then click Export DirectX.

Here is a brief description of the options:

  • Export Selected Objects Only - If unchecked, all supported objects in the scene will be exported.
  • Coordinate System - The coordinate system used for export. This setting along with the Up Axis setting will define the target coordinate space. DirectX natively uses a left-handed system with Y axis up, but some engines that use DirectX may use a different system.
    • Left-Handed - In a left-handed system, when the Y axis is up, the Z axis will be forward and when the Z axis is up, the -Y axis will be forward.
    • Right-Handed - In a right-handed system, when the Y axis is up, the -Z axis will be forward and when the Z axis is up, the Y axis will be forward.
  • Up Axis - The axis that points up. DirectX and OpenGL natively use the Y axis as up, but often modelers like Blender will use the Z axis up. Usually Y is a good choice for engines that use DirectX.
    • Y - The Y axis points up in the target engine.
    • Z - The Z axis points up in the target engine.
  • Export Meshes - Export mesh data. If unchecked the object's frame will still be exported.
    • Export Normals - Export mesh normals.
      • Flip Normals - Flip mesh normals before export.
    • Export UV Coordinates - Export the active UV layer.
    • Export Materials - Export material properties per face. Texture references will be exported as well.
      • Reference Active Images as Textures - Reference the active image of each face as a texture instead of the image texture assigned to the material.
    • Export Vertex Colors - Export the active vertex color layer.
    • Export Skin Weights - Export the vertex group data for the bones of an armature that affects this mesh. Multiple armatures per mesh is currently unsupported.
    • Apply Modifiers - Temporarily apply the effects of modifiers to the mesh before export. This excludes Armature modifiers only if Export Skin Weights is checked.
  • Export Armature Bones - Export frames for each bone of an armature. If unchecked, the armature object's frame will still be exported.
    • Export Rest Position - Export the bones of the armature in their rest positions. This is recommended if animation is exported.
  • Export Animation - Export object and bone animation (if bones are exported). Rotation, scale, and position is exported for every frame.
    • Include Frame Rate - Export the AnimTicksPerSecond template. This is required by some engines.
    • Export Actions as AnimationSets - Export the action of each object as a separate, named AnimationSet template.
      • Attach Unused Actions to First Armature - Export each unused action as if used by the first armature object.
  • Verbose - Displays debug text in the external console. Useful when getting export errors to see exactly where the problem occurred. Please email me with any bugs that you encounter.

Exporting Armatures

To export armatures that require complex constraints (i.e. MakeHuman rigs), it is often necessary to use the Bake Action operator on a new armature object before export:

  • Duplicate the armature object (Shift + D, not Alt + D) and set the mesh object's Armature modifier to use the new armature object. If you've parented the mesh object to the original armature object, it might be a good idea to parent it temporarily to the new armature object.
  • With the new armature object selected, press Space, type Bake Action, and press Enter.
  • Set the start and end frames appropriately and set Frame Step to 1.
  • Uncheck the Only Selected option and check the Visual Keying and Clear Constraints options.
  • For Bake Data, click on Pose.

After executing, the new armature object should have been stripped of all of its constraints and it should be using a new action. This new armature object and action should export correctly. After exporting, you can safely delete the new armature object and action, and set the mesh object's Armature modifier to use the original armature object again.

Other Information

The script has been updated and tested successfully on Blender 2.69.

Many people use the DirectX Viewer that used to ship with the DirectX SDK to test their exported models. I don't recommend this. The DirectX Viewer is old, outdated, and no longer supported by Microsoft. It also contains some weird bugs and quirks that might cause your model to render incorrectly. For instance, skinned meshes that use more than one material slot often appear to break apart in bizarre places and ways. For these reasons, I recommend using a different model viewer, such as AssimpView.

I'm committed to this project, so please feel free to email me about problems you encounter using the script, along with any questions, comments, or suggestions you might have. If something goes wrong, I can't fix it 'til you tell me! :)

Links and Support