DirectX Exporter

[View it on Github]

Blender is a top quality 3D content creation suite that just happens to be totally free. It comes with importers and exporters for many popular file formats, including 3DS, MD2 and Microsoft .X files (for easy integration with DirectX projects).

Blender ships with a .X exporter written by Ben Omari, who’s clearly put a lot of hard work and effort into writing it, and I owe him a huge debt of gratitude. Unfortunately, I was finding that I wasn’t getting very consistent results with it, and that in many cases it was silently failing without giving any clues for what was wrong with my mesh.

To support my Bible-teaching computer games project, I decided I’d have to get my hands dirty and start digging around in the Python source code for the exporter, to see if I could figure out what was going wrong. To aid my understanding of the code, I started adding comments, renaming functions to be more accurate, removing duplicate code (so that any modifications could be made in a single place) and adding various debugging error messages that make it clear where the code was failing. Doing all this highlighted a few undocumented assumptions that the exporter was making about how your mesh was set up, and also a number of minor bugs that were causing problems for me. I’ve written up the process in an article titled “Tips for taking over someone else’s code“, which you might find helpful if you’re a software developer yourself.

Under the terms of the GPL, and also to save others having to go through the same hassle I’ve been through, I’m making available my updated version of Ben’s exporter. I was doing my development using Blender 2.45, so I make no promises that it will still work with earlier versions.

New features include (updated 17th April 2009):

  • Improved error handling and plenty of warning messages to help you work out why the .X file it’s spewing out is a load of gibberish that won’t open in your DirectX application
  • Added new templates to support Shape Keys (morph targets). Obviously you’ll need to write some code on the DirectX side to actually make use of this data – feel free to email me for some ideas on this
  • It now correctly reverses the winding order when an object has a negative scaling factor
  • Many more bug fixes and improvements

It comes with the following caveats and warnings:

  • I believe the “Export Selected” button to be somewhat buggy. My advice is to stick to the “Export All” button.
  • The “Dedup” button I added to write out a VertexDuplicationIndices template doesn’t seem to work. I get a stupid error message “Invalid DuplicationIndices in x file. All duplicates must refer to the same vertex index”. If anybody has ever encountered that error before and knows how I can fix it, please let me know!


DirectX Exporter for Blender 2.45 on Github

Thoughts of a Christian Software Developer