From 255d8657ddecc280fc9118c75e08ce8242387803 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 21 Jun 2022 08:26:39 +0200 Subject: [PATCH] Tech ENABLE_RAYCAST_PICKING - Small refactoring --- src/slic3r/GUI/GLCanvas3D.hpp | 4 ++-- src/slic3r/GUI/Gizmos/GLGizmoBase.cpp | 2 +- src/slic3r/GUI/Gizmos/GLGizmoBase.hpp | 4 ++-- src/slic3r/GUI/Gizmos/GLGizmoFlatten.hpp | 2 +- src/slic3r/GUI/SceneRaycaster.cpp | 23 ++++++++--------------- src/slic3r/GUI/SceneRaycaster.hpp | 22 ++++++++++------------ 6 files changed, 24 insertions(+), 33 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 86989b80d..62c823e62 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -659,10 +659,10 @@ public: void post_event(wxEvent &&event); #if ENABLE_RAYCAST_PICKING - std::shared_ptr add_raycaster_for_picking(SceneRaycaster::EType type, PickingId id, const MeshRaycaster& raycaster, const Transform3d& trafo) { + std::shared_ptr add_raycaster_for_picking(SceneRaycaster::EType type, int id, const MeshRaycaster& raycaster, const Transform3d& trafo) { return m_scene_raycaster.add_raycaster(type, id, raycaster, trafo); } - void remove_raycasters_for_picking(SceneRaycaster::EType type, PickingId id) { + void remove_raycasters_for_picking(SceneRaycaster::EType type, int id) { m_scene_raycaster.remove_raycasters(type, id); } void remove_raycasters_for_picking(SceneRaycaster::EType type) { diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp index bebfc01a2..36603b692 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp @@ -54,7 +54,7 @@ float GLGizmoBase::Grabber::get_dragging_half_size(float size) const } #if ENABLE_RAYCAST_PICKING -void GLGizmoBase::Grabber::register_raycasters_for_picking(PickingId id) +void GLGizmoBase::Grabber::register_raycasters_for_picking(int id) { picking_id = id; // registration will happen on next call to render() diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp index c6667c92c..4001dd190 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp @@ -72,7 +72,7 @@ protected: EGrabberExtension extensions{ EGrabberExtension::None }; #if ENABLE_RAYCAST_PICKING // the picking id shared by all the elements - PickingId picking_id{ -1 }; + int picking_id{ -1 }; std::array, GRABBER_ELEMENTS_MAX_COUNT> raycasters = { nullptr }; #endif // ENABLE_RAYCAST_PICKING @@ -90,7 +90,7 @@ protected: float get_dragging_half_size(float size) const; #if ENABLE_RAYCAST_PICKING - void register_raycasters_for_picking(PickingId id); + void register_raycasters_for_picking(int id); void unregister_raycasters_for_picking(); #endif // ENABLE_RAYCAST_PICKING diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.hpp b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.hpp index aab042b03..32d119fbc 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.hpp @@ -40,7 +40,7 @@ private: Vec3d normal; float area; #if ENABLE_RAYCAST_PICKING - PickingId picking_id{ -1 }; + int picking_id{ -1 }; #endif // ENABLE_RAYCAST_PICKING }; diff --git a/src/slic3r/GUI/SceneRaycaster.cpp b/src/slic3r/GUI/SceneRaycaster.cpp index 2313fbf0c..41e8c69ce 100644 --- a/src/slic3r/GUI/SceneRaycaster.cpp +++ b/src/slic3r/GUI/SceneRaycaster.cpp @@ -33,7 +33,7 @@ SceneRaycaster::SceneRaycaster() { #endif // ENABLE_RAYCAST_PICKING_DEBUG } -std::shared_ptr SceneRaycaster::add_raycaster(EType type, PickingId id, const MeshRaycaster& raycaster, const Transform3d& trafo) +std::shared_ptr SceneRaycaster::add_raycaster(EType type, int id, const MeshRaycaster& raycaster, const Transform3d& trafo) { switch (type) { case EType::Bed: { return m_bed.emplace_back(std::make_shared(encode_id(type, id), raycaster, trafo)); } @@ -43,7 +43,7 @@ std::shared_ptr SceneRaycaster::add_raycaster(EType type, Pi }; } -void SceneRaycaster::remove_raycasters(EType type, PickingId id) +void SceneRaycaster::remove_raycasters(EType type, int id) { std::vector>* raycasters = get_raycasters(type); auto it = raycasters->begin(); @@ -186,13 +186,13 @@ std::vector>* SceneRaycaster::get_raycasters return ret; } -PickingId SceneRaycaster::base_id(EType type) +int SceneRaycaster::base_id(EType type) { switch (type) { - case EType::Bed: { return PickingId(EPickingIdBase::Bed); } - case EType::Volume: { return PickingId(EPickingIdBase::Volume); } - case EType::Gizmo: { return PickingId(EPickingIdBase::Gizmo); } + case EType::Bed: { return int(EIdBase::Bed); } + case EType::Volume: { return int(EIdBase::Volume); } + case EType::Gizmo: { return int(EIdBase::Gizmo); } default: { break; } }; @@ -200,15 +200,8 @@ PickingId SceneRaycaster::base_id(EType type) return -1; } -PickingId SceneRaycaster::encode_id(EType type, PickingId id) -{ - return base_id(type) + id; -} - -PickingId SceneRaycaster::decode_id(EType type, PickingId id) -{ - return id - base_id(type); -} +int SceneRaycaster::encode_id(EType type, int id) { return base_id(type) + id; } +int SceneRaycaster::decode_id(EType type, int id) { return id - base_id(type); } } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/SceneRaycaster.hpp b/src/slic3r/GUI/SceneRaycaster.hpp index fb5aee88e..c016e27e9 100644 --- a/src/slic3r/GUI/SceneRaycaster.hpp +++ b/src/slic3r/GUI/SceneRaycaster.hpp @@ -15,21 +15,19 @@ namespace GUI { struct Camera; -using PickingId = int; - class SceneRaycasterItem { - PickingId m_id{ -1 }; + int m_id{ -1 }; bool m_active{ true }; const MeshRaycaster* m_raycaster; Transform3d m_trafo; public: - SceneRaycasterItem(PickingId id, const MeshRaycaster& raycaster, const Transform3d& trafo) + SceneRaycasterItem(int id, const MeshRaycaster& raycaster, const Transform3d& trafo) : m_id(id), m_raycaster(&raycaster), m_trafo(trafo) {} - PickingId get_id() const { return m_id; } + int get_id() const { return m_id; } bool is_active() const { return m_active; } void set_active(bool active) { m_active = active; } const MeshRaycaster* get_raycaster() const { return m_raycaster; } @@ -48,7 +46,7 @@ public: Gizmo }; - enum class EPickingIdBase + enum class EIdBase { Bed = 0, Volume = 1000, @@ -58,7 +56,7 @@ public: struct HitResult { EType type{ EType::None }; - PickingId raycaster_id{ -1 }; + int raycaster_id{ -1 }; Vec3f position{ Vec3f::Zero() }; Vec3f normal{ Vec3f::Zero() }; @@ -83,8 +81,8 @@ private: public: SceneRaycaster(); - std::shared_ptr add_raycaster(EType type, PickingId picking_id, const MeshRaycaster& raycaster, const Transform3d& trafo); - void remove_raycasters(EType type, PickingId id); + std::shared_ptr add_raycaster(EType type, int picking_id, const MeshRaycaster& raycaster, const Transform3d& trafo); + void remove_raycasters(EType type, int id); void remove_raycasters(EType type); void remove_raycaster(std::shared_ptr item); @@ -103,9 +101,9 @@ public: #endif // ENABLE_RAYCAST_PICKING_DEBUG private: - static PickingId encode_id(EType type, PickingId id); - static PickingId decode_id(EType type, PickingId id); - static PickingId base_id(EType type); + static int encode_id(EType type, int id); + static int decode_id(EType type, int id); + static int base_id(EType type); }; } // namespace GUI