CariusLars / ar_flutter_plugin

Flutter Plugin for AR (Augmented Reality) - Supports ARKit on iOS and ARCore on Android devices
MIT License
322 stars 233 forks source link

Can't load models from local storage #72

Open hman-coder opened 2 years ago

hman-coder commented 2 years ago

While trying to load my own gtlf model, an "Unable to load renderable [assetLocation]" snackbar pops up, and an exception is printed into the console. I thought maybe it was the model itself, so I substituted it for the Chicken model in one of the example projects only to get the same exception. I double checked pubspec.yaml for correct asset path declaration.

It is working swimmingly when using web models.

Code is identical to the one in LocalAndWebObjectsWidget in the example project (after fixing null safety issues).

No issues with flutter doctor.

[√] Flutter (Channel stable, 2.5.3, on Microsoft Windows [Version 10.0.19043.1320], locale en-AE)
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[√] Chrome - develop for the web
[√] Android Studio (version 2020.3)
[√] IntelliJ IDEA Community Edition (version 2021.2)
[√] VS Code (version 1.63.2)
[√] Connected device (3 available)

Exception

I/BufferQueueProducer(21345): [ImageReader-640x480f23u3m16-21345-5](this:0x77bafb9000,id:8,api:4,p:614,c:21345) queueBuffer: fps=29.68 dur=1010.75 max=39.46 min=27.91
D/BufferQueueProducer(21345): [SurfaceTexture-0-21345-2](this:0x77bc8db800,id:7,api:1,p:540,c:21345) cancelBuffer: slot 1
D/BufferQueueProducer(21345): [SurfaceTexture-0-21345-2](this:0x77bc8db800,id:7,api:1,p:540,c:21345) cancelBuffer: slot 0
D/io.carius.lars.ar_flutter_plugin.AndroidARView(21345): AndroidARView onobjectmethodcall reveived a call!
E/ModelRenderable(21345): Unable to load Renderable registryId='flutter_assets/Models/Chicken_01/Chicken_01.gltf'
E/ModelRenderable(21345): java.util.concurrent.CompletionException: java.util.concurrent.CompletionException: java.io.FileNotFoundException: flutter_assets/Models/Chicken_01/Chicken_01.gltf (No such file or directory)
E/ModelRenderable(21345):   at com.google.ar.sceneform.utilities.SceneformBufferUtils.inputStreamToByteBuffer(SourceFile:48)
E/ModelRenderable(21345):   at com.google.ar.sceneform.rendering.LoadRenderableFromSfbTask.lambda$downloadAndProcessRenderable$0$LoadRenderableFromSfbTask(LoadRenderableFromSfbTask.java:118)
E/ModelRenderable(21345):   at com.google.ar.sceneform.rendering.-$$Lambda$LoadRenderableFromSfbTask$A8YYsoT3V_A--F80fBJ_ZLNSnhc.get(Unknown Source:4)
E/ModelRenderable(21345):   at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1625)
E/ModelRenderable(21345):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/ModelRenderable(21345):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/ModelRenderable(21345):   at java.lang.Thread.run(Thread.java:764)
E/ModelRenderable(21345): Caused by: java.util.concurrent.CompletionException: java.io.FileNotFoundException: flutter_assets/Models/Chicken_01/Chicken_01.gltf (No such file or directory)
E/ModelRenderable(21345):   at com.google.ar.sceneform.assets.RenderableSource.downloadUri(Unknown Source:26)
E/ModelRenderable(21345):   at com.google.ar.sceneform.assets.RenderableSource.call(Unknown Source:53)
E/ModelRenderable(21345):   at com.google.ar.sceneform.assets.RenderableSource.call(Unknown Source:0)
E/ModelRenderable(21345):   at com.google.ar.sceneform.utilities.SceneformBufferUtils.inputStreamToByteBuffer(SourceFile:42)
E/ModelRenderable(21345):   ... 6 more
E/ModelRenderable(21345): Caused by: java.io.FileNotFoundException: flutter_assets/Models/Chicken_01/Chicken_01.gltf (No such file or directory)
E/ModelRenderable(21345):   at java.io.FileInputStream.open0(Native Method)
E/ModelRenderable(21345):   at java.io.FileInputStream.open(FileInputStream.java:231)
E/ModelRenderable(21345):   at java.io.FileInputStream.<init>(FileInputStream.java:165)
E/ModelRenderable(21345):   at com.google.ar.sceneform.utilities.LoadHelper.lambda$fileUriToInputStreamCreator$1$LoadHelper(SourceFile:128)
E/ModelRenderable(21345):   at com.google.ar.sceneform.utilities.a.call(Unknown Source:6)
E/ModelRenderable(21345):   at com.google.ar.sceneform.assets.RenderableSource.downloadUri(Unknown Source:13)
E/ModelRenderable(21345):   ... 9 more
I/BufferQueueProducer(21345): [SurfaceTexture-0-21345-2](this:0x77bc8db800,id:7,api:1,p:540,c:21345) queueBuffer: slot 2 is dropped, handle=0x781874f400
I/flutter (21345): [Unable to load renderableModels/Chicken_01/Chicken_01.gltf]
D/BufferQueueProducer(21345): [SurfaceTexture-0-21345-2](this:0x77bc8db800,id:7,api:1,p:540,c:21345) cancelBuffer: slot 2
I/BufferQueueProducer(21345): [SurfaceTexture-0-21345-2](this:0x77bc8db800,id:7,api:1,p:540,c:21345) queueBuffer: fps=29.59 dur=1047.61 max=67.62 min=16.23

