Export utility for Blender 2.49 and 2.53

Hi everybody,

today I’d like to introduce you to a set of Blender Python scripts I wrote, that can be of great use to anybody interested in using Blender in realtime applications. Their purpose is to collect data about models within Blender and to bring it into an intermediate form, that is typically needed for efficient rendering in realtime applications. Thus it is the perfect base for developing export plugins.

The features
Let me list the features for you.

  • The scripts are completely under GNU-GPL

  • Full support for Blender 2.49 and Blender 2.53. Except for the UI you can use the same code for exporting from both versions.

  • It can export all the data that is typically needed in realtime applications:

  • Mesh objects, including vertex normals, vertex texture coordinates (optionally from multiple UV textures), painted skin weights and material data per triangle. Envelopes are not supported.

  • The effects of modifiers on meshes can be exported.

  • Metaballs, surfaces, curves and text objects can be exported as simple meshes.

  • Material objects with ambient, diffuse, emissive and specular color and with textures.

  • Armature objects with an arbitrary number of actions effecting them and with constraints (constraints can be baked automatically).

  • Parenting relations are handled correctly (including parent bones).

  • It optimizes its output data in useful ways:

  • Faces get triangulated.

  • Double vertices get removed (in an efficient octree based manner).

  • Unused materials are ignored.

  • Bones that do not effect any geometry can be removed automatically.

  • Weights are saved per vertex with bone indices and sorted by influence and they are normalized.

  • After collecting the data you can manipulate and simplify it to suit your needs better. You can:

  • apply transformations.

  • reduce the entire model to a single mesh and (if needed) a single skeleton.

  • create default texture coordinate sets to get consistent vertex formats.

  • unify the number of skin weights per vertex.

  • combine all actions into a single long animation.

  • you can still access corresponding Blender objects to retrieve additional data.

  • The scripts do not require a full Python installation.

    The use

    The typical workflow of an export script, that uses this utility script is as follows:

  • Get the correct settings through a UI (this is the only part that requires code that is specific to a particular Blender version).

  • Pass these settings to the constructor of the class CModel. The class will collect all the requested information and represent it through several utility classes (e.g. CMesh, CObject, CVertex, CSkeleton, CBone, etc.).

  • Apply post processing steps (e.g. reduce the model to a single mesh and skeleton).

  • Use your own functions to save the data in the utility classes to your file format.

If you use this set of scripts all steps except for step 4 will barely cause any work and step 4 should be as simple as your model file format allows it to be.

The development
You might wonder what I wrote this for. Originally I developed these scripts to export from Blender to my 3D engine. A while back I got in contact with the professional 3D engine developer Spinor and they asked me to write an export plugin for their 3D model file format. To do so my original export plugin needed quite a few improvements. This export utility is the result. Spinor kindly allowed me to release it under an open source license. The entire utility is heavily object oriented and as independent from particular Blender versions as possible. All Blender specific code is encapsulated in a single module that implements Blender wrapper classes. As a result future changes in the Blender 2.5x Python API won’t cause much trouble. With a total of 6000 lines just for the utility parts it is quite a large script.

Besides the export utility I have also released the exporter for my 3D engine under GNU GPL. This should be useful as it provides an example of how the utility modules can be used.

The documentation
At the moment there is no independent documentation for this utility module. However I’d appreciate getting a page in the Blender Wiki to write one. Other than that there are very thorough comments everywhere in the source code. I recommend that you start by reading the comments in CModel (export_utility_shared.py) and then move on to CModelData (export_utility_xx.py) and to the classes CMesh, CSkeleton, CBone, CObject, CMeshObject and CMaterial. If you add to this by checking how the exporter for my 3D engine works, you should be able to understand the concepts. There is a documentation for the format of my 3D engine that might be useful when trying to understand the exporter.

Alpha state and feedback
I ported this utility to Blender 2.53 last week. During this process a lot of code has changed. Therefore it is currently alpha software. There probably are several bugs to be found. If you find one please let me know. At the moment the easiest way to do so is a post in this topic or an email to admin( at )Ultimate3D.org.

There are also some features “missing”. The utility can impossibly support all of Blender’s features, but at the moment some things that can be useful for realtime applications are not supported. In my opinion the most important things that are missing are support for object animations (without armatures), support for dupli groups and maybe support for envelopes. If you can think of anything else, that would be a useful feature, please let me know.

Here is the download link for the export utility. The download includes a little readme file, that may help you to get started with the scripts. One of the modules reduces exporters based upon the export utility to single Python files, for an easier installation. If you like to you can download the result of this process for my U3D exporter as well.

I hope this will be of use for some of you.
With friendly regards,
Christoph Peters