无法在libgdx中加载3d模型

时间:2015-03-08 14:21:28

标签: android 3d libgdx assets

我为我的小项目制作了一些3D模型。但是当我使用资源管理器加载它们时,logcat会给我一个错误。

有代码:

public InGameScreen(TinyBattles game) { // screen constructor 

    ...

    assets = new AssetManager();
    assets.load("3d/tankbody6.obj", Model.class);
    loading = true;

}

private void doneLoading() {
    Model tank = assets.get("3d/tankbody6.obj", Model.class);

    ModelInstance tankInstanse = new ModelInstance(tank);
    tankInstanse.transform.setToTranslation(0, 0, 0);

    tankA.instance = tankInstanse;
    loading = false;
}

错误:

03-08 18:12:05.799  12397-12412/com.tinybattles003.game.android E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 22871
Process: com.tinybattles003.game.android, PID: 12397
com.badlogic.gdx.utils.GdxRuntimeException: Asset not loaded: 3d/tankbody6.obj
        at com.badlogic.gdx.assets.AssetManager.get(AssetManager.java:123)
        at com.tinybattles003.game.screens.InGameScreen.doneLoading(InGameScreen.java:92)
        at com.tinybattles003.game.screens.InGameScreen.render(InGameScreen.java:108)
        at com.badlogic.gdx.Game.render(Game.java:46)
        at com.tinybattles003.game.general.TinyBattles.render(TinyBattles.java:22)
        at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:422)
        at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1523)
        at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

这不仅是关于这个确切的模型,我试图加载它们中的每一个相同的结果。但最奇怪的是我可以在任何项目中加载模型,但是这个。

1 个答案:

答案 0 :(得分:0)

只需通过调用finishLoading()方法确保从资产文件夹加载模型。它会暂停渲染方法,直到模型完全加载。

li a:hover:not(.active) {
  background-color: #6497b1;
  color: white;
  text-decoration: none;
}