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

See wikipedia for more details.

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)#

Entry point for reading OBJ files.


The name of the file to read.


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)#

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)#

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')#

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)#

Write the given mesh instance.

writeTuple(val, what)#

Writes a tuple of numbers (on one line).