CariusLars / ar_flutter_plugin

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

How read .glb model from assets? #82

Open samatzp opened 2 years ago

samatzp commented 2 years ago

Hey!

I show "unable load renderableassets" error but webGLB work fine)

2022-01-27_19-33-21

2022-01-27_19-33-10

2022-01-27_19-33-29

ImHitL3r commented 2 years ago

did you find any way to load local .glb files im gettin same error as you "unable to load"

huayun502 commented 2 years ago

+1

KennyChan94P commented 2 years ago

have you resolved this yet? i have the error only when im loading the GLB model on ANDROID Unable to load Renderable registryId='path/my_assets.glb' "Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 21" i tried validating my GLB at https://github.khronos.org/glTF-Validator/ and i got "The asset is valid."

SapinderSingh commented 1 year ago

+1

utkarshjaiswal0004 commented 1 year ago

it's an open issue. +1

GoodMorrrrning commented 1 year ago

hi, i have the exact same problem, there is a solution for this please ? :)

rakotoleonce2106 commented 1 year ago

for me all local objects are not displayed, there is always the error, "Unable to load renderable", on ios.

marcoabat commented 1 year ago

Same issue, even with GLTF's. "Unable to load renderable".

rakotoleonce commented 1 year ago

I clone this package in my project and I make changes in this package, if you use url directly, it can display. But if you use assets or path_provider, this that the problem displays. because the path does not see with the native.

LiamMcMainsBR commented 1 year ago

I ran into the same issue on Android.

I was able to get it working though, through a workaround.

Basically, you can copy the contents of your flutter assets folder to the applications documents directory, and then load the models from there instead of directly from assets.

Here is some sample code for how to achieve it:

Future<void> copyAssetModelsToDocumentDirectory() async {
  // CHANGE THESE TO YOUR ASSET FILES
  List<String> filesToCopy = ["assets/test.glb", "assets/test2.glb"];

  // This getApplicationDocumentsDirectory call comes from the path_provider package
  final Directory docDir = await getApplicationDocumentsDirectory();
  final String docDirPath = docDir.path;

  await Future.wait(
    filesToCopy.map((String assetPath) async {
      // Create a new file in the documents directory with the asset file name
      String assetFilename = assetPath.split('/').last;
      File file = File('$docDirPath/$assetFilename');

      // Load the asset file from the assets folder
      final assetBytes = await rootBundle.load(assetPath);
      final buffer = assetBytes.buffer;

      // Write the asset file to the new file in the documents directory
      await file.writeAsBytes(
        buffer.asUint8List(
          assetBytes.offsetInBytes,
          assetBytes.lengthInBytes,
        ),
      );

      print("Copied $assetPath to ${file.path}");
    }),
  );

  print("Finished copying files to app's documents directory");
}

You should get output that looks something like this:

I/flutter (28853): Copied assets/tisch.glb to /data/user/0/com.example.flutter_ar/app_flutter/tisch.glb
I/flutter (28853): Copied assets/wooden_stool.glb to /data/user/0/com.example.flutter_ar/app_flutter/wooden_stool.glb
I/flutter (28853): Copied assets/wooden_stick.glb to /data/user/0/com.example.flutter_ar/app_flutter/wooden_stick.glb
I/flutter (28853): Copied assets/chair2.glb to /data/user/0/com.example.flutter_ar/app_flutter/chair2.glb
I/flutter (28853): Copied assets/wooden_chair.glb to /data/user/0/com.example.flutter_ar/app_flutter/wooden_chair.glb
I/flutter (28853): Finished copying files to app's documents directory

Then, make sure to call copyAssetModelsToDocumentDirectory when the ARView initializes, before you initialize your sessionManager and objectManager:

ARView(
  onARViewCreated: (
    ARSessionManager arSessionManager,
    ARObjectManager arObjectManager,
    ARAnchorManager arAnchorManager,
    ARLocationManager arLocationManager,
  ) async {
    await copyAssetModelsToDocumentDirectory();

    // The rest of your initialization code
  },
)

And each time you create a new ARNode, make sure to use the type: NodeType.fileSystemAppFolderGLB

That worked for me on both Android and iOS. If you aren't seeing them, make sure your scale is set correctly because sometimes they can be way too big or way too small. Hopefully this helps someone else!

nayanAubie commented 1 year ago

@LiamMcMainsBR I've used the solution exactly you mentioned above. But it's not working on my end. showing "unable to load renderable"

KaustubhVaidya404 commented 5 months ago
wm-jenildgohel commented 5 months ago

i am getting an exect issue with the glb and gltf both assets even though both files are valid

staminna commented 3 months ago

A Dart VM Service on SM G991B is available at: http://... I/BLASTBufferQueue_Java(19826): update, w= 1080 h= 2400 mName = ViewRootImpl@ee2a700[MainActivity] mNativeObject= 0xb40000795951c530 sc.mNativeObject= 0xb4000077e950e790 format= -3 caller= android.view.ViewRootImpl.updateBlastSurfaceIfNeeded:2968 android.view.ViewRootImpl.relayoutWindow:9998 android.view.ViewRootImpl.performTraversals:4056 android.view.ViewRootImpl.doTraversal:3239 android.view.ViewRootImpl$TraversalRunnable.run:11197 android.view.Choreographer$CallbackRecord.run:1650 I/ViewRootImpl@ee2a700MainActivity: Relayout returned: old=(0,0,1080,2400) new=(0,0,1080,2400) req=(1080,2400)0 dur=4 res=0x401 s={true 0xb40000778956d180} ch=false seqId=0 I/ViewRootImpl@ee2a700MainActivity: updateBoundsLayer: t=android.view.SurfaceControl$Transaction@17896ea sc=Surface(name=Bounds for - com.example.test/com.example.test.MainActivity@0)/@0x14fbddb frame=1 D/ViewRootImpl@ee2a700MainActivity: reportNextDraw android.view.ViewRootImpl.performTraversals:4658 android.view.ViewRootImpl.doTraversal:3239 android.view.ViewRootImpl$TraversalRunnable.run:11197 android.view.Choreographer$CallbackRecord.run:1650 android.view.Choreographer$CallbackRecord.run:1659 D/io.carius.lars.ar_flutter_plugin.AndroidARView(19826): Initializing AndroidARView D/SurfaceView(19826): 130103222 setFixedSize -1x-1 -> 0x0 I/Filament(19826): Filament library loaded. E/Filament(19826): Error opening trace file: No such file or directory (2) I/BLASTBufferQueue(19826): SurfaceView[com.example.test/com.example.test.MainActivity]@0#1 onFrameAvailable the first frame is available I/Filament(19826): FEngine (64 bits) created at 0xb4000076c73f5c00 (threading is enabled) D/Filament(19826): Using ASurfaceTexture D/Filament(19826): FEngine resolved backend: OpenGL I/SceneView(19826): Optional library com.google.ar.sceneform.animation loaded. D/io.carius.lars.ar_flutter_plugin.AndroidARView(19826): ARSceneView session is null. Trying to initialize I/third_party/arcore/ar/core/android/sdk/session_create.cc(19826): Entering ArSession_createWithFeatures I/third_party/arcore/ar/core/android/sdk/session_create.cc(19826): ARCore Version: SDK build name: 1.22 I/third_party/arcore/ar/core/android/sdk/session_create.cc(19826): ARCore Version: APK version code: 240360593