add web support for light changes

This commit is contained in:
Nick Fisher
2024-05-21 13:34:57 +08:00
parent 139c191a8a
commit 26f0c4a5b4
4 changed files with 45 additions and 9 deletions

View File

@@ -88,10 +88,31 @@ class DartFilamentJSExportViewer {
double dirX, double dirX,
double dirY, double dirY,
double dirZ, double dirZ,
double falloffRadius,
double spotLightConeInner,
double spotLightConeOuter,
double sunAngularRadius,
double sunHaloSize,
double sunHaloFallof,
bool castShadows) { bool castShadows) {
return viewer return viewer
.addLight(type, colour, intensity, posX, posY, posZ, dirX, dirY, dirZ, .addLight(
castShadows) LightType.values[type],
colour,
intensity,
posX,
posY,
posZ,
dirX,
dirY,
dirZ,
falloffRadius:falloffRadius,
spotLightConeInner:spotLightConeInner,
spotLightConeOuter: spotLightConeOuter,
sunAngularRadius: sunAngularRadius,
sunHaloSize: sunHaloSize,
sunHaloFallof: sunHaloFallof,
castShadows: castShadows)
.then((entity) => entity.toJS) .then((entity) => entity.toJS)
.toJS; .toJS;
} }

View File

@@ -63,7 +63,13 @@ extension type DartFilamentJSShim(JSObject _) implements JSObject {
double dirX, double dirX,
double dirY, double dirY,
double dirZ, double dirZ,
bool castShadows, double falloffRadius,
double spotLightConeInner,
double spotLightConeOuter,
double sunAngularRadius,
double sunHaloSize,
double sunHaloFallof,
bool castShadows
); );
@JS('removeLight') @JS('removeLight')

View File

@@ -1,5 +1,6 @@
import 'dart:js_interop'; import 'dart:js_interop';
import 'dart:js_interop_unsafe'; import 'dart:js_interop_unsafe';
import 'dart:math';
import 'package:animation_tools_dart/animation_tools_dart.dart'; import 'package:animation_tools_dart/animation_tools_dart.dart';
import 'package:dart_filament/dart_filament/abstract_filament_viewer.dart'; import 'package:dart_filament/dart_filament/abstract_filament_viewer.dart';
@@ -103,7 +104,7 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
@override @override
Future<FilamentEntity> addLight( Future<FilamentEntity> addLight(
int type, LightType type,
double colour, double colour,
double intensity, double intensity,
double posX, double posX,
@@ -112,10 +113,18 @@ class JsInteropFilamentViewer implements AbstractFilamentViewer {
double dirX, double dirX,
double dirY, double dirY,
double dirZ, double dirZ,
bool castShadows) async { {
double falloffRadius=1.0,
double spotLightConeInner=pi/8,
double spotLightConeOuter=pi/4,
double sunAngularRadius=0.545,
double sunHaloSize=10.0,
double sunHaloFallof=80.0,
bool castShadows=true
}) async {
return (await _jsObject return (await _jsObject
.addLight(type, colour, intensity, posX, posY, posZ, dirX, dirY, .addLight(type.index, colour, intensity, posX, posY, posZ, dirX, dirY,
dirZ, castShadows) dirZ, falloffRadius, spotLightConeInner, spotLightConeOuter, sunAngularRadius, sunHaloSize, sunHaloFallof, castShadows)
.toDart) .toDart)
.toDartInt; .toDartInt;
} }

View File

@@ -125,10 +125,10 @@ class FilamentViewer extends AbstractFilamentViewer {
await setCameraManipulatorOptions(zoomSpeed: 10.0); await setCameraManipulatorOptions(zoomSpeed: 10.0);
final out = calloc<Int32>(3); final out = allocator<Int32>(3);
get_gizmo(_sceneManager!, out); get_gizmo(_sceneManager!, out);
_gizmo = Gizmo(out[0], out[1], out[2], this); _gizmo = Gizmo(out[0], out[1], out[2], this);
calloc.free(out); allocator.free(out);
this._initialized.complete(true); this._initialized.complete(true);
} }