You may have noticed, designing 3D object is a pain if you have to type in every single vertex position.
We want you to do this once or twice, so you can see how hard it is.
After that, it grows old. And you realize that to make a fancy object what you’ll really do is to make is using some modeling software, or scan it, or find it on the web. This means the model will be stored in some file format. So your program needs to figure out this file format, read it in, and convert it to your data structures.
Learning to understand a file format is good practice (we used to make students do it). But now, we’ll give you JavaScript code that will read in a common object file format. (OBJ files). You can find tons of OBJ files on the web. The reader won’t read them all (it doesn’t have all the fancy features, and a lot of files don’t conform to the specification).
Because of the file loading security issues (the same ones as shaders and textures), if your program isn’t being web served, you can’t load files. So we’re also giving you a web service that will take an OBJ file and turn it into a javascript file that loads the information into objects.
The OBJ Loader (and converter) were written by Yusef Sohail.
- https://github.com/Squeakrats/OBJLoader is the site for the loader. It has some documentation.
- http://graphics.cs.wisc.edu/Courses/559-f2015/Examples/OBJGenerator/generator.html is the thing that converts OBJ to JS.
- http://graphics.cs.wisc.edu/Courses/559-f2015/Examples/ObjSimple/ is a simple program I wrote to try it out. You can see how I convert the OBJ loader data structures to things that WebGL wants. Although, I should warn you, this code was written for speed of writing, not ease of reading.