Homework 4: Off Putting

Short Description:

Write a program that converts a model in Object File Format to an object stored in javascript arrays.

This assignment is worth 15 points.

Goals

When you finish this homework, you should

Formal Description

The off file format was developed in the early days of the web. These files contain a basic model description. The format discussed here is relatively simple.

Unfortunately, it is difficult to load a file in javascript, so we need to convert these files to some format that can be placed on the web. While a json solution may be more elegant, you are to write a simple javascript solution.

You program should read in a .off file and produce a .js file. This file should construct an object. This object should have two properties, .triangles and .BC.

.triangles will return an array containing the triangles defining the object.

.BC returns the values required for barycentric shader. In the future, we will add another field, .normals which will return the computed normals associated with the vertex.

In the end, your program should produce a javascript file looking something like:

      function CubeModel() {
          this.triangles = [[-0.5, -0.5, -0.5], [0.5, -0.5, -0.5], ...]]; 
	  this.BC = [[1, 0, 0], [0, 1, 0] ...]];
      };
And will be used like:
      cube = new CubeModel();

      console.log(cube.triangles);
      console.log(cube.BC);

The off modes sometimes contain polygons that are not triangles, so your program should decompose all non-triangles into triangles.

While you have no control over how the polygons are specified (CW or CCW), make sure that you remain consistent with the original in your final output.

The Off models tend to be all over the place, so one additional requirement is that you scale the model so that it fits in the unit cube (-0.5, -0.5, -0.5) to (0.5, 0.5, 0.5). The ENTIRE model should be scaled by the largest dimension. So for example, if the model is bounded by the cube (1,1,1) to (9,10,11), the largest dimension is 11-1 or 10, so all coordinates should be scaled by 1/10.

Ideally the program should read the .off file from standard in and write the .js file to standard out. It should command line arguments for the name of the model to create. If you have had CSCI 311, you should do this. You may, however, write an interactive program that asks for

So to convert cube.off to cube.js :
$ off2js
   Enter the input file name: cube.off
   Enter the output file name: cube.js
   Enter the model name: CubeModel
If you chose the CSCI 311 approach, your program should accept the command line option -modelName name. If no name is given, the default should be CubeModel.
$ off2js -modelName CubeModel < cube.off > cube.js
By the way, please call your executable off2js.

More documentation on off files, along with links to multiple off file repositories are located here

You may use any language that will compile on the linux machines. I would assume C++. If you use c++, you may use the vector class.

Please be aware that lines in off files starting with a # are a comment.

Submission

Please submit a tar file containing your source code and instructions on how to build the project to your instructor via email by class time on the due date. This should also include a document describing how you accomplished the scaling of the model.