add loadIblFromTexture method

This commit is contained in:
Nick Fisher
2025-06-17 11:51:07 +08:00
parent 288acb019e
commit 71bae61015
2 changed files with 47 additions and 25 deletions

View File

@@ -288,40 +288,55 @@ class ThermionViewerFFI extends ThermionViewer {
/// ///
/// ///
@override @override
Future loadIbl(String lightingPath, {double intensity = 30000}) async { Future loadIbl(String lightingPath, {double intensity = 30000, bool destroyExisting= true}) async {
await removeIbl(); await removeIbl(destroy:destroyExisting);
final completer = Completer(); final completer = Completer();
_iblTextureUploadComplete = _iblTextureUploadComplete =
withVoidCallback((requestId, onTextureUploadComplete) async { withVoidCallback((requestId, onTextureUploadComplete) async {
late Pointer stackPtr; late Pointer stackPtr;
if (FILAMENT_WASM) { if (FILAMENT_WASM) {
//stackPtr = stackSave(); //stackPtr = stackSave();
} }
var data = await FilamentApp.instance!.loadResource(lightingPath); var data = await FilamentApp.instance!.loadResource(lightingPath);
final bundle = await FFIKtx1Bundle.create(data); final bundle = await FFIKtx1Bundle.create(data);
final texture = await bundle.createTexture(); final texture = await bundle.createTexture();
final harmonics = bundle.getSphericalHarmonics(); final harmonics = bundle.getSphericalHarmonics();
final ibl = await FFIIndirectLight.fromIrradianceHarmonics(harmonics, final ibl = await FFIIndirectLight.fromIrradianceHarmonics(
harmonics,
reflectionsTexture: texture,
intensity: intensity,
);
await scene.setIndirectLight(ibl);
if (FILAMENT_WASM) {
//stackRestore(stackPtr);
data.free();
}
data.free();
completer.complete();
}).then((_) {
_iblTextureUploadComplete = null;
});
await completer.future;
}
///
///
///
Future loadIblFromTexture(Texture texture, { double intensity = 30000, bool destroyExisting = true}) async {
await removeIbl(destroy: destroyExisting);
final ibl = await FFIIndirectLight.fromIrradianceTexture(texture,
reflectionsTexture: texture, intensity: intensity); reflectionsTexture: texture, intensity: intensity);
await scene.setIndirectLight(ibl); await scene.setIndirectLight(ibl);
if (FILAMENT_WASM) {
//stackRestore(stackPtr);
data.free();
}
data.free();
completer.complete();
}).then((_) {
_iblTextureUploadComplete = null;
});
await completer.future;
} }
/// ///

View File

@@ -97,7 +97,14 @@ abstract class ThermionViewer {
/// Creates an indirect light by loading the reflections/irradiance from the KTX file. /// Creates an indirect light by loading the reflections/irradiance from the KTX file.
/// Only one indirect light can be active at any given time; if an indirect light has already been loaded, it will be replaced. /// Only one indirect light can be active at any given time; if an indirect light has already been loaded, it will be replaced.
/// ///
Future loadIbl(String lightingPath, {double intensity = 30000}); Future loadIbl(String lightingPath,
{double intensity = 30000, bool destroyExisting = true});
///
///
///
Future loadIblFromTexture(Texture texture,
{double intensity = 30000, bool destroyExisting = true});
/// ///
/// Rotates the IBL & skybox. /// Rotates the IBL & skybox.