Main | Installing | Engine | Exporter | Project ideas | Contact | Discuss | Back to Sol

The blender exporter is also meant to be edited if new features demand some new information to be exported from blender. Blender's plugins are written in Python, which is rather easy to learn.

If you don't feel like taking that plunge right now, it's ok, as the current exporter gives you plenty of data to play with. Just keep in mind that if you need to, the exporter can be extended.

Using the exporter
When a scene is ready to be exported, launch the exporter from the File->Export menu:

When you do, you will get the exporter options screen:

By default, submeshes are collapsed, animations are exported, and quads are converted to triangles by calculating the shortest splitting edge. These defaults are usually ok. When you click 'export', blender will ask for the target filename, and then exports the scene.

In case of problems, the exporter script has a debug switch near the beginning of the file. If turned on, the script will output plenty of debug information to the blender console.

Exporter script overview
The script is based on some of the scripts that come with blender, and hence is licensed under the GPL. This doesn't really matter, as the script is always distributed as source.

When started, the first thing that the script does happens on the very last line of the script file, and there the script's UI is registered to blender.

The gui() function renders the exporter's interface. Events (i.e. keyboard) are handled in the event() function, where we only check for escape and quit. When buttons are pressed, the button_event() function gets a call. There we either change some script-global variable values, or start the export process.

The export process starts by launching a file selector with a callback. When the callback fs_callback() is called, it makes sure the file has the proper extension, and calls the actual exporting function do_export().

do_export() opens the target file, and then calls write_header(), write_textures(), write_materials(), write_meshes(), write_lamps(), write_cameras() and write_anims() to export the different bits to the file. The do_export() function also makes sure the current animation frame in blender is preserved and times the whole export process.

The most interesting export function is the write_meshes(), which has to duplicate vertices if blender wants to use several UV coordinates in one vertex (such as when uv unwrapping is done).

The second interesting tidbit is the handling of camera matrices, both in write_cameras() and write_animation() - the matrix is resized to 4x4 and inverted, so that it can be (more easily) used in OpenGL directly.

Site design & copyright © 2007 Jari Komppa