Libgdx加载blender模型,透明度不正确

时间:2017-10-19 09:22:13

标签: java libgdx blender

我正在使用libGdx 1.9.6并且我遇到了问题。我搜索过多个论坛,阅读各种教程,但没有任何内容。我在搅拌机中创建了一个简单的立方体,对其进行纹理处理并将其导出到FBX(使用fbx-conv)。我还下载了BDX-Blender-Exporter。我测试了Blender 2.69和2.76b而没有对结果进行任何更改。

加载并显示模型:

blended cube

如果我将背景颜色更改为(0,0,0,0)或(0,0,0,1),则只会出现黑屏。

这是代码(libGDX 1.9.6,Android-Studio 2.3.3)

public class modelloader implements ApplicationListener {
private PerspectiveCamera camera;
private ModelBatch modelBatch;
private Model model;
private ModelInstance modelInstance;
private Environment environment;
private CameraInputController camController;

private AssetManager as;

@Override
public void create() {

    camera = new PerspectiveCamera(
            75,
            Gdx.graphics.getWidth(),
            Gdx.graphics.getHeight());

    camera.position.set(0f,0f,7f);
    camera.lookAt(0f,0f,0f);

    camera.near = 0.1f;
    camera.far = 300.0f;

    modelBatch = new ModelBatch();

    as = new AssetManager();
    as.load("moon.g3db",Model.class);
    as.finishLoading();
    model = as.get("moon.g3db",Model.class);


    model.materials.get(0).set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));

    modelInstance = new ModelInstance(model);

    modelInstance.transform.rotate(1, 0, 0, 0);
    modelInstance.transform.translate(0, 0, -2);
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.8f, 0.8f, 0.8f, 1.0f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -0.8f, 0.3f, 1f));
    camController = new CameraInputController(camera);
    camController.forwardTarget = true;
    Gdx.input.setInputProcessor(camController);
}

@Override
public void dispose() {
    modelBatch.dispose();
    model.dispose();
}

@Override
public void render() {
    camController.update();
    Gdx.gl20.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl20.glClearColor(1,1,1,0);
    Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

    camera.update(true);

    modelBatch.begin(camera);
    modelBatch.render(modelInstance, environment);
    modelBatch.end();

}

模型也只在行

时显示
model.materials.get(0).set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));

存在。

这是blender文件:

cube.blend

哪里可能是问题?

1 个答案:

答案 0 :(得分:1)

圣鲭鱼,它是纹理文件......它是1024x1024 png ...但不知何故腐败...一旦打开并重新启动并且所有工作......无数个小时,这是我唯一的事情。没检查...谢谢你的帮助! -