In this MP you will
This MP is elective, with no core components. It assumes you have already completed the Terrain MP and optionally also the Textures MP.
You will submit a webpage that has
Submit an HTML file and any number of js, glsl, and css files. No image or JSON files are permitted for this assignment. Do not include spaces in file names as the submission server does not process them well.
You are welcome to use a JavaScript math library, such as the one used in in-class examples or others you might know.
Have one input text field for entering an OBJ file name. Optionally, also have one for entering a texture map image file name.
HTML input elements, styling, and event handling are beyond the scope of this class. See the Terrain MP for example code for setting up inputs.
For this assignment, you should use type="text"
instead
of the type="number"
used by the Terrain MP. You should
also remove the Number(...) || defaultValue
wrappers on the
inpupt checking in your JavaScript.
Given an OBJ file, parse it into a geometry object. You should support at least per-vertex positions and colors. We provide three example files that have just positions or just positions and colors:
triangle.obj
, the
smallest meaningful OBJ file we could maketeapot.obj
, with
positions onlycow.obj
, with positions and
colorsWe also provide a guide to reading OBJ files.
Once loaded, you should display the model with the following criteria:
This part is worth half of the points of this assignment.
To earn the other half of the points of this assignment, also handle OBJ-file-supplied normals and texture coordinates. We provide two example files for this:
bevel.obj
has surface
normals that are not the ones you’d computesuzanne.obj
has texture
coordinates and normalsAdditionally, you should allow a the user to provide an image to use as a texture map. If an image is provided (i.e. isn’t the empty string) you should use a vertex shader that uses the texture to pick the diffuse color of the model. If there are no texture coordinates the shader will default to using the top-left pixel as the object’s color – this will probably happen automatically, no special effort needed by you. If no image is provided, use the non-texture shader like usual.
On both your development machine and when submitted to the submission server and then viewed by clicking the HTML link, the resulting page should initially be blank. Once an OBJ (and optionally image) file name is entered and the button is pressed, the model should appear, filling most of the screen.
On the submission server, the following paths exist even if you didn’t upload them:
triangle.obj
teapot.obj
cow.obj
bevel.obj
suzanne.obj
example.jpg