Skip to main content
`Ctrl`+`K`

# vispy.io.wavefront module

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.

class vispy.io.wavefront.WavefrontReader(f)

  Bases: `object`

  finish()

    Converts gathere lists to numpy arrays and creates BaseMesh instance.

  classmethod read(fname)

    Entry point for reading OBJ files.

    Parameters:
      fname str

        The name of the file to read.

  readFace(line)

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

  readLine()

    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.

class vispy.io.wavefront.WavefrontWriter(f)

  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.

    Parameters:
      fname string

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

      vertices numpy array

        The vertex data

      faces numpy array

        The face data

      texcoords numpy array

        The texture coordinate per vertex

      name str

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

      reshape_faces bool

        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.

  writeLine(text)

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