LWJGL Model Loaders and Utility Demos

Started by crash0veride007, June 16, 2006, 16:49:18

Previous topic - Next topic

crash0veride007

I see that one of the most often asked questions for LWJGL is where can I get model loader<insert name here> or is there any example code for doing <X>
I am in the process of writing a few loaders and utilities for LWJGL which will be used in my personal java.net project JGLMark.
JGLMark (https://jglmark.dev.java.net/) is open source and  I intend it to be a Java OpenGL benchmark.
I will make regular update posts here as I progress with the loaders and utlities in hopes that I can receive FeedBack from the community on them and so that I may best optimize them as well as give something back to help improve the community as a whole.
I am also always looking for good help to join the JGLMark team as well... ;)

So on to the good stuff..
The code can be downloaded from JGLMarks Documents and files section here:
https://jglmark.dev.java.net/servlets/ProjectDocumentList?folderID=5582&expandFolder=5582&folderID=0

The Code thus far:

PACKAGE---------------------------------------------------------------------------------------------------------------------------------------------------
GL.LWJGL

Textures
Status: In Progress
Class:
Dependent Utility Classes: none
Desciption: Example of loading and using Textures in LWJGL

GLSL
Status: In Progress
Class:
Dependent Utility Classes: GLSLShaderUtil
Desciption: Example of loading and using GLSL Vertex and Fragment Shaders in LWJGL

LWJGL OBJ Model Loader
Status: In Progress
Class: OBJModelDemo
Dependents Utility Classes: OBJModelVBO
Desciption: Example of loading and using OBJ Models in LWJGL
So Far I have implemented loading and handling of:
1) Vertex data
2) 3D texture coordinate data
3) Normal Data
4) Load models using VBO's (OBJModelVBO)
5) draw the model
TO BE DONE.....
1) Implement support for OBJ Groups
2) Implement support for OBJ Materials and Textures
3) Implement support for OBJ Mesh Smooth Groups

Vertex Buffer Objects (VBO)
Status: In Progress
Class:
Dependent Utility Classes:
Desciption: Very Simple Example of using VBO's in LWJGL

PACKAGE---------------------------------------------------------------------------------------------------------------------------------------------------
GL.JOGL

Textures
Status: Done
Listener: SimpleTextureListenerSimple
Dependent Utility Classes: none
Desciption: Example of loading and using Textures in JOGL (JSR-231)

GLSL
Status: Done
Listener: SimpleGLSLListener
Dependent Utility Classes: GLSLShaderUtil
Desciption: Example of loading and using GLSL Vertex and Fragment Shaders in JOGL (JSR-231)

JOGL OBJ Model Loader
Status: In Progress
Listener: SimpleOBJModelListener
Dependent Utility Classes: OBJModel, OBJModelVBO
Desciption: Example of loading and using OBJ Models in JOGL (JSR-231)
So Far I have implemented loading and handling of:
1) Vertex data
2) 3D texture coordinate data
3) Normal Data
4) Load models using Vertex Arrays (OBJModel)
5) Load models using VBO's (OBJModelVBO)
6) draw the model
TO BE DONE.....
1) Implement support for OBJ Groups
2) Implement support for OBJ Materials and Textures
3) Implement support for OBJ Mesh Smooth Groups

Vertex Buffer Objects (VBO)
Status: Done
Listener: SimpleVBOListener
Dependent Utility Classes: none
Desciption: Very Simple Example of using VBO's in JOGL JSR-231




Please post or Email me your suggestions, feedback, and or if you'd like to volunteer to help the effort/Join the JGLMark team.

Fool Running

Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Kokoni

Hi Crash,

I get the following error when I try to draw my obj model :

java.nio.BufferOverflowException
	at java.nio.Buffer.nextPutIndex(Unknown Source)
	at java.nio.DirectFloatBufferU.put(Unknown Source)
	at OBJModelVBO.ConstructVTN(OBJModelVBO.java:195)
	at OBJModelVBO.BuildVBOModel(OBJModelVBO.java:162)
	at OBJModelVBO.DrawModel(OBJModelVBO.java:291)
	at DemoObjLoader.render(DemoObjLoader.java:88)
	at App.mainLoop(App.java:210)
	at App.run(App.java:183)


It occurs every time on all my models exported from Sketchup, I post you a simple example :

# Alias OBJ Model File
# Exported from SketchUp, (c) 2000-2005 @Last Software, Inc.
# File units = meters

mtllib cube.mtl

g Model

