loadTexture function
load texture from asset
Implementation
Future<MapEntry<String, Image>?> loadTexture(Material? material, String basePath, {bool isAsset = true}) async {
// get the texture file name
bool makeGray = false;
if (material == null) return null;
String fileName = material.mapKa;
if (fileName == '') fileName = material.mapKd;
if (fileName == ''){
fileName = material.mapBump;
makeGray = true;
}
if (fileName == '') return null;
// try to load image from asset in subdirectories
Image? image;
final List<String> dirList = fileName.split(RegExp(r'[/\\]+'));
while (dirList.isNotEmpty) {
fileName = path.join(basePath, path.joinAll(dirList));
try {
image = await loadImageFromAsset(fileName, isAsset: isAsset, makeGray: makeGray);
} catch (_) {}
if (image != null) return MapEntry(fileName, image);
dirList.removeAt(0);
}
return null;
}