OBJ Loader
Author |
Message |
RedHedZed
|
Posted: Tue Nov 22, 2011 8:20 pm Post subject: OBJ Loader |
|
|
Hey guys,
I'm a Game Development student in university. I'm building a game using OpenGL and one of the thing I'm required to do is load an obj file into the game.
I already have a simple character created in Maya, but I'm not really sure how to go about creating the code to load it. Any help would be welcome! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Tue Nov 22, 2011 8:30 pm Post subject: RE:OBJ Loader |
|
|
if you are simply using some Engine, then read that Engine's documentation on loading assets.
if you are writing your own Engine, then read the .obj file specification and write a parser. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
DemonWasp
|
Posted: Tue Nov 22, 2011 8:33 pm Post subject: RE:OBJ Loader |
|
|
I suggest reading about the file format itself: http://en.wikipedia.org/wiki/Wavefront_.obj_file and http://www.martinreddy.net/gfx/3d/OBJ.spec
Once you've done that, you should be able to come up with a way to read in the whole file. The easiest way is probably to read the input line-by-line, then break each line into tokens by splitting on whitespace (spaces, tabs, ...), then determine the "type" of the line by the contents of the first token -- a line that starts with "v" describes a vertex, a line that starts with "f" is a face, etc.
It will probably be helpful to create some very simple .obj files to start with, so you can work with small parts of the language at a time. The first one should probably be a single triangle, without textures or other advanced features. Once you can load that correctly, move to a more complicated model, such as a cube with a simple texture. Gradually work your way up to handling the whole file specification. |
|
|
|
|
|
RedHedZed
|
Posted: Tue Nov 22, 2011 9:48 pm Post subject: RE:OBJ Loader |
|
|
Thanks! I'll give that a shot. |
|
|
|
|
|
|
|