usemtl FrontColor
v -3.43255 -1.44382e-015 -0.317807
vt 135.14 12.5121
vn 0 -1 0
v -3.43255 -1.44382e-015 -1.93081
vt 135.14 76.016
v -1.11755 -1.44382e-015 -1.93081
vt 43.9979 76.016
v -1.11755 -1.44382e-015 -0.317807
vt 43.9979 12.5121
v -2.22751 -1.44382e-015 -0.317807
vt 87.6973 12.5121
v -2.22751 -1.44382e-015 0.387193
vt 87.6973 -15.2438
v -2.84351 -1.44382e-015 0.387193
vt 111.949 -15.2438
v -2.84351 -1.44382e-015 -0.317807
vt 111.949 12.5121
f 1/1/1 2/2/1 3/3/1 4/4/1 5/5/1 6/6/1 7/7/1 8/8/1 

usemtl FrontColor
v -3.43255 0.885 -1.93081
vt -135.14 76.016
vn 0 1 0
v -3.43255 0.885 -0.317807
vt -135.14 12.5121
v -1.11755 0.885 -0.317807
vt -43.9979 12.5121
v -1.11755 0.885 -1.93081
vt -43.9979 76.016
f 9/9/2 10/10/2 11/11/2 12/12/2 

usemtl FrontColor
vt -76.016 -5.68434e-014
vn -1 0 0
vt -12.5121 -5.68434e-014
vt -12.5121 34.8425
vt -76.016 34.8425
f 2/13/3 1/14/3 10/15/3 9/16/3 

usemtl FrontColor
vt 43.9979 -5.68434e-014
vn 0 0 -1
vt 135.14 -5.68434e-014
vt 135.14 34.8425
vt 43.9979 34.8425
f 3/17/4 2/18/4 9/19/4 12/20/4 

usemtl FrontColor
vt 12.5121 -5.68434e-014
vn 1 0 0
vt 76.016 -5.68434e-014
vt 76.016 34.8425
vt 12.5121 34.8425
f 4/21/5 3/22/5 12/23/5 11/24/5 

usemtl FrontColor
vt -135.14 -5.68434e-014
vn 0 0 1
vt -111.949 -5.68434e-014
v -2.84351 0.52 -0.317807
vt -111.949 20.4724
v -2.22751 0.52 -0.317807
vt -87.6973 20.4724
vt -87.6973 -5.68434e-014
vt -43.9979 -5.68434e-014
vt -43.9979 34.8425
vt -135.14 34.8425
f 1/25/6 8/26/6 13/27/6 14/28/6 5/29/6 4/30/6 11/31/6 10/32/6 

usemtl FrontColor
v -2.22751 0.52 0.387193
v -2.84351 0.52 0.387193
f 7/26/6 6/29/6 15/28/6 16/27/6 

usemtl FrontColor
vt 12.5121 20.4724
vt -15.2438 20.4724
vt -15.2438 -5.68434e-014
f 5/21/5 14/33/5 15/34/5 6/35/5 

usemtl FrontColor
vt -87.6973 12.5121
vt -111.949 12.5121
vt -111.949 -15.2438
vt -87.6973 -15.2438
f 14/36/2 13/37/2 16/38/2 15/39/2 

usemtl FrontColor
vt -12.5121 20.4724
vt 15.2438 -5.68434e-014
vt 15.2438 20.4724
f 13/40/3 8/14/3 7/41/3 16/42/3


Perhaps, it is du to a specific obj file format from sketchup, but I would be very surprised.

If you have any clue, it will be great. Anyways, your code is very clean, thanks for that !

crash0veride007

That OBJ file is malformed and does not conform to the obj specification: http://www.martinreddy.net/gfx/3d/OBJ.spec

Kokoni

Ok !! That's explain why it crashs.
Oh well, I have to write a little program to transform the odd format to the conform one.

Thanks for your answer.

Kokoni

Crash,

Comparing the specifications and my obj files, I don't see where is the malformation...

Except the lines orders, but at first sight your main loop should avoid this kind of problem.

crash0veride007

the problem lies here: "-1.44382e-015"

rethrick

Sweet, thanks for this. It's very helpful.

Just a small suggestion, looking at the demo sources: you are catching Exception in the run() method and trapping out with System.exit(0). I'd suggest exiting with System.exit(1) in this case.

Also you might consider implementing the Runnable interface on demos that have a run() method, that way the demos can be plugged into different runners easily (e.g junit or ant).

Anyway good project.