From 490074a2dd22d8666db46389de93b6d5a0c84e6b Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Wed, 27 Mar 2019 14:16:38 +0100 Subject: [PATCH] SLA gizmo now turns off in case someone adds an object/instance (to prevent rendering points in thin air, etc.) Also, a bug appering when adding an object larger than the bed and scaling it down was fixed (sla gizmo did not work correctly in that case) --- src/slic3r/GUI/GLCanvas3D.cpp | 1 + src/slic3r/GUI/GLCanvas3D.hpp | 2 ++ src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 18 +++++++++++++----- src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp | 10 ---------- src/slic3r/GUI/Plater.cpp | 7 +++++++ 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 1f616a101..7dc59ed30 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2114,6 +2114,7 @@ wxDEFINE_EVENT(EVT_GLCANVAS_UPDATE_GEOMETRY, Vec3dsEvent<2>); wxDEFINE_EVENT(EVT_GLCANVAS_MOUSE_DRAGGING_FINISHED, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_UPDATE_BED_SHAPE, SimpleEvent); wxDEFINE_EVENT(EVT_GLCANVAS_TAB, SimpleEvent); +wxDEFINE_EVENT(EVT_GLCANVAS_RESETGIZMOS, SimpleEvent); GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar) : m_canvas(canvas) diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 29e0fbb08..23e6814f8 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -116,6 +116,7 @@ wxDECLARE_EVENT(EVT_GLCANVAS_UPDATE_GEOMETRY, Vec3dsEvent<2>); wxDECLARE_EVENT(EVT_GLCANVAS_MOUSE_DRAGGING_FINISHED, SimpleEvent); wxDECLARE_EVENT(EVT_GLCANVAS_UPDATE_BED_SHAPE, SimpleEvent); wxDECLARE_EVENT(EVT_GLCANVAS_TAB, SimpleEvent); +wxDECLARE_EVENT(EVT_GLCANVAS_RESETGIZMOS, SimpleEvent); // this describes events being passed from GLCanvas3D to SlaSupport gizmo enum class SLAGizmoEventType { @@ -712,6 +713,7 @@ public: void set_camera_zoom(float zoom); void update_gizmos_on_off_state(); + void reset_all_gizmos() { m_gizmos.reset_all_states(); } void handle_sidebar_focus_event(const std::string& opt_key, bool focus_on); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index 31f6b0278..df7004b3f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -21,7 +21,7 @@ GLGizmoSlaSupports::GLGizmoSlaSupports(GLCanvas3D& parent, const std::string& ic GLGizmoSlaSupports::GLGizmoSlaSupports(GLCanvas3D& parent, unsigned int sprite_id) : GLGizmoBase(parent, sprite_id) #endif // ENABLE_SVG_ICONS - , m_starting_center(Vec3d::Zero()), m_quadric(nullptr) + , m_quadric(nullptr) { m_quadric = ::gluNewQuadric(); if (m_quadric != nullptr) @@ -44,12 +44,11 @@ bool GLGizmoSlaSupports::on_init() void GLGizmoSlaSupports::set_sla_support_data(ModelObject* model_object, const Selection& selection) { - m_starting_center = Vec3d::Zero(); + if (selection.is_empty()) + return; + m_old_model_object = m_model_object; m_model_object = model_object; - if (selection.is_empty()) - m_old_instance_id = -1; - m_active_instance = selection.get_instance_idx(); if (model_object && selection.is_from_single_instance()) @@ -74,6 +73,14 @@ void GLGizmoSlaSupports::set_sla_support_data(ModelObject* model_object, const S void GLGizmoSlaSupports::on_render(const Selection& selection) const { + // If current m_model_object does not match selection, ask GLCanvas3D to turn us off + if (m_state == On + && (m_model_object != selection.get_model()->objects[selection.get_object_idx()] + || m_active_instance != selection.get_instance_idx())) { + m_parent.post_event(SimpleEvent(EVT_GLCANVAS_RESETGIZMOS)); + return; + } + ::glEnable(GL_BLEND); ::glEnable(GL_DEPTH_TEST); @@ -717,6 +724,7 @@ std::string GLGizmoSlaSupports::on_get_name() const void GLGizmoSlaSupports::on_set_state() { if (m_state == On && m_old_state != On) { // the gizmo was just turned on + if (is_mesh_update_necessary()) update_mesh(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp index 993ab06bf..7e8113774 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp @@ -22,7 +22,6 @@ private: ModelObject* m_model_object = nullptr; ModelObject* m_old_model_object = nullptr; int m_active_instance = -1; - int m_old_instance_id = -1; std::pair unproject_on_mesh(const Vec2d& mouse_pos); const float RenderPointScale = 1.f; @@ -32,10 +31,6 @@ private: Eigen::MatrixXi m_F; // facets indices igl::AABB m_AABB; - struct SourceDataSummary { - Geometry::Transformation transformation; - }; - class CacheEntry { public: CacheEntry(const sla::SupportPoint& point, bool sel, const Vec3f& norm = Vec3f::Zero()) : @@ -46,11 +41,6 @@ private: Vec3f normal; }; - // This holds information to decide whether recalculation is necessary: - SourceDataSummary m_source_data; - - mutable Vec3d m_starting_center; - public: #if ENABLE_SVG_ICONS GLGizmoSlaSupports(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 0505d9276..7b31c80c0 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1191,6 +1191,7 @@ struct Plater::priv void select_view(const std::string& direction); void select_view_3D(const std::string& name); void select_next_view_3D(); + void reset_all_gizmos(); void update_ui_from_settings(); ProgressStatusBar* statusbar(); std::string get_config(const std::string &key) const; @@ -1396,6 +1397,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) view3D_canvas->Bind(EVT_GLCANVAS_UPDATE_GEOMETRY, &priv::on_update_geometry, this); view3D_canvas->Bind(EVT_GLCANVAS_MOUSE_DRAGGING_FINISHED, &priv::on_3dcanvas_mouse_dragging_finished, this); view3D_canvas->Bind(EVT_GLCANVAS_TAB, [this](SimpleEvent&) { select_next_view_3D(); }); + view3D_canvas->Bind(EVT_GLCANVAS_RESETGIZMOS, [this](SimpleEvent&) { reset_all_gizmos(); }); // 3DScene/Toolbar: view3D_canvas->Bind(EVT_GLTOOLBAR_ADD, &priv::on_action_add, this); view3D_canvas->Bind(EVT_GLTOOLBAR_DELETE, [q](SimpleEvent&) { q->remove_selected(); }); @@ -1478,6 +1480,11 @@ void Plater::priv::select_next_view_3D() set_current_panel(view3D); } +void Plater::priv::reset_all_gizmos() +{ + view3D->get_canvas3d()->reset_all_gizmos(); +} + // Called after the Preferences dialog is closed and the program settings are saved. // Update the UI based on the current preferences. void Plater::priv::update_ui_from_settings()