COS426 Mesh File Formats


COS426 File Format (.ray)

The COS426 file format is a rudimentary scene graph language. The full file format supports surface materials, light sources, and high-level geometric primitives (we will be using those features in assignments 3 and 4). However, for this assignment, you will need to know about only three commands:
#vertex_num    n
This directive specifies the number of vertices in the file. It must appear before the first vertex.
#vertex    x y z    nx ny nz    ts tt
This directive defines a vertex at position (x,y,z) with normal (nx,ny,nz) and texture coordinates (ts,tt). The normal and texture coordinates will usually be zero in the input files -- they can be created and output by your program.
#shape_triangle    0    i1 i2 i3
This directive defines a triangle with vertices indexed by i1, i2, and i3 (ignore the first field which will always be zero in this assignment), where the vertex identifiers correspond to the order of previously defined vertices in the file (note that the first vertex defined in the file has integer identifier 0).

Here is a simple example for a cube in .ray format:

#vertex_num 8
#vertex -0.5 -0.5 0.5 0 0 0 0 0
#vertex 0.5 -0.5 0.5 0 0 0 0 0
#vertex -0.5 0.5 0.5 0 0 0 0 0
#vertex 0.5 0.5 0.5 0 0 0 0 0
#vertex -0.5 0.5 -0.5 0 0 0 0 0
#vertex 0.5 0.5 -0.5 0 0 0 0 0
#vertex -0.5 -0.5 -0.5 0 0 0 0 0
#vertex 0.5 -0.5 -0.5 0 0 0 0 0
#shape_triangle 0 0 1 3
#shape_triangle 0 0 3 2
#shape_triangle 0 2 3 5
#shape_triangle 0 2 5 4
#shape_triangle 0 4 5 7
#shape_triangle 0 4 7 6
#shape_triangle 0 6 7 1
#shape_triangle 0 6 1 0
#shape_triangle 0 1 7 5
#shape_triangle 0 1 5 3
#shape_triangle 0 6 0 2
#shape_triangle 0 6 2 4


Object File Format (.off)

OFF files are simple ASCII files containing only vertices and faces. The file begins with the keyword OFF. The next line states the number of vertices, the number of faces, and the number of edges. The number of edges can be safely ignored. The vertices are listed with x, y, z coordinates, written one per line. After the list of vertices, the faces are listed, with one face per line. For each face, the number of vertices is specified, followed by indices into the list of vertices (note that vertex indices are numbered starting at 0). See the examples below.

OFF
numVertices numFaces numEdges
x y z
x y z
... numVertices like above
NVertices v1 v2 v3 ... vN
MVertices v1 v2 v3 ... vM
... numFaces like above

Here is a simple example for a cube in .off format:

OFF
8 6 0
-0.5 -0.5 0.5
0.5 -0.5 0.5
-0.5 0.5 0.5
0.5 0.5 0.5
-0.5 0.5 -0.5
0.5 0.5 -0.5
-0.5 -0.5 -0.5
0.5 -0.5 -0.5
4 0 1 3 2
4 2 3 5 4
4 4 5 7 6
4 6 7 1 0
4 1 7 5 3
4 6 0 2 4


Wavefront File Format (.obj)

The Wavefront .obj file format is a standard 3D object file format created for use with Wavefront's Advanced Visualizer. The format supports several high-level geometric primivites, including free-form surfaces. However, for this assignment, we will concern ourselves with only a subset of the language (other directives will be ignored):
v    x y z
This directive defines a vertex at position (x,y,z).
f    i1 i2 i3
This directive defines a triangle with vertices indexed by i1, i2, and i3, where the vertex identifiers correspond to the order of previously defined vertices in the file (note that the first vertex defined in the file has integer identifier 1, which is different than the other file formats).

Here is a simple example for a cube in .obj format:

v -0.5 -0.5 0.5
v 0.5 -0.5 0.5
v -0.5 0.5 0.5
v 0.5 0.5 0.5
v -0.5 0.5 -0.5
v 0.5 0.5 -0.5
v -0.5 -0.5 -0.5
v 0.5 -0.5 -0.5
f 1 2 4
f 1 4 3
f 3 4 6
f 3 6 5
f 5 6 8
f 5 8 7
f 7 8 2
f 7 2 1
f 2 8 6
f 2 6 4
f 7 1 3
f 7 3 5