Hello Guest

Load models (.obj/.mtl) blender in LWJGL 3

  • 8 Replies
  • 744 Views
*

Offline begin

  • *
  • 12
Load models (.obj/.mtl) blender in LWJGL 3
« on: October 29, 2018, 16:37:31 »
Hello!

Sorry for my speak, My English is not native
Okey, I need create load/parser of models for my project (library LWJGL 3)
Formats .mtl file and .obj.

I'm just starting to use the LWJGL library, so I do not know much.
But I have been looking for an answer to this question for a very long time - Where I can to find this is load/parser?
Now I ussing this engine - https://github.com/LWJGL/lwjgl3-demos

But have problem.
This engine dont't hold loading mtl format, i.e his don't can load texture (.mtl) of my model.
(Sorry for my speak. Hes very complicated for me  :) )

I aldready looked all sites with this loader,
but they were all used for LWJGL2 and the smaller version or they gave me a lot of errors.

Okey, now I ask your help me!  :'(

*

Offline KaiHH

  • ***
  • 149
Re: Load models (.obj/.mtl) blender in LWJGL 3
« Reply #1 on: October 29, 2018, 16:39:38 »
This demo https://github.com/LWJGL/lwjgl3-demos/blob/master/src/org/lwjgl/demo/opengl/assimp/WavefrontObjDemo.java#L240 uses Assimp to load both the geometry in the .obj file as well as the material from the .mtl file. It renders a red magnet.

*

Offline begin

  • *
  • 12
Re: Load models (.obj/.mtl) blender in LWJGL 3
« Reply #2 on: October 29, 2018, 17:26:14 »
I already looked this, but I could not  sort out with shaders..
Is it possible to simplify an example? I could not make out the work of shaders

*

Offline KaiHH

  • ***
  • 149
Re: Load models (.obj/.mtl) blender in LWJGL 3
« Reply #3 on: October 29, 2018, 19:14:13 »
What exactly are you asking for? If you just want to know how to extract the information from an .obj and .mtl file and render that however you want, then just look at these lines: https://github.com/LWJGL/lwjgl3-demos/blob/master/src/org/lwjgl/demo/opengl/assimp/WavefrontObjDemo.java#L380-L397
and the methods/constructors they call.
Just ignore the fact that this demo uses shaders to render the model. You can just as well use the fixed-function pipeline to render the model. Every information of the imported model is available through the AIScene instance.

*

Offline begin

  • *
  • 12
Re: Load models (.obj/.mtl) blender in LWJGL 3
« Reply #4 on: October 29, 2018, 19:57:47 »
Good, but I getting it:



Must be:



I can't understand, what me to do...
I think that problem in my code mtl and obj (OR shaders):

.mtl format

Code: [Select]
# Blender MTL File: 'None'
# Material Count: 3

newmtl Material.001
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.047609 0.042289 0.236911
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2

newmtl Material.002
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.678536 0.710339 0.647579
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2

newmtl Material.003
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.010962 0.254837 0.181573
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2


« Last Edit: October 29, 2018, 20:07:44 by begin »

*

Offline KaiHH

  • ***
  • 149
Re: Load models (.obj/.mtl) blender in LWJGL 3
« Reply #5 on: October 29, 2018, 21:20:08 »
You cannot really expect to export a model from Blender, use any arbitrary OpenGL demo program, which just happens to load a .obj/.mtl model, and get the same result compared to what Blender's 3D view shows you.
You HAVE TO learn about OpenGL/GLSL and shading models if you want that.

I can't understand, what me to do...
Learn Graphics Programming with OpenGL and GLSL:
1. read lots of articles, books, tutorials about OpenGL and GLSL
2. write lots of example/demos/throw-away programs
3. iterate between 1. and 2.

*

Offline begin

  • *
  • 12
Re: Load models (.obj/.mtl) blender in LWJGL 3
« Reply #6 on: October 30, 2018, 05:47:17 »
Okey, –°an you recommend something from the study material?

Re: Load models (.obj/.mtl) blender in LWJGL 3
« Reply #7 on: October 30, 2018, 11:13:17 »

*

Offline begin

  • *
  • 12
Re: Load models (.obj/.mtl) blender in LWJGL 3
« Reply #8 on: October 30, 2018, 15:07:20 »
I already look ThinMatrix, but thank you for material :)