From 7377fc34acef999774333466db18858a1dae5512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Fri, 4 Jun 2021 12:54:00 +0200 Subject: [PATCH] Fixed cracks in MMU painting gizmo. All triangles, even not painted triangles, are now rendered inside MMU painting gizmo. The cracks were caused by using glPolygonOffset to resolve Z-fighting. All triangles of the object were firstly rendered entirely with a base color. And then paint triangles were drawn over these already rendered triangles. --- src/slic3r/GUI/GLCanvas3D.cpp | 5 ++- .../GUI/Gizmos/GLGizmoMmuSegmentation.cpp | 2 +- src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp | 38 +++++++++---------- src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp | 2 +- 4 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index daf8c5991..9662bacc0 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1168,10 +1168,11 @@ void GLCanvas3D::toggle_model_objects_visibility(bool visible, const ModelObject const GLGizmosManager& gm = get_gizmos_manager(); auto gizmo_type = gm.get_current_type(); if ( (gizmo_type == GLGizmosManager::FdmSupports - || gizmo_type == GLGizmosManager::Seam - || gizmo_type == GLGizmosManager::MmuSegmentation) + || gizmo_type == GLGizmosManager::Seam) && ! vol->is_modifier) vol->force_neutral_color = true; + else if (gizmo_type == GLGizmosManager::MmuSegmentation) + vol->is_active = false; else vol->force_native_color = true; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp index ad726c110..0b6d7660b 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp @@ -99,7 +99,7 @@ void GLGizmoMmuSegmentation::render_painter_gizmo() const glsafe(::glEnable(GL_BLEND)); glsafe(::glEnable(GL_DEPTH_TEST)); - render_triangles(selection); + render_triangles(selection, false); m_c->object_clipper()->render_cut(); render_cursor(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp index 64b41e46e..dfb87880f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp @@ -13,8 +13,7 @@ -namespace Slic3r { -namespace GUI { +namespace Slic3r::GUI { GLGizmoPainterBase::GLGizmoPainterBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) @@ -110,13 +109,15 @@ void GLGizmoPainterBase::set_painter_gizmo_data(const Selection& selection) -void GLGizmoPainterBase::render_triangles(const Selection& selection) const +void GLGizmoPainterBase::render_triangles(const Selection& selection, const bool use_polygon_offset_fill) const { const ModelObject* mo = m_c->selection_info()->model_object(); - glsafe(::glEnable(GL_POLYGON_OFFSET_FILL)); - ScopeGuard offset_fill_guard([]() { glsafe(::glDisable(GL_POLYGON_OFFSET_FILL)); } ); - glsafe(::glPolygonOffset(-5.0, -5.0)); + if (use_polygon_offset_fill) { + glsafe(::glEnable(GL_POLYGON_OFFSET_FILL)); + ScopeGuard offset_fill_guard([]() { glsafe(::glDisable(GL_POLYGON_OFFSET_FILL)); }); + glsafe(::glPolygonOffset(-5.0, -5.0)); + } // Take care of the clipping plane. The normal of the clipping plane is // saved with opposite sign than we need to pass to OpenGL (FIXME) @@ -578,8 +579,8 @@ void GLGizmoPainterBase::on_load(cereal::BinaryInputArchive&) void TriangleSelectorGUI::render(ImGuiWrapper* imgui) { - int enf_cnt = 0; - int blc_cnt = 0; + int enf_cnt = 0; + int blc_cnt = 0; int seed_fill_cnt = 0; m_iva_enforcers.release_geometry(); @@ -590,12 +591,8 @@ void TriangleSelectorGUI::render(ImGuiWrapper* imgui) if (!tr.valid() || tr.is_split() || tr.get_state() == EnforcerBlockerType::NONE || tr.is_selected_by_seed_fill()) continue; - GLIndexedVertexArray& va = tr.get_state() == EnforcerBlockerType::ENFORCER - ? m_iva_enforcers - : m_iva_blockers; - int& cnt = tr.get_state() == EnforcerBlockerType::ENFORCER - ? enf_cnt - : blc_cnt; + GLIndexedVertexArray &va = tr.get_state() == EnforcerBlockerType::ENFORCER ? m_iva_enforcers : m_iva_blockers; + int &cnt = tr.get_state() == EnforcerBlockerType::ENFORCER ? enf_cnt : blc_cnt; for (int i=0; i<3; ++i) va.push_geometry(m_vertices[tr.verts_idxs[i]].v, m_mesh->stl.facet_start[tr.source_triangle].normal); @@ -617,8 +614,8 @@ void TriangleSelectorGUI::render(ImGuiWrapper* imgui) m_iva_blockers.finalize_geometry(true); m_iva_seed_fill.finalize_geometry(true); - bool render_enf = m_iva_enforcers.has_VBOs(); - bool render_blc = m_iva_blockers.has_VBOs(); + bool render_enf = m_iva_enforcers.has_VBOs(); + bool render_blc = m_iva_blockers.has_VBOs(); bool render_seed_fill = m_iva_seed_fill.has_VBOs(); auto* shader = wxGetApp().get_current_shader(); @@ -627,19 +624,19 @@ void TriangleSelectorGUI::render(ImGuiWrapper* imgui) assert(shader->get_name() == "gouraud"); if (render_enf) { - std::array color = { 0.47f, 0.47f, 1.f, 1.f }; + std::array color = {0.47f, 0.47f, 1.f, 1.f}; shader->set_uniform("uniform_color", color); m_iva_enforcers.render(); } if (render_blc) { - std::array color = { 1.f, 0.44f, 0.44f, 1.f }; + std::array color = {1.f, 0.44f, 0.44f, 1.f}; shader->set_uniform("uniform_color", color); m_iva_blockers.render(); } if (render_seed_fill) { - std::array color = { 0.f, 1.00f, 0.44f, 1.f }; + std::array color = {0.f, 1.00f, 0.44f, 1.f}; shader->set_uniform("uniform_color", color); m_iva_seed_fill.render(); } @@ -746,5 +743,4 @@ void TriangleSelectorGUI::render_debug(ImGuiWrapper* imgui) -} // namespace GUI -} // namespace Slic3r +} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp index 8e2d05ea8..6622f7326 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp @@ -75,7 +75,7 @@ public: virtual void render_painter_gizmo() const = 0; protected: - void render_triangles(const Selection& selection) const; + void render_triangles(const Selection& selection, const bool use_polygon_offset_fill = true) const; void render_cursor() const; void render_cursor_circle() const; void render_cursor_sphere(const Transform3d& trafo) const;