diff --git a/thermion_dart/lib/src/filament/src/implementation/ffi_filament_app.dart b/thermion_dart/lib/src/filament/src/implementation/ffi_filament_app.dart index 376cb610..6691702e 100644 --- a/thermion_dart/lib/src/filament/src/implementation/ffi_filament_app.dart +++ b/thermion_dart/lib/src/filament/src/implementation/ffi_filament_app.dart @@ -1036,6 +1036,32 @@ class FFIFilamentApp extends FilamentApp { return FFIAsset(assetPtr, this, animationManager.cast()); } + /// + /// + /// + Future createDirectLight(DirectLight directLight) async { + var entity = + LightManager_createLight(engine, lightManager, directLight.type.index); + if (entity == FILAMENT_ASSET_ERROR) { + throw Exception("Failed to add light to scene"); + } + + LightManager_setColor(lightManager, entity, directLight.color); + LightManager_setIntensity(lightManager, entity, directLight.intensity); + LightManager_setPosition(lightManager, entity, directLight.position.x, + directLight.position.y, directLight.position.z); + LightManager_setDirection(lightManager, entity, directLight.direction.x, + directLight.direction.y, directLight.direction.z); + LightManager_setFalloff(lightManager, entity, directLight.falloffRadius); + LightManager_setSpotLightCone(lightManager, entity, + directLight.spotLightConeInner, directLight.spotLightConeOuter); + // LightManager_setSunAngularRadius(lightManager, entity, directLight.spotLightConeInner, directLight.spotLightConeOuter); + // LightManager_setSunHaloSize(lightManager, entity, directLight.spotLightConeInner, directLight.spotLightConeOuter); + // LightManager_setSunHaloFalloff(lightManager, entity, directLight.spotLightConeInner, directLight.spotLightConeOuter); + LightManager_setShadowCaster(lightManager, entity, directLight.castShadows); + return entity; + } + /// /// /// diff --git a/thermion_dart/lib/src/filament/src/interface/filament_app.dart b/thermion_dart/lib/src/filament/src/interface/filament_app.dart index 2ff823db..130c1016 100644 --- a/thermion_dart/lib/src/filament/src/interface/filament_app.dart +++ b/thermion_dart/lib/src/filament/src/interface/filament_app.dart @@ -306,6 +306,11 @@ abstract class FilamentApp { Future createGeometry(Geometry geometry, T animationManager, {List? materialInstances, bool keepData = false}); + /// + /// + /// + Future createDirectLight(DirectLight directLight); + /// /// /// diff --git a/thermion_dart/lib/src/viewer/src/ffi/src/thermion_viewer_ffi.dart b/thermion_dart/lib/src/viewer/src/ffi/src/thermion_viewer_ffi.dart index 1df715a5..55333424 100644 --- a/thermion_dart/lib/src/viewer/src/ffi/src/thermion_viewer_ffi.dart +++ b/thermion_dart/lib/src/viewer/src/ffi/src/thermion_viewer_ffi.dart @@ -318,32 +318,13 @@ class ThermionViewerFFI extends ThermionViewer { /// @override Future addDirectLight(DirectLight directLight) async { - var entity = LightManager_createLight( - app.engine, app.lightManager, directLight.type.index); - if (entity == FILAMENT_ASSET_ERROR) { - throw Exception("Failed to add light to scene"); - } - LightManager_setColor(app.lightManager, entity, directLight.color); - LightManager_setIntensity(app.lightManager, entity, directLight.intensity); - LightManager_setPosition(app.lightManager, entity, directLight.position.x, - directLight.position.y, directLight.position.z); - LightManager_setDirection(app.lightManager, entity, directLight.direction.x, - directLight.direction.y, directLight.direction.z); - LightManager_setFalloff( - app.lightManager, entity, directLight.falloffRadius); - LightManager_setSpotLightCone(app.lightManager, entity, - directLight.spotLightConeInner, directLight.spotLightConeOuter); - // LightManager_setSunAngularRadius(app.lightManager, entity, directLight.spotLightConeInner, directLight.spotLightConeOuter); - // LightManager_setSunHaloSize(app.lightManager, entity, directLight.spotLightConeInner, directLight.spotLightConeOuter); - // LightManager_setSunHaloFalloff(app.lightManager, entity, directLight.spotLightConeInner, directLight.spotLightConeOuter); - LightManager_setShadowCaster( - app.lightManager, entity, directLight.castShadows); + var light = await FilamentApp.instance!.createDirectLight(directLight); - Scene_addEntity(scene.scene, entity); + await scene.addEntity(light); - _lights.add(entity); + _lights.add(light); - return entity; + return light; } ///