fromAsset method
asset
- path of the file to be loaded
package
- if the file is from another flutter package add the name of the package here
Implementation
@override
Future<ThreeFile?> fromAsset(String asset, {String? package}) async{
asset = package != null?'packages/$package/${path+asset}':path+asset;
asset = manager.resolveURL(asset);
final cacheName = asset;
final cached = Cache.get(cacheName);
if (cached != null) {
manager.itemStart(cacheName);
manager.itemEnd(cacheName);
return ThreeFile('bytes',cached,'cache');
}
try{
ByteData fileData = await rootBundle.load(asset);
final bytes = fileData.buffer.asUint8List();
Cache.add(cacheName,bytes);
return ThreeFile('asset',bytes,asset);
}
catch(e){
console.error('ThreeJS error: $e');
return null;
}
}