Closed i-panov closed 3 years ago
Hi @i-panov, did you have a look at the Code example for loading models from the local file system and from online resources? As you can see in there, you have to place you model inside the flutter asset folder of your app (NOT the asset folder of the AR Flutter plugin), then you can simply provide the path to the ARNode
's uri
property and load the locally saved model.
Best
Lars
@CariusLars Yes, I looked at this particular example. This is the load from assets, and I need it from the phone's file system. For example, I downloaded the model and saved it to the folder that the get getApplicationDocumentsDirectory()
function returned. After that, I tried to pass the path to this model to the ArNode.uri
parameter, but I got an error "unable to load".
Hi @i-panov , sorry for the misunderstanding, now I get it! You're right, the plugin actually doesn't support loading from models from the device's file system, but that can be added easily. I suggest you fork the repo and add the function, it would be great if you could create a pull request afterwards so I can include it in the next release! Here are some pointers on how to do it:
fileSystemGltf
ARNode
's uri
property right away to pass to the ARModelBuilder's function makeNodeFromGltf
Let me know if you struggle at any point :)
Cheers Lars
It worked, thanks!
Nice! Would be really cool if you could open a pull request with the code you added so others in the community can profit from your contribution :)
I am facing the same issue. Have you rolled this into the last release?
I am trying to implement this myself but makeNodeFromGltf
is failing when I pass the path uri. I'm only working on an iOS implementation too so would it be worth joining forces to get this in? I need to do the snapshot
feature too, so would like to get this done ASAP.
When I pass the URI to the GLTFSceneSource
class it fails. The path string I am sending as the name
attribute is: /var/mobile/Containers/Data/Application/DC0F7267-7901-470D-A834-84B0E5B40FF1/Documents/statue.glb
so I'm not sure this line: Bundle.main.path(forResource: name, ofType: nil)
is handling that resource name properly.
@i-panov - how did you do this when you fixed the issue?
Any update ? i want to load glb model from my device but it's not working
ARNode(
name: "buggy"
type: NodeType.fileSystemAppFolderGLB,
uri: "path/to/buggy.glb",
scale: Vector3(0.1, 0.1, 0.1),
position: Vector3(0.0, 0.0, 0.0),
rotation: Vector4(1.0, 0.0, 0.0, 0.0),
);
this should work if your model is in localfolderofyourapplication/path/to/buggy.glb
. Where exactly is your model and what error do you get?
I'm using to filepicker to upload model. I'm sure it's not in local folder. i'm getting unable to load this model. So i can't load model from any folders ?
can you give an example for the exact path that you provide to the plugin and also the exact error message?
can you give an example for the exact path that you provide to the plugin and also the exact error message?
log message :
D/io.carius.lars.ar_flutter_plugin.AndroidARView(14468): AndroidARView onobjectmethodcall reveived a call!
E/ModelRenderable(14468): Unable to load Renderable registryId='/data/user/0/com.cart.app/app_flutter//data/user/0/com.cart.app/cache/file_picker/Duck.glb'
E/ModelRenderable(14468): java.util.concurrent.CompletionException: java.util.concurrent.CompletionException: java.io.FileNotFoundException: /data/user/0/com.cart.app/app_flutter/data/user/0/com.cart.app/cache/file_picker/Duck.glb: open failed: ENOENT (No such file or directory)
E/ModelRenderable(14468): at com.google.ar.sceneform.utilities.SceneformBufferUtils.inputStreamToByteBuffer(SourceFile:48)
E/ModelRenderable(14468): at com.google.ar.sceneform.rendering.LoadRenderableFromSfbTask.lambda$downloadAndProcessRenderable$0$LoadRenderableFromSfbTask(LoadRenderableFromSfbTask.java:118)
E/ModelRenderable(14468): at com.google.ar.sceneform.rendering.LoadRenderableFromSfbTask$$ExternalSyntheticLambda7.get(Unknown Source:4)
E/ModelRenderable(14468): at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1627)
E/ModelRenderable(14468): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/ModelRenderable(14468): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/ModelRenderable(14468): at java.lang.Thread.run(Thread.java:919)
E/ModelRenderable(14468): Caused by: java.util.concurrent.CompletionException: java.io.FileNotFoundException: /data/user/0/com.cart.app/app_flutter/data/user/0/com.cart.app/cache/file_picker/Duck.glb: open failed: ENOENT (No such file or directory)
E/ModelRenderable(14468): at com.google.ar.sceneform.assets.RenderableSource.downloadUri(Unknown Source:26)
E/ModelRenderable(14468): at com.google.ar.sceneform.assets.RenderableSource.call(Unknown Source:33)
E/ModelRenderable(14468): at com.google.ar.sceneform.assets.RenderableSource.call(Unknown Source:0)
E/ModelRenderable(14468): at com.google.ar.sceneform.utilities.SceneformBufferUtils.inputStreamToByteBuffer(SourceFile:42)
E/ModelRenderable(14468): ... 6 more
E/ModelRenderable(14468): Caused by: java.io.FileNotFoundException: /data/user/0/com.cart.app/app_flutter/data/user/0/com.cart.app/cache/file_picker/Duck.glb: open failed: ENOENT (No such file or directory)
E/ModelRenderable(14468): at libcore.io.IoBridge.open(IoBridge.java:496)
E/ModelRenderable(14468): at java.io.FileInputStream.<init>(FileInputStream.java:159)
Path:
/data/user/0/com.cart.app/app_flutter//data/user/0/com.cart.app/cache/file_picker/Duck.glb
Node type:
NodeType.fileSystemAppFolderGLB
ah I see, thanks for the logs!
can you get the file picker to place the model into the app_flutter part of your app's storage instead of the cache part? loading models from cache doesn't seem to work with this nodetype, the model should rather be saved to /data/user/0/com.cart.app/app_flutter/file_picker/Duck.glb
and can then be loaded by passing just file_picker/Duck.glb
to the constructor of the ARNode
@CariusLars I've seen the example. got the file from file picker and created a file in path from getApplicationDocumentsDirectory
. But still i'm getting unable to load the model
why ?
Snippet:
Directory appDocDir = await getApplicationDocumentsDirectory();
String fileName = result.files.single.name; // duck.glb
File file = File("${appDocDir.path}/$fileName");
await file.create();
current path : /data/data/com.demo.app/app_flutter/Duck.glb
Update : As in the example folder i tried with file.writeasbytes . Still same issue
String fileName = result.files.single.name; // duck.glb
var bytes = result.files.single.bytes; // unit8list
File file = File("${appDocDir.path}/$fileName");
await file.writeAsBytes(bytes!);
var newNode = ARNode(
name: "duck"
type: NodeType.fileSystemAppFolderGLB,
uri: file.path, // /data/data/com.demo.app/app_flutter/Duck.glb
scale: Vector3(0.5, 0.5, 0.5),
position: Vector3(0.0, 0.0, 0.0),
rotation: Vector4(1.0, 0.0, 0.0, 0.0),
);
Figured out . The problem is i was adding the whole path . Now it's working
ARNode(
type: NodeType.fileSystemAppFolderGLB,
uri: fileName, // duck.glb
scale: Vector3(0.5, 0.5, 0.5),
position: Vector3(0.0, 0.0, 0.0),
rotation: Vector4(1.0, 0.0, 0.0, 0.0),
);
This wont work for me...
I keep getting "Unable to load renderable"
#
This wont work for me...
I keep getting "Unable to load renderable"
Me too. Any solutions to this ?
Hello! Please tell me how to load the model saved to the device?
ArNode.uri
supports only assets and links.