diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 3100a024b..dac370b54 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -6294,7 +6294,7 @@ void GLCanvas3D::_picking_pass() const else { m_hover_volume_id = -1; - m_gizmos.set_hover_id(inside && volume_id <= 254 * 255 * 255 ? (254 * 255 * 255 - volume_id) : -1); + m_gizmos.set_hover_id(inside && volume_id <= GLGizmoBase::BASE_ID ? (GLGizmoBase::BASE_ID - volume_id) : -1); } _update_volumes_hover_state(); diff --git a/src/slic3r/GUI/GLGizmo.cpp b/src/slic3r/GUI/GLGizmo.cpp index 19d50e2e0..6ab2f46ab 100644 --- a/src/slic3r/GUI/GLGizmo.cpp +++ b/src/slic3r/GUI/GLGizmo.cpp @@ -246,18 +246,17 @@ void GLGizmoBase::update(const UpdateData& data, const GLCanvas3D::Selection& se std::array GLGizmoBase::picking_color_component(unsigned int id) const { - // Starting value for id to avoid clashing with id used by GLVolumes - static const unsigned int BASE = 254 * 255 * 255; static const float INV_255 = 1.0f / 255.0f; - id = BASE - id; + id = BASE_ID - id; if (m_group_id > -1) id -= m_group_id; + // color components are encoded to match the calculation of volume_id made into GLCanvas3D::_picking_pass() return std::array { (float)((id >> 0) & 0xff) * INV_255, // red (float)((id >> 8) & 0xff) * INV_255, // green - (float)((id >> 16)& 0xff) * INV_255}; // blue + (float)((id >> 16) & 0xff) * INV_255 }; // blue } void GLGizmoBase::render_grabbers(const BoundingBoxf3& box) const diff --git a/src/slic3r/GUI/GLGizmo.hpp b/src/slic3r/GUI/GLGizmo.hpp index 83a062a2c..4e44da540 100644 --- a/src/slic3r/GUI/GLGizmo.hpp +++ b/src/slic3r/GUI/GLGizmo.hpp @@ -35,6 +35,11 @@ class ImGuiWrapper; class GLGizmoBase { +public: + // Starting value for ids to avoid clashing with ids used by GLVolumes + // (254 is choosen to leave some space for forward compatibility) + static const unsigned int BASE_ID = 255 * 255 * 254; + protected: struct Grabber { @@ -175,6 +180,8 @@ protected: virtual void on_render_input_window(float x, float y, float bottom_limit, const GLCanvas3D::Selection& selection) {} #endif // ENABLE_IMGUI + // Returns the picking color for the given id, based on the BASE_ID constant + // No check is made for clashing with other picking color (i.e. GLVolumes) std::array picking_color_component(unsigned int id) const; void render_grabbers(const BoundingBoxf3& box) const; void render_grabbers(float size) const;