6

我正在尝试将 obj 模型导入 libgdx 并对其应用一种颜色 - 没有任何阴影,所有面上只有一种颜色。

这是我在创建方法中使用的:

    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);

在我的渲染方法中:

    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();

结果是模型是白色/灰色 - 为什么不是绿色?

4

1 回答 1

13

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));"
于 2013-10-11T05:21:36.633 回答