解析文件时出错:file.g3db,同时在libgdx中使用blender对象

时间:2015-12-20 09:50:39

标签: 3d libgdx blender fbx

我正在玩libGDX导入3d模型。我成功地将fbx文件转换为d3db。这是完整的错误,以下是show方法中使用的源代码。我从教程中获得了代码,它应该可以正常工作。转换器有问题吗?

12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime: Process: com.mygdx.cube.android, PID: 19468
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime: com.badlogic.gdx.utils.SerializationException: Error parsing file: convertedModel.g3db
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.utils.UBJsonReader.parse(UBJsonReader.java:56)
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader.parseModel(G3dModelLoader.java:65)
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader.loadModelData(G3dModelLoader.java:61)
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.assets.loaders.ModelLoader.loadModel(ModelLoader.java:53)
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.assets.loaders.ModelLoader.loadModel(ModelLoader.java:69)
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.mygdx.cube.GameScreen.show(GameScreen.java:47)
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.Game.setScreen(Game.java:61)
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.mygdx.cube.Cube.create(Cube.java:9)
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:243)
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1511)
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:  Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: convertedModel.g3db (Internal)
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:77)
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:151)
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.utils.UBJsonReader.parse(UBJsonReader.java:54)
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader.parseModel(G3dModelLoader.java:65) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader.loadModelData(G3dModelLoader.java:61) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.assets.loaders.ModelLoader.loadModel(ModelLoader.java:53) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.assets.loaders.ModelLoader.loadModel(ModelLoader.java:69) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.mygdx.cube.GameScreen.show(GameScreen.java:47) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.Game.setScreen(Game.java:61) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.mygdx.cube.Cube.create(Cube.java:9) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:243) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1511) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:  Caused by: java.io.FileNotFoundException: convertedModel.g3db
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at android.content.res.AssetManager.openAsset(Native Method)
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at android.content.res.AssetManager.open(AssetManager.java:313)
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at android.content.res.AssetManager.open(AssetManager.java:287)
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:75)
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:151) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.utils.UBJsonReader.parse(UBJsonReader.java:54) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader.parseModel(G3dModelLoader.java:65) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader.loadModelData(G3dModelLoader.java:61) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.assets.loaders.ModelLoader.loadModel(ModelLoader.java:53) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.assets.loaders.ModelLoader.loadModel(ModelLoader.java:69) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.mygdx.cube.GameScreen.show(GameScreen.java:47) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.Game.setScreen(Game.java:61) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.mygdx.cube.Cube.create(Cube.java:9) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:243) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1511) 
12-20 10:47:38.866 19468-19519/com.mygdx.cube.android E/AndroidRuntime:     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239) 









public void show() {
            camera = new PerspectiveCamera(45, Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
            camera.position.set(3.8f, 8f, 3f);


            camera.lookAt(0f,0f,0f);
            camera.near =0.1f;
            camera.far = 300f;

            modelBatch = new ModelBatch();

            UBJsonReader jsonReader = new UBJsonReader();

            G3dModelLoader modelLoader = new G3dModelLoader(jsonReader);
            model = modelLoader.loadModel(Gdx.files.getFileHandle("convertedModel.g3db", Files.FileType.Internal));

            modelInstance = new ModelInstance(model);

            environment = new Environment();
            environment.set(new ColorAttribute(ColorAttribute.AmbientLight,0.8f,0.8f,0.8f,1.0f));



            Gdx.input.setInputProcessor(this);
        }

1 个答案:

答案 0 :(得分:0)

看起来非常简单的错误消息:“FileNotFoundException:convertedModel.g3db”。确保文件名(区分大小写)正确且文件存在。要进行验证,您可以将以下代码添加到show()方法的顶部。

Gdx.app.log("", Gdx.files.internal("convertedModel.g3db").exists() ? "exists" : "does not exist");

确保两行中的文件名一致(此行和对loadModel的调用)。

默认情况下,内部文件应位于Android项目的assets子文件夹中,或者,如果您没有Android项目,则应位于核心项目中。这是使用设置实用程序创建新项目时badlogic.jpg所在的位置。

另请参阅:https://github.com/libgdx/libgdx/wiki/File-handling