This module produces functionality to read and write wavefront (.OBJ) files.

The wavefront format is quite powerful and allows a wide variety of surfaces to be described.

This implementation does only supports mesh stuff, so no nurbs etc. Further, material properties are ignored, although this might be implemented later,

The classes are written with compatibility of Python3 in mind.


Bases: object


Converts gathere lists to numpy arrays and creates BaseMesh instance.

classmethod read(fname, fmt)[source]

This classmethod is the entry point for reading OBJ files.


The name of the file to read.


Can be “obj” or “gz” to specify the file format.


Each face consists of three or more sets of indices. Each set consists of 1, 2 or 3 indices to vertices/normals/texcords.


The method that reads a line and processes it.

readTuple(line, n=3)[source]

Reads a tuple of numbers. e.g. vertices, normals or teture coords.


Bases: object

classmethod write(fname, vertices, faces, normals, texcoords, name='', reshape_faces=True)[source]

This classmethod is the entry point for writing mesh data to OBJ.


The filename to write to. Must end with “.obj” or “.gz”.

verticesnumpy array

The vertex data

facesnumpy array

The face data

texcoordsnumpy array

The texture coordinate per vertex


The name of the object (e.g. ‘teapot’)


Reshape the faces array to (Nf, 3). Set to False if you need to write a mesh with non triangular faces.

writeFace(val, what='f')[source]

Write the face info to the net line.


Simple writeLine function to write a line of code to the file. The encoding is done here, and a newline character is added.

writeMesh(vertices, faces, normals, values, name='', reshape_faces=True)[source]

Write the given mesh instance.

writeTuple(val, what)[source]

Writes a tuple of numbers (on one line).