CPSC 424, Computer Graphics, Spring 2010
Lab 5: OBJ files and Indexed Face Sets


The objective of this lab is simply stated: you want to be able to read a file in Wavefront OBJ format, build a data structure to represent the indexed face set that it contains, and display the object represented by that indexed face set. For displaying IFS data, you should create an IFS node type that you can use in your 3D scene graphs. Write a test program that simply displays one IFS node or, if you prefer, three of them created from the three sample data files.

You can ignore any information in the OBJ file about normal vectors and texture coordinates. You should ignore any line that does not begin with "v" or "f". You can assume that the "f" lines contain only vertex indices, with no normal or texture coordinates (although it would be better to allow the extra data to be there, but ignore them).

You will find three OBJ files in /classes/s10/cs424 that you can use as examples: pyramid.obj, an OBJ file for the simple pyramid example that we have been using in class; blender_monkey.obj, a file exported from Blender, containing the data for the iconic Blender chimp, Suzanne; and the large file text.obj, a file exported from Blender, containing data for a text object. You should make these files available to your program as resources, that is, as files in a package in your program that you can access with the getResource method of a class loader. Your OBJ-reading utility should be able to read such resource files.

To display the mesh described by an OBJ file, you will have to create normal vectors. The utility class Vec3fMath contains static methods that can help you do this. You will find a copy of Vec3fMath.java in /classes/s10/cs225; it is meant to be added to my glutil package.

You will need to be able to compute the normal vector to a polygon. You can use one of the methods Vec3fMath.computeNormalFromPoints(p1, p2, p3) or Vec3fMath.computeNormalFromPoints(p1, offset1, p2, offset2, p3, offset3) to do this for you. The first method will be useful if you store your vertex data in an array of type float[][] in which vertex number N is the N-th row of the array; the second, if you use an array of type float[] in which the coordinates for vertex number N are stored in the array starting at position 3*N. Warning: These methods return null if all the vertices of the polygon lie on a line. In that case, the polygon has no interior, and it doesn't make sense to draw it. This actually happens for a few of the faces in text.obj, so you have to consider this possibility.

If you use the normals to the polygon faces as normal vectors for the object, it will have a faceted appearance. This is correct for pyramid.obj. It works fine for text.obj, since the faces in that model are either flat or quite small. For blender_monkey.obj, however, and for many other models, it would be preferable to make the model look smooth. To do this, you can do the following: For each vertex, find the unit normal vector to each face that contains that vertex. Add up all these vectors, and normalize the result. This gives you a unit normal that you can use for that vertex. For methods that can help you with the computations, look at the addInto and normalize methods in Vec3Math.

You can get full credit for this lab if you just show IFSs with faceted appearance. You can get extra credit if you provide an option to smooth the models. Ideally, you should have a boolean flag in your IFS screen graph node to say whether it should be smoothed or not.

The lab is due in two weeks. Next week will be a Blender modeling lab, and part of that lab will be to export a mesh model that you have created and to import it into an OpenGL program using the IFS scene graph node that you write for this lab.


David Eck for CPSC 424