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.
This commit is contained in:
Lukáš Hejl 2021-06-04 12:54:00 +02:00
parent de9ed9ee3e
commit 7377fc34ac
4 changed files with 22 additions and 25 deletions

View File

@ -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;
}

View File

@ -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();

View File

@ -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<float, 4> color = { 0.47f, 0.47f, 1.f, 1.f };
std::array<float, 4> color = {0.47f, 0.47f, 1.f, 1.f};
shader->set_uniform("uniform_color", color);
m_iva_enforcers.render();
}
if (render_blc) {
std::array<float, 4> color = { 1.f, 0.44f, 0.44f, 1.f };
std::array<float, 4> 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<float, 4> color = { 0.f, 1.00f, 0.44f, 1.f };
std::array<float, 4> 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

View File

@ -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;