CSCI 250 Graphics File Format

 

This document describes the data file format to be used for the z-buffer and raytracing projects for the computer graphics course.  The format is a mixture of the Neutral File Format of Eric Haines, and of the Wavefront .obj format.  Any command in an input file that is not described below is to be treated as a comment, and the line ignored.

 

Files are stored as ASCII text, with one command per line.  The first character on the line determines the command type.  The following commands are valid:

 

#                comment…rest of line is ignored

v                vertex

vn              normal vertex

f                 face

g                group

 

c                camera specification

b                background color

l                 positional light location/color

m               object material properties

s                sphere primitive

p                polygon primitive

pp              polygon patch primitive

 

The syntax of each command is given below in more detail.

 

# a comment line

 

All text from the ‘#’ symbol through the next carriage return is ignored.

 

v x y z

 

Specifies the coordinates of a vertex.  Vertex commands are indexed in the order they are listed in the file, starting at 1.

 

vn x y z

 

Specifies a normal vector at a vertex.  These are indexed in the order they appear and match the “v” commands, so the third “vn” command describes the normal direction of the third point (specified by the third “v” command).

 

f v1[//vn1] v2[//vn2] v3[//vn3]…

 

Specifies a polygon made from connecting the vertices v1, v2, v3, etc, in the order specified in the command.  The last vertex is connected to the first vertex to complete the polygon.  If included, the vt’s specify the vertex normals for their paired vertices.  Note that v1, vn1, v2, vn2, etc, are just integers starting with 1, which specify the index of the vertex (or vertex normal).

 

g name

 

Specifies a group name.  All face commands following a group command are considered to be part of the same group until another “g” command is issued.  We will use this later to do some speedups using culling and bounding volumes.

 

c

from fx fy fz

at ax ay az

up ux uy uz

angle degrees

hither front_clip_distance

resolution xres, yres

 

This command sets up the virtual camera.  The “from” command specifies the location of the camera.  The “at” command specifies the center coordinates of the generated image.  The “up” command specifies the camera up vector.  The “hither” command specifies the distance to the front clipping plane, while the “resolution” command specifies the image size in pixels.  All images are assumed to have an aspect ratio of 1.0, and the far clipping plane is assumed to be at infinity.  Also, note that 1 or more of the vectors might need normalizing.

 

b r g b

 

Specifies the red, green, and blue components of the background color.  This is the color to use when there is no other object to determine the pixel color.

 

l x y z r g b

 

Position and color of a directional light source.

 

 

m r g b Kd Ks shine T index_of_refraction

 

The “m” command specifies the material properties for all following objects until the next “m” command is parsed.  The base color of the argument is specified, along with the diffuse coefficient, specular coefficient, shininess exponent, transmittance, and index of refraction.

 

S x y z r

Specifies a sphere with center at (x, y, z) and radius r.

 

p #vertices

x1 y1 z1

x2 y2 z2

x3 y3 z3

. . .

 

An alternative way of specifying a polygon by giving the x, y, and z coordinates of each of its vertices.  Each vertex is connected to the next, and the last is connected to the first.  These vertices do not get included in the vertex count when computing indexes.

 

pp #vertices

x1 y1 z1 xn1 yn1 zn1

x2 y2 z2 xn2 yn2 zn2

x3 y3 z3 xn3 yn3 zn3

. . .

 

An alternative way of specifying a polygon with vertex normals by giving the x, y, and z coordinates of each of the vertices, and the normals at each.  These vertices do not get included in the vertex count when computing indexes.