在 libgdx 中使用 blender 对象时解析文件时出错:file.g3db
Error parsing file: file.g3db, while using blender objects in libgdx
我正在尝试 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);
}
看起来是一条非常简单的错误消息:"FileNotFoundException: convertedModel.g3db"。确保文件名(区分大小写)正确并且文件存在。要验证它,您可以将以下代码添加到 show()
方法的顶部。
Gdx.app.log("", Gdx.files.internal("convertedModel.g3db").exists() ? "exists" : "does not exist");
确保文件名在两行中一致(这一行和对 loadModel
的调用)。
默认情况下,内部文件应位于 android 项目的 assets
子文件夹中,或者当您没有 android 项目时,位于核心项目中。这是您使用设置实用程序创建新项目时 badlogic.jpg
所在的位置。
我正在尝试 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);
}
看起来是一条非常简单的错误消息:"FileNotFoundException: convertedModel.g3db"。确保文件名(区分大小写)正确并且文件存在。要验证它,您可以将以下代码添加到 show()
方法的顶部。
Gdx.app.log("", Gdx.files.internal("convertedModel.g3db").exists() ? "exists" : "does not exist");
确保文件名在两行中一致(这一行和对 loadModel
的调用)。
默认情况下,内部文件应位于 android 项目的 assets
子文件夹中,或者当您没有 android 项目时,位于核心项目中。这是您使用设置实用程序创建新项目时 badlogic.jpg
所在的位置。