Programming assignment 3 - .obj File Loader/viewer/modeler

CS 354 - Introduction to Computer Graphics
Spring, 2015
Don Fussell

DUE Monday March 9 at 11:59pm

In this assignment, you'll expand on your work in Assignment 2 to become more familiar with OpenGL and scene descriptions by creating your own 3D model viewer. Your system will read input files in .obj format, build scene graphs using them, and render the results. You''ll implement much more sophisticated camera control than in the previous assignment, and your scene graph will support simple animations. Here are some objects that you should be able to parse and display along with code for parsing them. You may also be able to parse and render other objects in this format that you find on the web, but at a minimum you must be able to handle the ones we're giving you.

.obj files contain a rather simple ASCII format that's very easy to parse. Design your user interface to allow interactively selecting files to be read into your scene.

Object loader

Each line of an .obj file contains a record of some sort. The first character of the line indicates what the type of record is, and thus what to do with the rest of the line. The only ones you need to implement are: There are several other record types that you'll encounter, but you're free to ignore them. Once you've loaded the model, compute normals for both faces and vertices. Assume counter-clockwise winding for the face normals, then average the incident face normals to produce normals for each vertex. Note that the parser in loader.h assumes a Trimesh object with methods for adding vertices and faces is provided in geom.h (not provided). Such an object maintains a list of vertex positions and defines the face mesh using indices into this vertex list. Designing this will be one significant part of this assignment. You are free to modify loader.h as you see fit to accomplish the project.

Camera control

Being able to move the camera around is crucial when trying to examine an object, so the second part of this assignment is to add orbit-style camera control. In this type of camera control, there's a point of interest that the camera is looking at. The camera can orbit around the point, zoom in and out, and move the point around by panning.

Implement these controls with the following mouse operations:

Make sure that you set the camera controls to sensible defaults when starting up! The initial point of interest should be the center of the object, and the zoom level should comfortably fit the object in the window. Your camera must do perspective projection, not orthonormal projection. As before, you're free to use the built-in OpenGL transformation and perspective functions to implement your camera; you don't need to do any of the matrix math yourself. You are also allowed to use gluLookat as before if you choose.

Rendering

In addition to the camera, you will also implement several rendering modes. The best way to expose these to the user is probably as keyboard commands, but it's up to you to determine how the user interface works.

Implement the following list of rendering options:

As you'll see, solid mode is not very useful; all it displays is a solid block of pixels in the outline of the object. To make the display a little more sensible, you'll implement a shaded mode as well. For shaded mode, you can use OpenGL's default lighting. The following code snippet shows you how to do this:

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
// draw triangles here
// use glNormal3f() to submit a vertex normal with each vertex
glDisable(GL_LIGHTING);

Hierachical modeling and motion control

You should implement all camera and object motions as well as placement of lights using a scene graph. All drawing should be done by a generic traversal of the graph to draw it. Changes to what is drawn are accomplished by changes to the scene graph. You should have several types of scene graph nodes:

For simplicity and due to the limitations of the glut GUI capabilities, you may hard code a scene graph structure to start with. This scene graph should have a root object, at least one light node, a camera node and a child object of the root that will link to the geometry node that contains your parsed object data. All of these object, light, and camera nodes will be linked by transform nodes. You should move the camera by manipulating the transform node connecting it to the world, likewise you will do object motions this way. Due to GUI limitations, the only required motion is for your object to be able to spin around any of its local object coordinate system primary axes. You should be able to turn on or off any combination of these spins interactively.

Extra credit

As you will presumably notice doing it, there are many ways to enhance this project if you're so inclined. Here are some suggestions:

Notes:


Last modified: 02/19/15 by Don Fussell fussell@cs.utexas.edu