解析文件时出错:file.g3db,同时在 libgdx 中使用搅拌机对象
Posted
技术标签:
【中文标题】解析文件时出错:file.g3db,同时在 libgdx 中使用搅拌机对象【英文标题】:Error parsing file: file.g3db, while using blender objects in libgdx 【发布时间】:2016-03-26 14:04:32 【问题描述】:我正在使用 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】:看起来很简单的错误消息:“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
【讨论】:
该文件被手动放入 android/assets 目录。在将它也放入 Android 工作室的 android/assets 之后,它就可以工作了。不知道为什么..我认为如果通过 android studio 或通过操作系统的文件系统放置它并没有什么不同以上是关于解析文件时出错:file.g3db,同时在 libgdx 中使用搅拌机对象的主要内容,如果未能解决你的问题,请参考以下文章
将 SOIL.lib 与 GCC 一起使用 - 添加符号时出错:无法识别文件格式
用vs2010编译cegui时,CEGUICoronaImageCodec项出错