eclipse LibGDX 3d模型纹理未正确渲染

yqhsw0fo  于 2022-11-23  发布在  Eclipse
关注(0)|答案(2)|浏览(171)

只是提醒一下,我真的是新来的,所以很抱歉,如果我的问题是不清楚:
我已经用Blender做了一个3D模型,我只是用了一个混合着色器来作为我的模型的材质。我试图让它在LibGDX中正确显示。当我在Blender中渲染模型时,它看起来像这样:

然后我将文件导出到fbx,然后使用fbx-conv将其转换为.g3db文件,但是当我尝试在代码中加载模型(取自http://blog.xoppa.com/loading-models-using-libgdx/)时:

public class Basic3DTest implements ApplicationListener {
PerspectiveCamera cam;
public CameraInputController camController;
public Environment environment;
public ModelInstance instance;
public ModelBatch modelBatch;
public AssetManager assets;
public Array<ModelInstance> instances = new Array<ModelInstance>();
public boolean loading;

@Override
public void create() {
    modelBatch = new ModelBatch();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f,
            0.4f, 0.4f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -.5f,
            -0.6f, -1f));
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(),
            Gdx.graphics.getHeight());
    cam.position.set(10f, 10f, 10f);
    cam.lookAt(0, 0, 0);
    cam.near = 0.1f;
    cam.far = 300f;
    cam.update();
    camController = new CameraInputController(cam);
    Gdx.input.setInputProcessor(camController);
    assets = new AssetManager();
    assets.load("data/Space Game/ModelData/blinky.g3db", Model.class);
    loading = true;
}

  private void doneLoading() {
        Model ship = assets.get("data/Space Game/ModelData/blinky.g3db", Model.class);
        ModelInstance shipInstance = new ModelInstance(ship); 
        instances.add(shipInstance);
        loading = false;
    }

@Override
public void dispose() {
    modelBatch.dispose();
    instances.clear();
    assets.dispose();
}

@Override
public void pause() {
    // TODO Auto-generated method stub

}

@Override
   public void render () {
    if (loading && assets.update())
        doneLoading();
    camController.update();

    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    modelBatch.begin(cam);
    modelBatch.render(instances, environment);
    modelBatch.end();
}

@Override
public void resize(int arg0, int arg1) {
    // TODO Auto-generated method stub

}

@Override
public void resume() {
    // TODO Auto-generated method stub

}

}
以下是显示的内容:

知道哪里出了问题吗?提前感谢。

yhqotfr8

yhqotfr81#

渲染时应该明确设置着色器。有关在libgdx中使用着色器的信息,请参阅https://github.com/libgdx/libgdx/wiki/Shaders

5sxhfpxr

5sxhfpxr2#

'AssetManager assets = new AssetManager();'
'assets.load("myFile.g3db", Model.class);'
'assets.finishLoading();'
'Model myModel = assets.get("myFile.g3db", Model.class);'

'ModelInstance myInstance = new ModelInstance(myModel);'
'Texture myTexture = new Texture(Gdx.files.internal("badlogic.png"));'
'Material myMaterial = new Material(TextureAttribute.createDiffuse(myTexture));'
'NodePart nodePart = myModel.nodes.get(0).parts.get(0);'
'nodePart.material.set(myMaterial);

/* 所有这些都必须在create方法中 */

相关问题