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?
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));"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With