Models

We will need to use models of objects to create scenes. There are many model formats, but OBJ is one that is easy to understand and many programs can read and write the format. Models in this format often have several parts:

The format was developed many years ago by a company called Wavefront. The format is not actively maintained. Paul Bourke maintains a description of the spec here:

OBJ files

We will use several components from OBJ files. There are many more that we will not be using; read the spec if you want more details.

Vertex positions

A list of xyz triples representing positions in 3D space.

v 0.5 0.01 1.2
v 0.2 1.8 1.73
...

Vertex normals

A list of xyz triples representing normal vectors away from surfaces.

vn  0 1 0
vn 0.707 0.707 0
...

Texture coordinates

A list of xyz triples representing texture coordinates on a volume or surface. We will only use 2D coordinates in this class.

vt 0 0
vt 0 1
vt 1 1
vt 1 0
...

Faces

Uses the lists of positions, normals, and texture coordinates to form faces. These can be arbitrary polygons, but we will only use triangles. Note that the vertex lists are start at index '1', not index '0'. Negative number refer to the list in reverse order.

Faces are componsed of several 3-references, where the first refernce is vertex position index, then normal index, then texture coordinate index. References are separated by '/'.

f 1// 2// 3//
f 1// 3// 4//

f 1/56/8 34/55/921 38/12/109
...

Other

Links to a material file can be defined with mtllib FILENAMEHERE and materials can be switched with usemtl MAT_NAME.

MTL files

Material files are lists of material properties. The most important terms are:

An example MTL file:

newmtl material_name_goes_here
Ka  0.1 0 0      # ambient values
Kd  1 0 0        # diffuse values
Ks  1 1 1        # specular values
Ns  10           # sharpness of specular highlight
map_Kd test.png  # texture map filename
sharpness 30     # sharpness of reflection
d  0.5           # transparency amount
Ni  1.33         # index of refraction