Model Loading

Model Loading is a problem mainly of file loading, and should be a simple problem to solve, and it is. The hard part is getting the specs FOR the various file formats. OBJ is a good example. It is a very simple file format, but every application that exports it, does it differently, and each in their own way. Here is the basic format:

OBJ files are textual, and are line based. Each line can have one of several commands:

v - vertex command vn - normal command vt - texture command f - face command

These are the basic ones, and the rest are really not that important for loading. Some of these others are:

usemtl - use a material defined in an external file (MAYA is the only app I know of that does this properly, as it's Wavefront's file format) g - Group command # - Comment command

Vertex commands are the 'v' followed by a whitespace delimited list of coordinates Normal commands are the 'vn' followed by three whitespace delimited coordinates Textures are 'vt' and followed by two.

Face structure commands have two types, with '/'-es and without. With, it looks something like this:

f 1/2/3 4/5/6 ... for as many vertices that the polygon has.

Of course, since this is a textual format, any number can be skipped, resulting in a form more like:

f 1//3 or f 5/4/

Sometimes it will even skip the '/'-es all together and just have vertices:

f 1 4 7


Since OpenGl is fastest with triangles, it is a good idea to outline a simple way of turning a convex polygon (where any line will only pass through the sides at most twice, so, a square, rectangle, or regular polygon, but not a heart, ocean outline, or some such thing with protrusions) into triangles. This is fairly simple, pick a vertex, and draw lines to all other vertices of the polygon. This divides it into the minimum number of triangles possible.

Note: Since OBJ only allows convex polygons, this method should be fine.


If someone wishes to write a method of NonConvexPolygonTesselation?, then that would be helpful.

DanielStaudigel


EditText of this page (last edited November 12, 2014) or FindPage with title or text search