JakubW
JakubW

Reputation: 1121

FileTextureProvider only loading files from "Internal"

I'm trying to load downloaded .zip files containing both .g3db and all required textures. It looks like the .g3db file is loading fine with loadModel() method. But as I can see the TextureProvider method called load() can only read Internal files.

Any ideas how to force ModelLoader to use only Absolute paths?

CODE

Loading Model

UBJsonReader jsonReader = new UBJsonReader();
G3dModelLoader modelLoader = new G3dModelLoader(jsonReader);
model = modelLoader.loadModel(Gdx.files.absolute(modelPath));

FileTextureProvider load() method

@Override
public Texture load (String fileName) {
    Texture result = new Texture(Gdx.files.internal(fileName), useMipMaps);
    result.setFilter(minFilter, magFilter);
    result.setWrap(uWrap, vWrap);
    return result;
}

Error when loading textures

Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: /data/user/0/com.app.sample/files/model/flower/flowerTextures.png (Internal)
                                                                                 at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:77)
                                                                                 at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:222)
                                                                                 at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:144)
                                                                                 at com.badlogic.gdx.graphics.TextureData$Factory.loadFromFile(TextureData.java:98) 
                                                                                 at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:100) 
                                                                                 at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:96) 
                                                                                 at com.badlogic.gdx.graphics.g3d.utils.TextureProvider$FileTextureProvider.load(TextureProvider.java:52) 
                                                                                 at com.badlogic.gdx.graphics.g3d.Model.convertMaterial(Model.java:292) 
                                                                                 at com.badlogic.gdx.graphics.g3d.Model.loadMaterials(Model.java:268) 
                                                                                 at com.badlogic.gdx.graphics.g3d.Model.load(Model.java:107) 
                                                                                 at com.badlogic.gdx.graphics.g3d.Model.<init>(Model.java:102) 
                                                                                 at com.badlogic.gdx.assets.loaders.ModelLoader.loadModel(ModelLoader.java:54) 
                                                                                 at com.badlogic.gdx.assets.loaders.ModelLoader.loadModel(ModelLoader.java:69) 
                                                                                 at com.app.sample.sdk.libgdx.ar.Display$2.call(Display.java:71) 
                                                                                 at com.app.sample.libgdx.ar.Display$2.call(Display.java:62) 
                                                                                 at rx.internal.operators.OnSubscribeFromCallable.call(OnSubscribeFromCallable.java:48) 
                                                                                 at rx.internal.operators.OnSubscribeFromCallable.call(OnSubscribeFromCallable.java:33) 
                                                                                 at rx.Observable.unsafeSubscribe(Observable.java:8460) 
                                                                                 at rx.internal.operators.OperatorSubscribeOn$1.call(OperatorSubscribeOn.java:94) 
                                                                                 at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker$1.call(CachedThreadScheduler.java:222) 
                                                                                 at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) 
                                                                                 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423) 
                                                                                 at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
                                                                                 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269) 
                                                                                 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
                                                                                 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
                                                                                 at java.lang.Thread.run(Thread.java:818) 
                                                                              Caused by: java.io.FileNotFoundException

Upvotes: 1

Views: 106

Answers (2)

JakubW
JakubW

Reputation: 1121

It turns out that you can use AssetManager to load files that are stored as internal data. The key to succes was to use AbsoluteFileHandleResolver().

This is how I load my Model from custom created folder inside application.

private Model loadModelFromFile(File file) {
    AssetManager assets = new AssetManager(new AbsoluteFileHandleResolver());
    assets.load(file.getPath(), Model.class);
    assets.finishLoading();
    return assets.get(file.getPath(), Model.class);
}

Upvotes: 1

Lucas B
Lucas B

Reputation: 348

It says that in the libgdx docs that for Android you need to have your assets either as a resource or in the assets folder. So there is no point in forcing the loader to use file paths if you have to have your assets in the assets folder for android.

https://github.com/libgdx/libgdx/wiki/File-handling

Upvotes: 0

Related Questions