Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Libgdx applying color to model instance doesn't work

Tags:

3d

libgdx

I'm trying to import a obj model to libgdx and apply one color to it - no shading whatsoever, just one color on all faces.

this is what I use in my create method:

    modelBatch = new ModelBatch();
    ObjLoader loader = new ObjLoader();
    model = loader.loadModel(Gdx.files.internal("data/test.obj"));
    model.materials.add( new Material(ColorAttribute.createDiffuse(Color.GREEN)));
    instance = new ModelInstance(model);

and in my render method:

    Gdx.gl.glClearColor(52 / 255f, 152 / 255f, 219 / 255f, 1.0f);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    modelBatch.begin(perspCam);
    modelBatch.render(instance);
    modelBatch.end();

The result is that model is white/grayish - why isn't it green?

like image 359
user2011769 Avatar asked Oct 09 '13 21:10

user2011769


1 Answers

Directly from here: http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=11115#p50125

"That's it. In my example I try to change the material from the model, but i need to change on the instance:

//Example, not work:
playerInstance.model.materials.get(0).set(new ColorAttribute(ColorAttribute.Diffuse, Color.RED));

//Actual, works:
playerInstance.materials.get(0).set(ColorAttribute.createDiffuse(Color.RED));"
like image 145
Lestat Avatar answered Sep 28 '22 09:09

Lestat