From 4c22023762d4231df4823c7e0c9f85ca89b0f05a Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 21 Feb 2020 08:14:45 +0100 Subject: [PATCH] SLA gizmo clipping plane resetting Clipping plane direction is now initialized when the plane is first moved, not when the gizmo is opened. This is how previous versions worked. This is a minimal-effort solution before the clipping plane is refactored properly. --- src/slic3r/GUI/Gizmos/GLGizmoBase.cpp | 22 +++++++++++++++++--- src/slic3r/GUI/Gizmos/GLGizmoBase.hpp | 1 + src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp | 14 ++++++++----- src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 18 +++++++++------- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp index 523d3eef6..52518878f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp @@ -310,6 +310,7 @@ unsigned char picking_checksum_alpha_channel(unsigned char red, unsigned char gr bool CommonGizmosData::update_from_backend(GLCanvas3D& canvas, ModelObject* model_object) { recent_update = false; + bool object_changed = false; if (m_model_object != model_object || (model_object && m_model_object_id != model_object->id())) { @@ -325,7 +326,7 @@ bool CommonGizmosData::update_from_backend(GLCanvas3D& canvas, ModelObject* mode m_active_instance = canvas.get_selection().get_instance_idx(); m_active_instance_bb_radius = m_model_object->instance_bounding_box(m_active_instance).radius(); } - + object_changed = true; recent_update = true; } @@ -347,6 +348,7 @@ bool CommonGizmosData::update_from_backend(GLCanvas3D& canvas, ModelObject* mode } } + bool mesh_exchanged = false; m_mesh = nullptr; // Load either the model_object mesh, or one provided by the backend // This mesh does not account for the possible Z up SLA offset. @@ -359,6 +361,7 @@ bool CommonGizmosData::update_from_backend(GLCanvas3D& canvas, ModelObject* mode m_backend_mesh_transformed.transform(canvas.sla_print()->sla_trafo(*m_model_object).inverse()); m_mesh = &m_backend_mesh_transformed; m_has_drilled_mesh = true; + mesh_exchanged = true; } } @@ -371,6 +374,21 @@ bool CommonGizmosData::update_from_backend(GLCanvas3D& canvas, ModelObject* mode m_model_object_id = m_model_object->id(); if (m_mesh != m_old_mesh) { + // Update clipping plane position. + float new_clp_pos = m_clipping_plane_distance; + if (object_changed) { + new_clp_pos = 0.f; + m_clipping_plane_was_moved = false; + } else { + // After we got a drilled mesh, move the cp to 25% (if not used already) + if (m_clipping_plane_distance == 0.f && mesh_exchanged && m_has_drilled_mesh) { + new_clp_pos = 0.25f; + m_clipping_plane_was_moved = false; // so it uses current camera direction + } + } + m_clipping_plane_distance = new_clp_pos; + m_clipping_plane_distance_stash = new_clp_pos; + m_schedule_aabb_calculation = true; recent_update = true; return true; @@ -392,8 +410,6 @@ void CommonGizmosData::build_AABB_if_needed() m_object_clipper.reset(); m_supports_clipper.reset(); m_old_mesh = m_mesh; - m_clipping_plane_distance = 0.f; - m_clipping_plane_distance_stash = 0.f; m_schedule_aabb_calculation = false; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp index 157100687..695946e3d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp @@ -220,6 +220,7 @@ public: float m_clipping_plane_distance = 0.f; std::unique_ptr m_clipping_plane; + bool m_clipping_plane_was_moved = false; void stash_clipping_plane() { m_clipping_plane_distance_stash = m_clipping_plane_distance; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp index 27e99e240..260bc813d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp @@ -57,10 +57,11 @@ bool GLGizmoHollow::on_init() void GLGizmoHollow::set_sla_support_data(ModelObject*, const Selection&) { if (m_c->recent_update) { + if (m_state == On) m_c->build_AABB_if_needed(); - update_clipping_plane(); + update_clipping_plane(m_c->m_clipping_plane_was_moved); if (m_c->m_model_object) { reload_cache(); @@ -511,7 +512,8 @@ bool GLGizmoHollow::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_pos if (action == SLAGizmoEventType::MouseWheelUp && control_down) { m_c->m_clipping_plane_distance = std::min(1.f, m_c->m_clipping_plane_distance + 0.01f); - update_clipping_plane(true); + update_clipping_plane(m_c->m_clipping_plane_was_moved); + m_c->m_clipping_plane_was_moved = true; return true; } @@ -901,8 +903,10 @@ RENDER_AGAIN: ImGui::SameLine(clipping_slider_left); ImGui::PushItemWidth(window_width - clipping_slider_left); - if (ImGui::SliderFloat(" ", &m_c->m_clipping_plane_distance, 0.f, 1.f, "%.2f")) - update_clipping_plane(true); + if (ImGui::SliderFloat(" ", &m_c->m_clipping_plane_distance, 0.f, 1.f, "%.2f")) { + update_clipping_plane(m_c->m_clipping_plane_was_moved); + m_c->m_clipping_plane_was_moved = true; + } // make sure supports are shown/hidden as appropriate if (m_imgui->checkbox(m_desc["show_supports"], m_show_supports)) { @@ -985,7 +989,7 @@ void GLGizmoHollow::on_set_state() //Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("SLA gizmo turned on"))); //m_c->update_from_backend(m_parent, m_c->m_model_object); m_c->unstash_clipping_plane(); - update_clipping_plane(m_c->m_clipping_plane_distance != 0.f); + update_clipping_plane(m_c->m_clipping_plane_was_moved); m_c->build_AABB_if_needed(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index d9898b315..247e643eb 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -71,7 +71,7 @@ void GLGizmoSlaSupports::set_sla_support_data(ModelObject* model_object, const S if (m_state == On) m_c->build_AABB_if_needed(); - update_clipping_plane(); + update_clipping_plane(m_c->m_clipping_plane_was_moved); if (m_state == On) { m_parent.toggle_model_objects_visibility(false); @@ -599,7 +599,8 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous if (action == SLAGizmoEventType::MouseWheelUp && control_down) { m_c->m_clipping_plane_distance = std::min(1.f, m_c->m_clipping_plane_distance + 0.01f); - update_clipping_plane(true); + update_clipping_plane(m_c->m_clipping_plane_was_moved); + m_c->m_clipping_plane_was_moved = true; return true; } @@ -925,8 +926,10 @@ RENDER_AGAIN: ImGui::SameLine(clipping_slider_left); ImGui::PushItemWidth(window_width - clipping_slider_left); - if (ImGui::SliderFloat(" ", &m_c->m_clipping_plane_distance, 0.f, 1.f, "%.2f")) - update_clipping_plane(true); + if (ImGui::SliderFloat(" ", &m_c->m_clipping_plane_distance, 0.f, 1.f, "%.2f")) { + update_clipping_plane(m_c->m_clipping_plane_was_moved); + m_c->m_clipping_plane_was_moved = true; + } if (m_imgui->button("?")) { @@ -1011,7 +1014,7 @@ void GLGizmoSlaSupports::on_set_state() Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("SLA gizmo turned on"))); m_c->unstash_clipping_plane(); - update_clipping_plane(m_c->m_clipping_plane_distance != 0.f); + update_clipping_plane(m_c->m_clipping_plane_was_moved); m_c->build_AABB_if_needed(); @@ -1021,9 +1024,10 @@ void GLGizmoSlaSupports::on_set_state() reload_cache(); m_parent.toggle_model_objects_visibility(false); - if (m_c->m_model_object /*&& ! m_c->m_cavity_mesh*/) + if (m_c->m_model_object) { m_parent.toggle_model_objects_visibility(true, m_c->m_model_object, m_c->m_active_instance); - m_parent.toggle_sla_auxiliaries_visibility(! m_editing_mode, m_c->m_model_object, m_c->m_active_instance); + m_parent.toggle_sla_auxiliaries_visibility(! m_editing_mode, m_c->m_model_object, m_c->m_active_instance); + } // Set default head diameter from config. const DynamicPrintConfig& cfg = wxGetApp().preset_bundle->sla_prints.get_edited_preset().config;