У меня есть модель, которая находится в локальном хранилище (/data/user/0/com.myapp/files/model.g3db
).Я хочу загрузить эту модель в мой AssetManager
, чтобы использовать ее позже.Если использовать стандартный метод, такой как assetManager.load("model.obj", Model.class);
, он получает файл из папки assets
, которая является частью проекта.Это меня не устраивает.Итак, я попытался использовать AssetDescriptor
для указания файла:
FileHandle fh = Gdx.files.local("model.g3db");
if(fh.exists()) Gdx.app.log("file", "exists");
else Gdx.app.log("file", "not exists");
AssetDescriptor<Model> ad = new AssetDescriptor<Model>(fh, Model.class);
assets.load(ad);
Вывод:
I/file: exists
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load dependencies of asset: model.g3db
at com.badlogic.gdx.assets.AssetLoadingTask.handleAsyncLoader(AssetLoadingTask.java:121)
at com.badlogic.gdx.assets.AssetLoadingTask.update(AssetLoadingTask.java:90)
at com.badlogic.gdx.assets.AssetManager.updateTask(AssetManager.java:507)
at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:381)
at com.myapp.EngineCore.render(EngineCore.java:226)
at com.badlogic.gdx.backends.android.AndroidGraphicsLiveWallpaper.onDrawFrame(AndroidGraphicsLiveWallpaper.java:220)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1571)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.SerializationException: Error parsing file: model.g3db
at com.badlogic.gdx.utils.async.AsyncResult.get(AsyncResult.java:46)
at com.badlogic.gdx.assets.AssetLoadingTask.handleAsyncLoader(AssetLoadingTask.java:119)
at com.badlogic.gdx.assets.AssetLoadingTask.update(AssetLoadingTask.java:90)
at com.badlogic.gdx.assets.AssetManager.updateTask(AssetManager.java:507)
at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:381)
at com.nolesh.android.livewallpapers.iamrich.EngineCore.render(EngineCore.java:226)
at com.badlogic.gdx.backends.android.AndroidGraphicsLiveWallpaper.onDrawFrame(AndroidGraphicsLiveWallpaper.java:220)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1571)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270)
Caused by: com.badlogic.gdx.utils.SerializationException: Error parsing file: model.g3db
at com.badlogic.gdx.utils.UBJsonReader.parse(UBJsonReader.java:56)
at com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader.parseModel(G3dModelLoader.java:65)
at com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader.loadModelData(G3dModelLoader.java:61)
at com.badlogic.gdx.assets.loaders.ModelLoader.getDependencies(ModelLoader.java:75)
at com.badlogic.gdx.assets.loaders.ModelLoader.getDependencies(ModelLoader.java:35)
at com.badlogic.gdx.assets.AssetLoadingTask.call(AssetLoadingTask.java:64)
at com.badlogic.gdx.assets.AssetLoadingTask.call(AssetLoadingTask.java:34)
at com.badlogic.gdx.utils.async.AsyncExecutor$2.call(AsyncExecutor.java:58)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: model.g3db (Internal)
at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:77)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:151)
at com.badlogic.gdx.utils.UBJsonReader.parse(UBJsonReader.java:54)
at com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader.parseModel(G3dModelLoader.java:65)
at com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader.loadModelData(G3dModelLoader.java:61)
at com.badlogic.gdx.assets.loaders.ModelLoader.getDependencies(ModelLoader.java:75)
at com.badlogic.gdx.assets.loaders.ModelLoader.getDependencies(ModelLoader.java:35)
at com.badlogic.gdx.assets.AssetLoadingTask.call(AssetLoadingTask.java:64)
at com.badlogic.gdx.assets.AssetLoadingTask.call(AssetLoadingTask.java:34)
at com.badlogic.gdx.utils.async.AsyncExecutor$2.call(AsyncExecutor.java:58)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.io.FileNotFoundException: model.g3db
at android.content.res.AssetManager.openAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:374)
at android.content.res.AssetManager.open(AssetManager.java:348)
at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:75)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:151)
at com.badlogic.gdx.utils.UBJsonReader.parse(UBJsonReader.java:54)
at com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader.parseModel(G3dModelLoader.java:65)
at com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader.loadModelData(G3dModelLoader.java:61)
at com.badlogic.gdx.assets.loaders.ModelLoader.getDependencies(ModelLoader.java:75)
at com.badlogic.gdx.assets.loaders.ModelLoader.getDependencies(ModelLoader.java:35)
at com.badlogic.gdx.assets.AssetLoadingTask.call(AssetLoadingTask.java:64)
at com.badlogic.gdx.assets.AssetLoadingTask.call(AssetLoadingTask.java:34)
at com.badlogic.gdx.utils.async.AsyncExecutor$2.call(AsyncExecutor.java:58)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Когда я перемещаю эту модель в папку assets
моего проекта, онауспешно загружается.
Итак, мой вопрос, как загрузить модель в AssetManager
из локального хранилища.