loadEnvironment method
Method to load the environment from assets or network URLs.
Implementation
@override
Future<void> loadEnvironment({
String? iblPath,
String? iblUrl,
String? skyboxPath,
String? skyboxUrl,
}) async {
Uint8List? iblBytes;
Uint8List? skyboxBytes;
try {
if (iblPath != null) {
ByteData iblData = await rootBundle.load(iblPath);
iblBytes = iblData.buffer.asUint8List();
} else if (iblUrl != null) {
final response = await http.get(Uri.parse(iblUrl));
if (response.statusCode == 200) {
iblBytes = response.bodyBytes;
} else {
debugPrint('Failed to load IBL from $iblUrl: ${response.statusCode}');
}
}
} catch (e) {
debugPrint('Error loading IBL: $e');
}
try {
if (skyboxPath != null) {
ByteData skyboxData = await rootBundle.load(skyboxPath);
skyboxBytes = skyboxData.buffer.asUint8List();
} else if (skyboxUrl != null) {
final response = await http.get(Uri.parse(skyboxUrl));
if (response.statusCode == 200) {
skyboxBytes = response.bodyBytes;
} else {
debugPrint('Failed to load skybox from $skyboxUrl: ${response.statusCode}');
}
}
} catch (e) {
debugPrint('Error loading skybox: $e');
}
if (iblBytes == null || skyboxBytes == null) {
throw Exception('Failed to load environment: iblBytes or skyboxBytes is null');
}
await _methodChannel.invokeMethod('loadEnvironment', {
'iblBytes': iblBytes,
'skyboxBytes': skyboxBytes,
});
}