How to load .obj file into JOGL program

Hello ,
(sorry for the long intro I just wanted to say that I actually worked on this)
I’m a newbie in JOGL, I’m working on creating a 3D world where I can move around and navigate through, I was trying to create the objects from the shapes that are already in JOGL such as (GL_QUADS, GL_POLYGON , etc …) and texture them, I’ve done a lot of works into this project and I created some simple shapes such as a Sky (using 5 QUADS), a house (using 4 QUADS as walls), and other objects as well such as TV’s, Table’s and other stuff, but the problem is that creating those objects using these simple shapes would take me forever and also kinda impossible…

SO to keep it short I want to load .obj 3D files into my world and so far I searched but without any results, I can’t find any OBJ loaders that are simple or even any complex ones with a good tutorial so if anyone can guide me through one that will be very much appreciated.

Sincerely ,
Lawa

shameless plug : http://www.java-gaming.org/topics/yet-another-obj-loader/35405/view.html

Thanks for the reply !
Can you give me a simple explaining on how this works? because as I said I’m new in this and I’ve never imported and OBJ into java so this is my very first time even working with obj files so I have absolutely no idea about how it works ! (sorry for being a noobie I guess? ) ;D

so in an obj file…
(everything in {} means that it is a variable)

Keyword: ------ Definition
mtllib {mtl file name}.mtl ----- mtllib is short for “material library.” this line is found at the top of the file and it tells the parser which mtl file we are going to be calling materials from.

o {name} -----------------New polygon group in the model
v {x} {y} {z} -----------------Defines a vertex
f {index1}/{index2}/{index3} ------Defines a face (which is a collection of vertices)
usemtl {name} ------ use the material named {name}. All faces defined after this line will use this material until another usemtl is used.
vt {x} {y} {z} ------ Defines a texture coordinate
vn {x} {y} {z} ----- Defines a vertex normal

Thank you for the explanation that was very useful, now can you explain these parts of the example code that I can’t understand such as:
1- What is this?
obj = new Simple[your_implementation]ObjFile();
obj.load(“meshes/some.obj”);

what should be my implementation?
what is “meshes/some.obj” ?

2- At the beginning of the code the example says “assuming blending and color is set up before.” what is blending & color?

Thanks

[quote]1- What is this?
obj = new Simple[your_implementation]ObjFile();
obj.load(“meshes/some.obj”);

what should be my implementation?
what is “meshes/some.obj” ?
[/quote]
Your implementation is the code you write, if you are going to write a class to load obj files then you need to call it something.

“meshes/some.obj” is the path to where your obj file is.

You are taking things too literally in the post, the post contained some abstract code which you need to build and implement.

This is just assuming some opengl defaults have been setup before

So apart from the codes that are posted

I should create another class? or that setup will work ?

So I don’t have to worry about these right?

that looks good.

“meshes/some.obj” means, there is a directory “meshes” in your project-root-folder, not a source-package.

you can ofc. load files form source directories, but that’s more complicated.

in this “tutorial” i’m assuming, you know basic opengl already. i’m using LWJGL here; shouldn’t be too complicated to make it work with JOGL.

here the class SimpleOBJFile is most important (line 205). it shows how to interpret the content of .obj files. it’s ment to be a simple starting point to implement more of the format : https://en.wikipedia.org/wiki/Wavefront_.obj_file

o/

Thank you very much for the help I just loaded my .obj file into my program successfully ! but the shape appears as points I know that happens because we call the drawPoints method but If you don’t call that method the shape won’t appear and I changed the GL_POINTS in the drawPoint method but that didn’t work out very well , so how can I solve that ?

This is the shape in the post :

And this is an object I wanted to import :

and one more question , what is the best way to texture the obj shaped inside a JOGL world?

Thanks!

Edit : And one last thing , I noticed importing these shapes impact FPS very hard (drops from 60 to 20 and less) especially at the second shape the first shape that I posted above doesn’t affect anything since its simple, is there any workaround for that?

Can you show us some of you code?

Which OpenGL profile are you targetting?

Yeah sure this is what I placed into my renderer method :

       glPushMatrix();
		glTranslated(10, 0, 10);
		GL11.glPointSize(3.0f);
		GL11.glLineWidth(2.0f);
		GL11.glColor4f(0.5f,0.5f,0.5f,0.25f);
		SimpleObjFileTools.drawFaces(obj);
		SimpleObjFileTools.drawQuads(obj);
		GL11.glColor4f(0.1f,0.1f,0.1f,1.0f);
		SimpleObjFileTools.drawPoints(obj);
		glPopMatrix();

and this is in my init method :


			obj = new SimpleArrayObjFile();
			obj.load("res/FinalBaseMesh.obj");
			obj.dump();

currently using GL11 from lwjgl , but I’m going to move back to GL2 from JOGL cause that where my world is created, does it make a difference?

Solved Thanks to basil_ for his help.

glad to help :slight_smile:

o/

I remind you that there is already one OBJ loader in JOGL and there is another one in JOGL-Utils…

Eww external libraries.

Check out youtube, it’s a great resource.

Follow thin matrix and all his videos. You will learn A LOT!!