JOGL - Loading a 3d model(request)

If, someone could post a very simple code how to load a 3d models into my code with JOGL.

Thanks!

P.s. No custom libraries just JOGL

sry but nobody can just post simple code for that^^

When you want to display model on the screen you must go through some steps, which are not really hard, but some work.

First you need a model file which is in a specific format, you want to use a format which is widly used and supported so you can use common tools to create your models. Most you because of this the OBJ format at first, because it is really easy to parse yourself and is very basic and nearly every tool supports it.

After that you will have some model data in your memory which needs to be converted to some data which can be used with OpenGL.
When you ave this you finally have to choose how to render it, i.e. glBegin or Buffer Objects and how to you handle materials(textures, properties like shininess).

I started out myself parsing OBJ and now finished(btw :)) a lib to read the OpenCTM format, take a look how I did it DarwinsBox: geometrie/io

The user “TheCodingUniverse” has created an object loader for .obj models. You can check out the source code here:

Thanks, now I’m on track!

MEMO FROM DUMB QUESTIONS DEPARTMENT:

What is a model when it is loaded anyway? What is an animation when it is loaded?

Are we just talking about a bunch of verteces and attributes. In the case of an animation, a sequence of sets of verteces and attributes?

Hi

Please could you be more precise? JOGL-utils is not very big and supports several model formats. I wrote an MD3 loader using JOGL several years ago.

I have an idea of what would go in a model file, and I know that OpenGL treats everything as verteces, so all I’m really asking is what sort of logic underlies the translation between the model file and the vertex array in OpenGL. How do animations work? How is the process optimised?

It depends on several aspects. There are models with hierarchies and models without any hierarchy. The former can contain “sub models” whereas the latter can’t. Each sub model contains some data (vertices, indices, textures coordinates, …) that you can store into vertex arrays or VBOs.

On the other hand, your animations can be skeletal or key frame based. For the former, the real geometry is computed by using the bones. For the latter, when you play an animation, you display a model corresponding to a given frame, obviously you can interpolate two predefined models corresponding to the closest key frames to get a smoother result.

There are tons of ways to optimize animations or even the meshes (make a quick search with the keywords “mesh optimization”).

You don’t answer his question, he’s looking for an example using JOGL and yours only supports a very limited subset of the WaveFront OBJ format, it doesn’t even handle texture coordinates.

There is a 3DS loader here, in JOGL-utils:

There is an OBJ loader here (using JOGL 1.1.1 unfortunately):
http://code.google.com/p/joglobj/

Thanks gouessej, it gives me something to think about. Sorry for the thread hijack.