OBJ Exporter Using PyMel

The work of most Tech Artists revolves around pipelines. And, as an exporter is the starting point of any pipeline, I’m going to investigate making a PyMEL OBJ Exporter.

Creating a simple obj exporter is fairly straightforward. It can get more complex when you start adding this like multiple UV sets, smoothing groups, constraints etc.

So let’s start simple.

Exporting a simple 1-dimensional plane from Maya gives the following .obj file:

Lets break this down:

This is the definition of where the material file is in relation to the obj file

Now we start building the mesh. In obj, we build the definition of the mesh elements and then define it at the end, so we start off by listing the vertices and their world space positions.

These are the texture vertex coordinates. As we propagate through the elements, we have to ensure that the orders all match.

These define the vertex normals

s = smoothing groups, in this case we’re not using them

g = group name, i.e. the name of the mesh (group of elements)

simply the name of the material to be assigned

Each of these lines define a face (we only have one line as we only have the one face). The data is in the order of the indexes above, so:

vert1_POSITION_index / vert1_UV_index / vert1_NORMAL_index      vert2_POSITION_index / vert2_UV_index / vert2_NORMAL_index      etc…



Building the code

Starting with our simple plane, lets try to replicate the output we have from the Maya exporter:


This was pretty easy, we just had to ensure we collected the data in the same order, and the easiest way to do that is to just build the lists of data as we go.

Now we build the face data. This can be a little trickier, as we have to watch we get the index allocation correct, but it’s still pretty straightforward.


Lets test this thing.



Model credit: http://tf3dm.com/3d-model/black-dragon-rigged-and-game-ready-92023.html




Further reading:

PaulBourke.net : Extensive documentation about everything that an obj file can contain

Article Name
Obj PyMel Exporter
Writing an .obj exporter using Maya PyMel

Leave a Reply

Your email address will not be published. Required fields are marked *