CariusLars / ar_flutter_plugin

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

Out of mem issue #34

Closed lecanhhiep closed 3 years ago

lecanhhiep commented 3 years ago

Hi,

Our model file is over 50MB and in GLD format that it always throw out of mem exception when loading the model.

Do you have any idea to help us fix it? (setting android:largeHeap="true" is the same).

We have tried by converting that GLD file to GLTF format, and it works fine. But it seems it only work when we put the GLTF file to asset folder. If we change to use custom file location, it throws File not found exception. Do you have any idea to fix it?

Really appreciate for your help!

CariusLars commented 3 years ago

Hi @lecanhhiep, GLD is currently not supported by the plugin, so you have to use GLB or GLTF. Does it also throw the out of memory error when you use that format? When you use "custom file location", where exactly do you put the model file and how do you pass the path to the ARNode constructor?

lecanhhiep commented 3 years ago

Hi @CariusLars

Thank you so much for your response :)

This is my code:

  Directory tempDir = await getTemporaryDirectory();
  String tempPath = tempDir.path;
  print("tempPathtempPathtempPathtempPathtempPath: " + tempPath);

  await Utils.downloadFile(Constants. AR_URL   +  "Chicken_01.zip", tempPath, "Chicken_01.zip");
  print("downloadede downloadede downloadede : " + tempPath );

  final zipFile = File(tempDir.path + "/Chicken_01.zip");
  final destinationDir = Directory(tempPath);
  try {
    ZipFile.extractToDirectory(zipFile: zipFile, destinationDir: destinationDir);
    print("extractedextractedextractedextracted: " + zipFile.uri.toString() );
  } catch (e) {
    print ("Exception unzipException unzipException unzipException unzip");
    print(e);
  }

  var newNode = ARNode(
      type: NodeType.localGLTF2,
      uri: tempDir.uri.toString() + "Chicken_01.gltf",
      scale: Vector3(0.2, 0.2, 0.2),
      position: Vector3(0.0, 0.0, 0.0),
      rotation: Vector4(1.0, 0.0, 0.0, 0.0));
  bool? didAddLocalNode = await this.arObjectManager?.addNode(newNode);
  this.localObjectNode = (didAddLocalNode!) ? newNode : null;
}

Chicken_01.zip contains Chicken_01.gltf and Chicken_01.bin and was put on server. There is code to download that zip file and extract to temp folder like that.

The exception is: Unable to load Renderable registryId='flutter_assets/file:///data/user/0/com.

Thanks and waiting for your reply.

CariusLars commented 3 years ago

Thanks for the code @lecanhhiep . The problem is that right now, the plugin can only load models from the local storage that are compiled into the app bundle. I'm currently working on loading from the app's document directory (which can be retrieved and saved to by calling getApplicationDocumentsDirectory(); instead of getTemporaryDirectory();. The code is still on a feature branch (https://github.com/CariusLars/ar_flutter_plugin/tree/feature/filesystemassets), but I'll merge it into main in the next few days so you can then use it for your code. If you need it right now, you can also base you project on this feature branch until it gets merged, but currently you would have to use .glb models, .gltf doesn't work yet

lecanhhiep commented 3 years ago

Thank you so much!

CariusLars commented 3 years ago

The functionality (loading both GLB and GLTF models from the app's local memory that can be queried by flutter using getApplicationDocumentsDirectory();) is now on the Develop Branch, including samples for both downloading GLBs and downloading zip files like you did and extracting them in the file localandwebobjectsexample.dart. The features will probably make it into the main branch within a week, but until then you could just use the develop branch.

CariusLars commented 3 years ago

The functionality (loading both GLB and GLTF models from the app's local memory that can be queried by flutter using getApplicationDocumentsDirectory();) is now on the Develop Branch, including samples for both downloading GLBs and downloading zip files like you did and extracting them in the file localandwebobjectsexample.dart. The features will probably make it into the main branch within a week, but until then you could just use the develop branch.

just published v0.5.0 which contains the changes described

lecanhhiep commented 3 years ago

Thank you so much @CariusLars it works perfect!