简体   繁体   中英

can not load 3d model in libgdx

I've made some 3d models for my small project. But when I load them using assets manager, logcat gives me an error.

There is the code:

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

Error:

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)

It is not only about this exact model, I tried to load each of them this the same result. But the weirdest thing is that I can load model in any project, but this.

Just make sure your model is loaded from asset folder by invoking the finishLoading() method. It pauses render method until the model is completely loaded.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM