From f9c5ee58962bc850093dd6f38878ccd06aa99cc0 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Wed, 16 Apr 2025 13:59:42 +0800 Subject: [PATCH] remove pick() from FFI viewer / add setLayerVisibility --- .../src/ffi/src/thermion_viewer_ffi.dart | 60 +++---------------- 1 file changed, 8 insertions(+), 52 deletions(-) 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 f3158bfc..92c7a71c 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 @@ -27,8 +27,6 @@ class ThermionViewerFFI extends ThermionViewer { final _initialized = Completer(); Future get initialized => _initialized.future; - late NativeCallable _onPickResultCallable; - late final FFIFilamentApp app; late final FFIView view; @@ -44,8 +42,7 @@ class ThermionViewerFFI extends ThermionViewer { throw Exception("FilamentApp has not been created"); } app = FilamentApp.instance as FFIFilamentApp; - _onPickResultCallable = - NativeCallable.listener(_onPickResult); + _initialize(); } @@ -521,54 +518,6 @@ class ThermionViewerFFI extends ThermionViewer { app.lightManager, lightEntity, direction.x, direction.y, direction.z); } - void _onPickResult(int requestId, ThermionEntity entityId, double depth, - double fragX, double fragY, double fragZ) async { - if (!_pickRequests.containsKey(requestId)) { - _logger.severe( - "Warning : pick result received with no matching request ID. This indicates you're clearing the pick cache too quickly"); - return; - } - final (:handler, :x, :y, :view) = _pickRequests[requestId]!; - _pickRequests.remove(requestId); - - final viewport = await view.getViewport(); - - handler.call(( - entity: entityId, - x: x, - y: y, - depth: depth, - fragX: fragX, - fragY: viewport.height - fragY, - fragZ: fragZ, - )); - } - - int _pickRequestId = -1; - final _pickRequests = {}; - - /// - /// - /// - @override - Future pick(int x, int y, void Function(PickResult) resultHandler) async { - _pickRequestId++; - var pickRequestId = _pickRequestId; - _pickRequests[pickRequestId] = - (handler: resultHandler, x: x, y: y, view: view); - - var viewport = await view.getViewport(); - y = viewport.height - y; - - View_pick( - view.view, pickRequestId, x, y, _onPickResultCallable.nativeFunction); - - Future.delayed(Duration(seconds: 1)).then((_) { - _pickRequests.remove(pickRequestId); - }); - } - /// /// /// @@ -612,6 +561,13 @@ class ThermionViewerFFI extends ThermionViewer { } } + /// + /// + /// + Future setLayerVisibility(VisibilityLayers layer, bool visible) async { + await view.setLayerVisibility(layer, visible); + } + /// /// ///