Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LibGDX and ObjLoader not displaying .mtl?

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?

like image 953
cavemaneca Avatar asked Apr 19 '13 17:04

cavemaneca


1 Answers

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/.

like image 124
Xoppa Avatar answered Oct 04 '22 03:10

Xoppa