CPSC310A Assignment 8 - Meshes

Due Monday February 20

Details

Modify your C++ ray tracing program to include the ability to render scenes that include triangle meshes in obj 3D model files. You should create a model class and a mesh class.

The model class should have a material library, an array of vertices, an array of normals, and an array of meshes as member data. The model constructor should read an obj file that contains only faces with three vertices, with or without vertex normals. Refer to the obj file format specification for more details on the obj file. The model class should store all vertices and all normals in its instance arrays and usemtl lines in the obj file should deliminate collections of faces as meshes. That is, all faces after a usemtl line should be added to a mesh that contains a pointer to the material. If there are any faces defined before a usemtl line, then the faces should be added to a mesh that uses the default material.

The mesh class should have an array of triangles and a pointer to a material as instance data. The Triangle class should have pointers to the vertices and normals in the model class. The mesh class should also have an intersect method that iterates through all of the triangles in the mesh to determine if any triangles intersect. If an intersection is found the surface normal should be interpolated using the barycentric coordinates and the vertex normals. If the vertex normals do not exist for the triangle, then then the normal of the plane the triangles are in should be used.

The scene file specifies a model to be rendered with a line that begins with "obj" and looks like:

obj filename.obj

Triangles in the scene class can be implemented by creating a model that contains the vertices of the triangle with one mesh that contains only one triangle.

Submission

Tar your code in a file that contains your name and submit it on the course Inquire site.