feat: add removeStencilHighlight, queuePositionUpdateFromViewportCoords to ThermionViewer

This commit is contained in:
Nick Fisher
2024-09-07 17:54:42 +08:00
parent 331caccc22
commit aecde97200
2 changed files with 52 additions and 11 deletions

View File

@@ -203,10 +203,11 @@ abstract class ThermionViewer {
/// If you want to be able to call [createInstance] at a later time, you must pass true for [keepData]. /// If you want to be able to call [createInstance] at a later time, you must pass true for [keepData].
/// If [keepData] is false, the source glTF data will be released and [createInstance] will throw an exception. /// If [keepData] is false, the source glTF data will be released and [createInstance] will throw an exception.
/// ///
Future<ThermionEntity> loadGlb(String path, {int numInstances = 1, bool keepData = false}); Future<ThermionEntity> loadGlb(String path,
{int numInstances = 1, bool keepData = false});
/// ///
/// Create a new instance of [entity]. /// Create a new instance of [entity].
/// ///
Future<ThermionEntity> createInstance(ThermionEntity entity); Future<ThermionEntity> createInstance(ThermionEntity entity);
@@ -224,7 +225,7 @@ abstract class ThermionViewer {
/// Load the .gltf asset at the given path and insert into the scene. /// Load the .gltf asset at the given path and insert into the scene.
/// [relativeResourcePath] is the folder path where the glTF resources are stored; /// [relativeResourcePath] is the folder path where the glTF resources are stored;
/// this is usually the parent directory of the .gltf file itself. /// this is usually the parent directory of the .gltf file itself.
/// ///
/// See [loadGlb] for an explanation of [keepData]. /// See [loadGlb] for an explanation of [keepData].
/// ///
Future<ThermionEntity> loadGltf(String path, String relativeResourcePath, Future<ThermionEntity> loadGltf(String path, String relativeResourcePath,
@@ -609,12 +610,20 @@ abstract class ThermionViewer {
ThermionEntity entity, double x, double y, double z, ThermionEntity entity, double x, double y, double z,
{bool relative = false}); {bool relative = false});
///
/// TODO
///
Future queuePositionUpdateFromViewportCoords(
ThermionEntity entity, double x, double y);
/// ///
/// TODO /// TODO
/// ///
Future queueRelativePositionUpdateWorldAxis(ThermionEntity entity, Future queueRelativePositionUpdateWorldAxis(ThermionEntity entity,
double viewportX, double viewportY, double x, double y, double z); double viewportX, double viewportY, double x, double y, double z);
/// ///
/// Queues an update to the worldspace rotation for [entity]. /// Queues an update to the worldspace rotation for [entity].
/// The actual update will occur on the next frame, and will be subject to collision detection. /// The actual update will occur on the next frame, and will be subject to collision detection.
@@ -818,7 +827,13 @@ abstract class ThermionViewer {
Future setGizmoVisibility(bool visible); Future setGizmoVisibility(bool visible);
/// ///
/// Outlines [entity]. /// Renders an outline around [entity] with the given color.
/// ///
Future setStencilHighlight(ThermionEntity entity); Future setStencilHighlight(ThermionEntity entity,
{double r = 1.0, double g = 0.0, double b = 0.0});
///
/// Removes the outline around [entity]. Noop if there was no highlight.
///
Future removeStencilHighlight(ThermionEntity entity);
} }

View File

@@ -444,8 +444,8 @@ class ThermionViewerFFI extends ThermionViewer {
throw Exception("Not yet implemented"); throw Exception("Not yet implemented");
} }
final pathPtr = path.toNativeUtf8(allocator: allocator).cast<Char>(); final pathPtr = path.toNativeUtf8(allocator: allocator).cast<Char>();
var entity = await withIntCallback((callback) => var entity = await withIntCallback((callback) => load_glb_ffi(
load_glb_ffi(_sceneManager!, pathPtr, numInstances, keepData, callback)); _sceneManager!, pathPtr, numInstances, keepData, callback));
allocator.free(pathPtr); allocator.free(pathPtr);
if (entity == _FILAMENT_ASSET_ERROR) { if (entity == _FILAMENT_ASSET_ERROR) {
throw Exception("An error occurred loading the asset at $path"); throw Exception("An error occurred loading the asset at $path");
@@ -1334,6 +1334,9 @@ class ThermionViewerFFI extends ThermionViewer {
set_scale(_sceneManager!, entity, scale); set_scale(_sceneManager!, entity, scale);
} }
///
///
///
Future queueRotationUpdateQuat(ThermionEntity entity, Quaternion rotation, Future queueRotationUpdateQuat(ThermionEntity entity, Quaternion rotation,
{bool relative = false}) async { {bool relative = false}) async {
queue_rotation_update(_sceneManager!, entity, rotation.radians, rotation.x, queue_rotation_update(_sceneManager!, entity, rotation.radians, rotation.x,
@@ -1361,6 +1364,18 @@ class ThermionViewerFFI extends ThermionViewer {
queue_position_update(_sceneManager!, entity, x, y, z, relative); queue_position_update(_sceneManager!, entity, x, y, z, relative);
} }
///
/// Queues an update to the worldspace position for [entity] to the viewport coordinates {x,y}.
/// The actual update will occur on the next frame, and will be subject to collision detection.
///
Future queuePositionUpdateFromViewportCoords(
ThermionEntity entity, double x, double y) async {
queue_position_update_from_viewport_coords(_sceneManager!, entity, x, y);
}
///
///
///
Future queueRelativePositionUpdateWorldAxis(ThermionEntity entity, Future queueRelativePositionUpdateWorldAxis(ThermionEntity entity,
double viewportX, double viewportY, double x, double y, double z) async { double viewportX, double viewportY, double x, double y, double z) async {
queue_relative_position_update_world_axis( queue_relative_position_update_world_axis(
@@ -1742,7 +1757,7 @@ class ThermionViewerFFI extends ThermionViewer {
} }
var entity = await withIntCallback((callback) => create_geometry_ffi( var entity = await withIntCallback((callback) => create_geometry_ffi(
_viewer!, _sceneManager!,
vertexPtr, vertexPtr,
vertices.length, vertices.length,
indicesPtr, indicesPtr,
@@ -1830,7 +1845,18 @@ class ThermionViewerFFI extends ThermionViewer {
set_gizmo_visibility(_sceneManager!, visible); set_gizmo_visibility(_sceneManager!, visible);
} }
Future setStencilHighlight(ThermionEntity entity) async { ///
set_stencil_highlight(_sceneManager!, entity); ///
///
Future setStencilHighlight(ThermionEntity entity,
{double r = 1.0, double g = 0.0, double b = 0.0}) async {
set_stencil_highlight(_sceneManager!, entity, r, g, b);
}
///
///
///
Future removeStencilHighlight(ThermionEntity entity) async {
remove_stencil_highlight(_sceneManager!, entity);
} }
} }