pubspec.yaml

....
  assets:
    - images/triangle.png
    - Models/Chicken_01/
....

Project file structure, just to make sure.

EDIT:

Code

  // Called on button press.
  Future<void> onLocalObjectAtOriginButtonPressed() async {
    clearAllObjects(); // Clears all objects in arObjectManager

    var newNode = ARNode(
      type: NodeType.localGLTF2, // also tried NodeType.fileSystemAppFolderGLTF2,
      uri: "Chicken_01.gltf", // also tried "Models/Chicken_01/Chicken_01.gltf"
      scale: vector.Vector3(0.2, 0.2, 0.2),
      rotation: vector.Vector4(1.0, 0.0, 0.0, 0.0),
      transformation: myTransformation,
    );
    bool didAddLocalNode = await arObjectManager.addNode(newNode) ?? false;
    testNodes.local = (didAddLocalNode) ? newNode : null;
  }
CariusLars commented 2 years ago

can you share the exact code you are using to pass the path to the plugin?

hman-coder commented 2 years ago

can you share the exact code you are using to pass the path to the plugin?

I've updated the question with the relevant code.

CariusLars commented 2 years ago

you should definitely use Models/Chicken_01/Chicken_01.gltf (the version you commented out), does this give the same error? and is the Models folder in the actual app folder (make sure it's not accidentally in the plugin's parent folder)?

If it still doesn't work, you should set some debug points and examine the device's storage to see if the files are actually compiled into the app

hman-coder commented 2 years ago

I tried both uris and they are giving the same Exception. Regarding whether Models is in the app folder or not, I linked an image in the OP showing the project file structure. It is in the app folder. The weird thing is, when I use "images/triangle.png" for marking planes it is not producing that import exception - so I don't think it's a problem of the assets not compiling into the device storage.

I will do those debug points, however, and get back to you

nauval123 commented 2 years ago

i can use the model,but i use the File widget and get the path from my modal's,then it did appear

lore-co commented 2 years ago

Same for me, when I try to load custom .glb or .gftl objects Arkit won't show them and just place the node. No error seems to be thrown neither in dart code or native swift code. Managed to render an arrow glb model, but nothing else, meanwhile Arcore renders all the models without any problem.

P.s. the arrow loads but the lighting looks very dark, practically obscuring the model's color.

CariusLars commented 2 years ago

can you check the models that don't load with the glTF Validator or try them in a pure ARKit app? The native frameworks often struggle to load models that are not up to the standard which is a likely cause that it loads in ARCore but not ARKit

lore-co commented 2 years ago

can you check the models that don't load with the glTF Validator or try them in a pure ARKit app? The native frameworks often struggle to load models that are not up to the standard which is a likely cause that it loads in ARCore but not ARKit

Strange thing is that the Validator gives me green light with the models I struggle to load. I'm currently trying to load them on a pure ARKit app and will tell you how it goes. Still it would be great to tell beforehand if the selected model can be loaded by arkit to avoid the final user this kind of experiences

lore-co commented 2 years ago

can you check the models that don't load with the glTF Validator or try them in a pure ARKit app? The native frameworks often struggle to load models that are not up to the standard which is a likely cause that it loads in ARCore but not ARKit

It looks like a lot of the models I'm failing to load are shown in a native 3d models app like they are totally white/colourless, and the flutter app loads them but they just seems to be transparent. Do you know any native AR app with which I can test the models? I found some but most are not free.

CariusLars commented 2 years ago

I've used an adaption of this ARKit sample app before and I've modified it so it can load glb models, if you send me an email at lars@carius.io I can send you the modified project as a zip file :)

lore-co commented 2 years ago

I've used an adaption of this ARKit sample app before and I've modified it so it can load glb models, if you send me an email at lars@carius.io I can send you the modified project as a zip file :)

Hey Lars, first thing first let me thank you for the support and the dedication you are showing for the project. I tried the sample native app you passed me and I managed loading all models I passed it that I failed loading in its flutter counter part. While the lightining seemed a bit off too in the sample app, the models shows correctly. If you want I can pass you more files to test for yourself :)

CariusLars commented 2 years ago

hm that's really annoying that it doesn't work in this package! Can you send me the models so I can try it myself?

lore-co commented 2 years ago

hm that's really annoying that it doesn't work in this package! Can you send me the models so I can try it myself?

I've sent you the models with WeTransfer, you'll notice that I put in some working models along with the non working ones! The arrow, in particular, is loading, but the ligthing seems quite off (the model is green).

kishaningithub commented 1 year ago

I am also facing the exact same issue in android @lore-co @CariusLars should i add or update some permission for android? what was the fix/workaround you found for this?

sudo-ulmas commented 4 months ago

This problem is still there, did anyone managed to solve it?

staminna commented 4 months ago

I was able to copy the file but not display it, at least on my Android 14. I/flutter ( 6000): Copied assets/animation.glb to /data/user/0/com.example.test/app_flutter/animation.glb I/flutter ( 6000): Finished copying files to app's documents directory