3D asset from files
Hi. thank you for this awesome package. are there any ways to present 3D objects from file system?
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.
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}', ),
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.
、、、 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