LibGDX and ObjLoader not displaying .mtl?
Asked Answered
Q

2

7

I am trying to load .obj files into an Android project with LibGDX. The files have no texture file, but include materials in .mtl files. I'm using the latest official nightly, and rendering the object file only results in the object appearing white. How do I get the ObjLoader to use the .mtl file?

@Override
public void create() {
    objLoader = new ObjLoader();
    model = objLoader.loadObj( Gdx.files.internal("data/obj.obj"), true);
}

@Override
public void render() {
    Gdx.gl.glClearColor(0, 0, 0, 0);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    batch.begin();

    model.render();

    batch.end();
}

This is how the code to render the object is called. Here is a link to the ObjLoader class

https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g3d/loaders/wavefront/ObjLoader.java

What am I doing wrong? And why won't it load the .mtl file? From what I can understand, it should load a .mtl file that's in the same folder and same name as the .obj file.

EDIT I have messed around a bit, putting some lines into the ObjLoader class to log what it is and isn't loading. It looks like it's loading the mtl file, and assigning each mtl to a Material instance, and it also looks like the obj is correctly asking for those materials.

Is there something I need to enable or otherwise do on the OpenGL end to make sure it's using these materials properly?

Quoit answered 19/4, 2013 at 17:40 Comment(0)
S
1

The ObjLoader and especially the MtlLoader it uses is very limited. Try using the new 3D api with fbx instead. Here's explained how to load a model: http://blog.xoppa.com/loading-models-using-libgdx/.

Sidelong answered 23/6, 2013 at 1:30 Comment(1)
Note that link-only answers are discouraged (links tend to get stale over time). Please consider editing your answer and adding a synopsis here.Myopic
B
0

I found the very same issue, and that's exactly why I both reported it here:

https://github.com/libgdx/libgdx/issues/2441

and committed a fix to it here:

https://github.com/libgdx/libgdx/commit/d7e716351d26ddfba19ce9e0b3bdfb449dbc81b7

, supporting virtually all MTL parameters out there. Note that this is a WIP, and (hopefully) will get into trunk once it's finished.

Banting answered 1/12, 2014 at 18:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.