Libgdx applying color to model instance does not work

I am trying to import the obj model into libgdx and apply one color to it - without shading at all, only 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 rendering 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();

As a result, the model is white / gray - why is it not green?

+4
source share
1 answer

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

"This is in my example. I'm trying to change the material from the model, but I need to change 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));"
+7
source

All Articles