diff --git a/src/libslic3r/TriangleSelector.cpp b/src/libslic3r/TriangleSelector.cpp index 0846cec89..95f2984e3 100644 --- a/src/libslic3r/TriangleSelector.cpp +++ b/src/libslic3r/TriangleSelector.cpp @@ -463,7 +463,7 @@ TriangleSelector::TriangleSelector(const TriangleMesh& mesh) } -void TriangleSelector::reset() +void TriangleSelector::reset(const EnforcerBlockerType reset_state) { if (m_orig_size_indices != 0) // unless this is run from constructor garbage_collect(); @@ -474,7 +474,7 @@ void TriangleSelector::reset() for (size_t i=0; iits.indices.size(); ++i) { const stl_triangle_vertex_indices& ind = m_mesh->its.indices[i]; const Vec3f& normal = m_mesh->stl.facet_start[i].normal; - push_triangle(ind[0], ind[1], ind[2], normal); + push_triangle(ind[0], ind[1], ind[2], normal, reset_state); } m_orig_size_vertices = m_vertices.size(); m_orig_size_indices = m_triangles.size(); @@ -500,13 +500,13 @@ void TriangleSelector::set_edge_limit(float edge_limit) -void TriangleSelector::push_triangle(int a, int b, int c, const Vec3f& normal) +void TriangleSelector::push_triangle(int a, int b, int c, const Vec3f& normal, const EnforcerBlockerType state) { for (int i : {a, b, c}) { assert(i >= 0 && i < int(m_vertices.size())); ++m_vertices[i].ref_cnt; } - m_triangles.emplace_back(a, b, c, normal); + m_triangles.emplace_back(a, b, c, normal, state); } @@ -663,9 +663,9 @@ std::map> TriangleSelector::serialize() const return out; } -void TriangleSelector::deserialize(const std::map> data) +void TriangleSelector::deserialize(const std::map> data, const EnforcerBlockerType init_state) { - reset(); // dump any current state + reset(init_state); // dump any current state for (const auto& [triangle_id, code] : data) { assert(triangle_id < int(m_triangles.size())); assert(! code.empty()); diff --git a/src/libslic3r/TriangleSelector.hpp b/src/libslic3r/TriangleSelector.hpp index 1a420c547..383aab480 100644 --- a/src/libslic3r/TriangleSelector.hpp +++ b/src/libslic3r/TriangleSelector.hpp @@ -49,7 +49,7 @@ public: void set_facet(int facet_idx, EnforcerBlockerType state); // Clear everything and make the tree empty. - void reset(); + void reset(const EnforcerBlockerType reset_state = EnforcerBlockerType{0}); // Remove all unnecessary data. void garbage_collect(); @@ -59,7 +59,7 @@ public: std::map> serialize() const; // Load serialized data. Assumes that correct mesh is loaded. - void deserialize(const std::map> data); + void deserialize(const std::map> data, const EnforcerBlockerType init_state = EnforcerBlockerType{0}); // For all triangles, remove the flag indicating that the triangle was selected by seed fill. void seed_fill_unselect_all_triangles(); @@ -73,10 +73,10 @@ protected: public: // Use TriangleSelector::push_triangle to create a new triangle. // It increments/decrements reference counter on vertices. - Triangle(int a, int b, int c, const Vec3f& normal_) + Triangle(int a, int b, int c, const Vec3f& normal_, const EnforcerBlockerType init_state) : verts_idxs{a, b, c}, normal{normal_}, - state{EnforcerBlockerType(0)}, + state{init_state}, number_of_splits{0}, special_side_idx{0}, old_number_of_splits{0} @@ -178,7 +178,7 @@ protected: void remove_useless_children(int facet_idx); // No hidden meaning. Triangles are meant. bool is_pointer_in_triangle(int facet_idx) const; bool is_edge_inside_cursor(int facet_idx) const; - void push_triangle(int a, int b, int c, const Vec3f& normal); + void push_triangle(int a, int b, int c, const Vec3f &normal, const EnforcerBlockerType state = EnforcerBlockerType{0}); void perform_split(int facet_idx, EnforcerBlockerType old_state); }; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp index 962015dde..e5acda8c6 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp @@ -299,7 +299,7 @@ void GLGizmoMmuSegmentation::set_painter_gizmo_data(const Selection &selection) if (m_state != On) return; - size_t prev_extruders_count = m_original_extruders_colors.size(); + int prev_extruders_count = m_original_extruders_colors.size(); if (prev_extruders_count != wxGetApp().extruders_edited_cnt() || get_extruders_colors() != m_original_extruders_colors) { this->init_extruders_data(); // Reinitialize triangle selectors because of change of extruder count need also change the size of GLIndexedVertexArray @@ -465,7 +465,8 @@ void GLGizmoMmuSegmentation::on_render_input_window(float x, float y, float bott for (ModelVolume *mv : mo->volumes) { if (mv->is_model_part()) { ++idx; - m_triangle_selectors[idx]->reset(EnforcerBlockerType(mv->extruder_id())); + size_t extruder_id = (mv->extruder_id() > 0) ? mv->extruder_id() - 1 : 0; + m_triangle_selectors[idx]->reset(EnforcerBlockerType(extruder_id)); } } @@ -576,8 +577,9 @@ void GLGizmoMmuSegmentation::init_model_triangle_selectors() // This mesh does not account for the possible Z up SLA offset. const TriangleMesh *mesh = &mv->mesh(); + size_t extruder_id = (mv->extruder_id() > 0) ? mv->extruder_id() - 1 : 0; m_triangle_selectors.emplace_back(std::make_unique(*mesh, m_modified_extruders_colors)); - m_triangle_selectors.back()->deserialize(mv->mmu_segmentation_facets.get_data()); + m_triangle_selectors.back()->deserialize(mv->mmu_segmentation_facets.get_data(), EnforcerBlockerType(extruder_id)); } } @@ -602,8 +604,7 @@ void TriangleSelectorMmuGui::render(ImGuiWrapper *imgui) for (size_t color_idx = 0; color_idx < m_iva_colors.size(); ++color_idx) { for (const Triangle &tr : m_triangles) { - if (!tr.valid || tr.is_split() || /*tr.get_state() == EnforcerBlockerType::NONE ||*/ tr.is_selected_by_seed_fill() || - tr.get_state() != EnforcerBlockerType(color_idx)) + if (!tr.valid || tr.is_split() || tr.is_selected_by_seed_fill() || tr.get_state() != EnforcerBlockerType(color_idx)) continue; for (int i = 0; i < 3; ++i)