From 7c15125a975ebaa81becb1a2550989659d333a78 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Wed, 30 Oct 2024 10:44:55 +0800 Subject: [PATCH] fix: reduce size of pick functor for compatibility with armeabi-v7a --- .../viewer/src/ffi/src/thermion_dart.g.dart | 6 +++++ .../native/include/FilamentViewer.hpp | 6 +++++ .../native/include/ThermionDartApi.h | 1 + thermion_dart/native/src/FilamentViewer.cpp | 23 +++++++------------ thermion_dart/native/src/ThermionDartApi.cpp | 5 ++++ 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/thermion_dart/lib/src/viewer/src/ffi/src/thermion_dart.g.dart b/thermion_dart/lib/src/viewer/src/ffi/src/thermion_dart.g.dart index b58047ce..6ce01183 100644 --- a/thermion_dart/lib/src/viewer/src/ffi/src/thermion_dart.g.dart +++ b/thermion_dart/lib/src/viewer/src/ffi/src/thermion_dart.g.dart @@ -178,6 +178,12 @@ external void Viewer_pick( callback, ); +@ffi.Native, EntityId)>(isLeaf: true) +external bool Viewer_isNonPickableEntity( + ffi.Pointer viewer, + int entityId, +); + @ffi.Native Function(ffi.Pointer)>(isLeaf: true) external ffi.Pointer Viewer_getEngine( ffi.Pointer viewer, diff --git a/thermion_dart/native/include/FilamentViewer.hpp b/thermion_dart/native/include/FilamentViewer.hpp index 41db5f20..327a182b 100644 --- a/thermion_dart/native/include/FilamentViewer.hpp +++ b/thermion_dart/native/include/FilamentViewer.hpp @@ -99,6 +99,12 @@ namespace thermion void setBackgroundImagePosition(float x, float y, bool clamp, uint32_t width, uint32_t height); typedef void (*PickCallback)(EntityId entityId, int x, int y, View *view, float depth, float fragX, float fragY, float fragZ); + + /// + /// Returns true if the specified entity is a gizmo, grid or background image entity. + /// + bool isNonPickableEntity(EntityId entityId); + void pick(View *view, uint32_t x, uint32_t y, PickCallback callback); Engine* getEngine() { diff --git a/thermion_dart/native/include/ThermionDartApi.h b/thermion_dart/native/include/ThermionDartApi.h index fd2171c2..862ac0de 100644 --- a/thermion_dart/native/include/ThermionDartApi.h +++ b/thermion_dart/native/include/ThermionDartApi.h @@ -86,6 +86,7 @@ extern "C" EMSCRIPTEN_KEEPALIVE TSwapChain* Viewer_getSwapChainAt(TViewer *tViewer, int index); EMSCRIPTEN_KEEPALIVE void Viewer_setViewRenderable(TViewer *viewer, TSwapChain *swapChain, TView* view, bool renderable); EMSCRIPTEN_KEEPALIVE void Viewer_pick(TViewer *viewer, TView* tView, int x, int y, void (*callback)(EntityId entityId, int x, int y, TView *tView, float depth, float fragX, float fragY, float fragZ)); + EMSCRIPTEN_KEEPALIVE bool Viewer_isNonPickableEntity(TViewer *viewer, EntityId entityId); // Engine EMSCRIPTEN_KEEPALIVE TEngine *Viewer_getEngine(TViewer* viewer); diff --git a/thermion_dart/native/src/FilamentViewer.cpp b/thermion_dart/native/src/FilamentViewer.cpp index 5a404418..2235a1b7 100644 --- a/thermion_dart/native/src/FilamentViewer.cpp +++ b/thermion_dart/native/src/FilamentViewer.cpp @@ -1191,23 +1191,16 @@ namespace thermion return _engine->getCameraComponent(Entity::import(entity)); } + bool FilamentViewer::isNonPickableEntity(EntityId entityId) { + auto renderable = Entity::import(entityId); + return _sceneManager->isGizmoEntity(renderable) || renderable == _imageEntity || renderable == _sceneManager->_gridOverlay->sphere() || _sceneManager->_gridOverlay->grid(); + } + void FilamentViewer::pick(View *view, uint32_t x, uint32_t y, PickCallback callback) { - view->pick(x, y, [=](filament::View::PickingQueryResult const &result) { - - if(_sceneManager->isGizmoEntity(result.renderable)) { - Log("Gizmo entity, ignoring"); - return; - } - std::unordered_set nonPickableEntities = { - _imageEntity, - _sceneManager->_gridOverlay->sphere(), - _sceneManager->_gridOverlay->grid(), - }; - - if (nonPickableEntities.find(result.renderable) == nonPickableEntities.end()) { - callback(Entity::smuggle(result.renderable), x, y, view, result.depth, result.fragCoords.x, result.fragCoords.y, result.fragCoords.z); - } }); + view->pick(x, y, [=](filament::View::PickingQueryResult const &result) { + callback(Entity::smuggle(result.renderable), x, y, view, result.depth, result.fragCoords.x, result.fragCoords.y, result.fragCoords.z); + }); } void FilamentViewer::unprojectTexture(EntityId entityId, uint8_t *input, uint32_t inputWidth, uint32_t inputHeight, uint8_t *out, uint32_t outWidth, uint32_t outHeight) diff --git a/thermion_dart/native/src/ThermionDartApi.cpp b/thermion_dart/native/src/ThermionDartApi.cpp index 0d9879dd..671cf7e5 100644 --- a/thermion_dart/native/src/ThermionDartApi.cpp +++ b/thermion_dart/native/src/ThermionDartApi.cpp @@ -56,6 +56,11 @@ extern "C" ((FilamentViewer *)viewer)->pick(view, static_cast(x), static_cast(y), reinterpret_cast(callback)); } + EMSCRIPTEN_KEEPALIVE bool Viewer_isNonPickableEntity(TViewer *tViewer, EntityId entityId) { + auto *viewer = reinterpret_cast(tViewer); + return viewer->isNonPickableEntity(entityId); + } + EMSCRIPTEN_KEEPALIVE void destroy_filament_viewer(TViewer *viewer) { delete ((FilamentViewer *)viewer);