OBJ Model Loader v0.1

Here it is…
My Wavefront OBJ Loader! It took me about two days to program this. It works perfect for me.

Here are the features:
-Allows you to load a model which uses both quads (4 vertexes) and triangles (3 vertexes), even if your model uses both quads and triangles simultaneously.
-No normals yet, sorry.
-Position, rotation, and scale.
-No textures yet - I’m still struggling with this.

Instructions for use:
To load an OBJ file, simply use the following command:

OBJRender model = OBJRender("your_model.obj");

After you have loaded your model, you must call the method render() to draw your model to the display (in your loop). Note that render() automatically calls glPushMatrix() before rendering the model and glPopMatrix() after, so it is not necessary to do this.

To control the position, rotation, and scale is very simple. The variables x, y, z, rotX, rotY, rotZ, scaleX, scaleY, and scaleZ are all public which allow you to alter the respective position, rotation, and scale. They should be self-explanatory, but if not, here’s a quick break-down:
x positions the model on it’s X axis.
y positions the model on it’s Y axis.
z positions the model on it’s Z axis.
rotX rotates the model around it’s X axis
rotY rotates the model around it’s Y axis
rotZ rotates the model around it’s Z axis
scaleX scales the model around it’s X axis.
scaleY scales the model around it’s Y axis.
scaleZ scales the model around it’s Z axis.
Theses values must be set before render() is called.

Get it here:
Source: http://www.gonavitch.info/OBJRender/OBJRender_v0.1_src.zip
Classes: http://www.gonavitch.info/OBJRender/OBJRender_v0.1.zip

Note: The source code is NOT commented!

Please post any comments, rants, or suggestions.

I am sorry to say that, but there were many many obj loaders done in the past.

Treating textures and the containing normals isn’t that hard. For the textures you can use a HashMap with the texture and its assigned mesh.
For a better performance you should sort the polygons and avoid unnessesarry glBindTexture calls.

Anyway, if not using an engine, the programmer will allways write its own modelloader :wink: except he found a really cool one.

In the lwjgl forum were some cool examples :slight_smile:

http://lwjgl.org/forum/viewtopic.php?t=917 and http://lwjgl.org/forum/viewtopic.php?t=1451

Evil-Devil: do you have a zipped example (maybe sources as well) with ready-to-run binaries of OBJViewer. I looked at the lwjgl posts and link you provided over there did not work anymore. I havent followed lwjgl progress lately (long time) and did not know it can be embedded to swing application.

At the moment the example only runs with lwjgl 0.99. I planned to port it over to lwjgl 1.0 asap. But need to find some time first :wink:

Else you can decompile the modelloader class or just use the example code from elias4444.

not much to port from 0.99 to 1.0 its pretty much the same (the api that is), just drop in the new libs and your done :slight_smile:

Yea, theoretical. The port itself isn’t that big, but i need time first. My AWTOpenGLCanvas need the modifications. Because some AWTGLCanvas Stuff changed from 0.99 to 1.0.
THere will be a port and if it is done, the Example thread will be updated. Or feel free to do the port yourself :wink: