OBJ format

A copy of the original, full description of the OBJ model format is at http://www.cs.utah.edu/~boulos/cs3505/obj_spec.pdf. (This includes *many* advanced features that we don't care about.) Some additional info is on Wikipedia.

Geometry

The basics that you need to know for the homework are:

For example

v 0 0 0
v 5 0 0
v 2.5 3.2 0
v 0 1 1
v -1 1 0.5
v -1 5 1
f 1 2 3
f 4 5 6

describes two triangles. The first 3 vertices are at positions (0,0,0), (5,0,0), and (2.5,3.2,0); the line "f 1 2 3" uses them to form the first triangle. The fourth, fifth, and sixth vertices form the second triangle.

Other things to note:

  1. The same vertex can be used by multiple faces
  2. Faces have only one side; the other side is not drawn. The visible side is that where the vertices are listed in clockwise order, when viewed from the camera.

The file cube.obj uses 8 vertices for 6 square faces of a cube. The faces should be visible from outside the cube; if you move the camera inside it, they will be invisible.

Colors

To add color to an OBJ model, use a "material library". This is a separate file (usually with the extension .mtl). The file is a list of materials. Each material starts with a newmtl line, giving it a name, followed by lines specifying different aspects of the color. The most important color part (all we'll bother with for now) is the "diffuse" color, labeled Kd and giving R G B values.

Example (this is in the .mtl file):

newmtl brown
Kd 0.65 0.16 0.16

The materials are then applied to the model by first referencing the material file in the OBJ file (a mtllib line), then selecting a material with a usemtl line. The most recently selected material is applied to all subsequent faces.

Example (this is in the .obj file):

mtllib triangles.mtl
v 0 0 0
v 5 0 0
v 2.5 3.2 0
v 0 1 1
v -1 1 0.5
v -1 5 1
usemtl brown
f 1 2 3
f 4 5 6

Example

The Viewpoint cow is a larger example model, which also includes normals for lighting (something we'll get to later).