feat: expose setLightDirection and setLightPosition

This commit is contained in:
Nick Fisher
2024-09-05 22:18:54 +08:00
parent c93cc296a0
commit d17cce2ca4
8 changed files with 122 additions and 19 deletions

View File

@@ -183,6 +183,28 @@ external void clear_lights(
ffi.Pointer<ffi.Void> viewer,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<ffi.Void>, EntityId, ffi.Float, ffi.Float, ffi.Float)>()
external void set_light_position(
ffi.Pointer<ffi.Void> viewer,
int light,
double x,
double y,
double z,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<ffi.Void>, EntityId, ffi.Float, ffi.Float, ffi.Float)>()
external void set_light_direction(
ffi.Pointer<ffi.Void> viewer,
int light,
double x,
double y,
double z,
);
@ffi.Native<
EntityId Function(ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Char>, ffi.Int)>()
external int load_glb(

View File

@@ -2256,4 +2256,28 @@ class ThermionViewerWasm implements ThermionViewer {
[_sceneManager!, visible.toJS].toJS,
null);
}
@override
Future setLightDirection(ThermionEntity lightEntity, Vector3 direction) async {
direction.normalize();
_module!.ccall(
"set_light_direction",
"void",
["void*".toJS, "double".toJS, "double".toJS, "double".toJS].toJS,
[_viewer!, direction.x.toJS, direction.y.toJS, direction.z.toJS]
.toJS,
null);
}
@override
Future setLightPosition(
ThermionEntity lightEntity, double x, double y, double z) async {
_module!.ccall(
"set_light_position",
"void",
["void*".toJS, "double".toJS, "double".toJS, "double".toJS].toJS,
[_viewer!, x.toJS,y.toJS,z.toJS]
.toJS,
null);
}
}

View File

@@ -570,10 +570,20 @@ abstract class ThermionViewer {
Future transformToUnitCube(ThermionEntity entity);
///
/// Directly sets the world space position for [entity] to the given coordinates, skipping all collision detection.
/// Directly sets the world space position for [entity] to the given coordinates.
///
Future setPosition(ThermionEntity entity, double x, double y, double z);
///
/// Set the world space position for [lightEntity] to the given coordinates.
///
Future setLightPosition(ThermionEntity lightEntity, double x, double y, double z);
///
/// Sets the world space direction for [lightEntity] to the given vector.
///
Future setLightDirection(ThermionEntity lightEntity, Vector3 direction);
///
/// Directly sets the scale for [entity], skipping all collision detection.
///

View File

@@ -1287,6 +1287,24 @@ class ThermionViewerFFI extends ThermionViewer {
set_position(_sceneManager!, entity, x, y, z);
}
///
///
///
@override
Future setLightPosition(
ThermionEntity lightEntity, double x, double y, double z) async {
set_light_position(_viewer!, lightEntity, x, y, z);
}
///
///
///
@override
Future setLightDirection(ThermionEntity lightEntity, Vector3 direction) async {
direction.normalize();
set_light_direction(_viewer!, lightEntity, direction.x, direction.y, direction.z);
}
///
///
///