flutter_3d_controller icon indicating copy to clipboard operation
flutter_3d_controller copied to clipboard

3D asset from files

Open farhodyusupov opened this issue 1 year ago • 5 comments

Hi. thank you for this awesome package. are there any ways to present 3D objects from file system?

farhodyusupov avatar Jun 02 '24 09:06 farhodyusupov

Hi, its good to hear that this package could help you, about the feature you mentioned, right now I only support loading 3D models from assets and url, but it may be possible to load models from file system, for example create file and passing file path as the model src, I have not test it it yet, if you have fixed it please share and feel free to create PR to package.

m-r-davari avatar Jun 04 '24 09:06 m-r-davari

hello, I am also interested in this way of displaying models from file system. I tried to use this code, but it gives me this exception: Flutter3DControllerFormatException: Cannot Parse the model source. versione package: flutter_3d_controller: ^2.0.2

Example code:

Directory appDocDir = await getApplicationDocumentsDirectory(); final filePath = '$appDocDir/flutter_dash.obj'; File file = File(filePath); .... Flutter3DViewer.obj( onProgress: (double progressValue) { debugPrint('model loading progress : $progressValue'); }, onLoad: (String modelAddress) { debugPrint('model loaded : $modelAddress'); }, onError: (String error) { debugPrint('model failed to load : $error'); }, src: '${file.path}', ),

MTMProject avatar Nov 25 '24 13:11 MTMProject

or maybe you could try my package? you can use it like an asset bundle but read files from an external location instead of a bundle.

https://github.com/rockingdice/external_asset_bundle

I don't have time to update it on pub.dev, so you guys probably need to use it from git directly.

rockingdice avatar Feb 14 '25 17:02 rockingdice

、、、 Future<String> downloadFile(String url, String fileName) async { final response = await http.get(Uri.parse(url)); if (response.statusCode == 200) { final dir = await getApplicationDocumentsDirectory(); final file = File('${dir.path}/$fileName'); await file.writeAsBytes(response.bodyBytes); return file.path; } else { throw Exception('Fail: ${response.statusCode}'); } }

          final path = await downloadFile("https://modelviewer.dev/shared-assets/models/Astronaut.glb", "Astronaut.glb");
          setState(() {
            srcGlb = "file://$path";
          });

、、、

The code written in this way is effective, I have verified it。 @MTMProject @m-r-davari

winter-tech avatar May 12 '25 03:05 winter-tech