Libgdx在Android上没有加载model.g3db

时间:2017-05-22 20:13:00

标签: java android libgdx

它没有给出任何致命的异常或错误,我只能在我的设备或模拟器中看到它。该项目位于Android Studio中。我还尝试使用.g3dj扩展名加载模型。

@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, -1f, -0.8f, -0.2f));

    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(1f, 1f, 1f);
    cam.lookAt(0,0,0);
    cam.near = 1f;
    cam.far = 300f;
    cam.update();

    camController = new CameraInputController(cam);
    Gdx.input.setInputProcessor(camController);

    assets = new AssetManager();
    assets.load("piramid.g3db", Model.class);
    loading = true;
}

private void doneLoading() {
    Model ship = assets.get("piramid.g3db", Model.class);
    ModelInstance shipInstance = new ModelInstance(ship);
    instances.add(shipInstance);
    loading = false;
}

@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(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

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

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

有谁知道如何才能正确渲染模型?感谢。

0 个答案:

没有答案