Modified MMU painting gizmo behavior so that all triangles aren't painted by default by the first extruder, which was causing several problems.
This commit also fixed the following issues: 1) After loading a 3MF with painted triangles using the MMU painting gizmo, the painted triangles might not be displayed correctly in the MMU painting gizmo. 2) The MMU segmentation was unnecessarily executed for all layers and not just for the painted layers. 3) Object's base color wasn't changed when the assigned extruder for that object was changed while the MMU paint gizmo was opened. 4) Changing the base color of an object was only possible by removing all painted triangles.
This commit is contained in:
parent
b2677f513c
commit
8a77fa38f0
@ -736,7 +736,7 @@ TriangleSelector::TriangleSelector(const TriangleMesh& mesh)
|
||||
}
|
||||
|
||||
|
||||
void TriangleSelector::reset(const EnforcerBlockerType reset_state)
|
||||
void TriangleSelector::reset()
|
||||
{
|
||||
m_vertices.clear();
|
||||
m_triangles.clear();
|
||||
@ -749,7 +749,7 @@ void TriangleSelector::reset(const EnforcerBlockerType reset_state)
|
||||
m_triangles.reserve(m_mesh->its.indices.size());
|
||||
for (size_t i=0; i<m_mesh->its.indices.size(); ++i) {
|
||||
const stl_triangle_vertex_indices& ind = m_mesh->its.indices[i];
|
||||
push_triangle(ind[0], ind[1], ind[2], i, reset_state);
|
||||
push_triangle(ind[0], ind[1], ind[2], i);
|
||||
}
|
||||
m_orig_size_vertices = m_vertices.size();
|
||||
m_orig_size_indices = m_triangles.size();
|
||||
@ -930,8 +930,8 @@ std::pair<std::vector<std::pair<int, int>>, std::vector<bool>> TriangleSelector:
|
||||
// In case this is leaf, we better save information about its state.
|
||||
int n = int(tr.get_state());
|
||||
if (n >= 3) {
|
||||
assert(n <= 15);
|
||||
if (n <= 15) {
|
||||
assert(n <= 16);
|
||||
if (n <= 16) {
|
||||
// Store "11" plus 4 bits of (n-3).
|
||||
data.second.insert(data.second.end(), { true, true });
|
||||
n -= 3;
|
||||
@ -963,9 +963,9 @@ std::pair<std::vector<std::pair<int, int>>, std::vector<bool>> TriangleSelector:
|
||||
return out.data;
|
||||
}
|
||||
|
||||
void TriangleSelector::deserialize(const std::pair<std::vector<std::pair<int, int>>, std::vector<bool>> &data, const EnforcerBlockerType init_state)
|
||||
void TriangleSelector::deserialize(const std::pair<std::vector<std::pair<int, int>>, std::vector<bool>> &data)
|
||||
{
|
||||
reset(init_state); // dump any current state
|
||||
reset(); // dump any current state
|
||||
|
||||
// Vector to store all parents that have offsprings.
|
||||
struct ProcessingInfo {
|
||||
|
@ -50,7 +50,7 @@ public:
|
||||
void set_facet(int facet_idx, EnforcerBlockerType state);
|
||||
|
||||
// Clear everything and make the tree empty.
|
||||
void reset(const EnforcerBlockerType reset_state = EnforcerBlockerType{0});
|
||||
void reset();
|
||||
|
||||
// Remove all unnecessary data.
|
||||
void garbage_collect();
|
||||
@ -60,7 +60,7 @@ public:
|
||||
std::pair<std::vector<std::pair<int, int>>, std::vector<bool>> serialize() const;
|
||||
|
||||
// Load serialized data. Assumes that correct mesh is loaded.
|
||||
void deserialize(const std::pair<std::vector<std::pair<int, int>>, std::vector<bool>> &data, const EnforcerBlockerType init_state = EnforcerBlockerType{0});
|
||||
void deserialize(const std::pair<std::vector<std::pair<int, int>>, std::vector<bool>> &data);
|
||||
|
||||
// For all triangles, remove the flag indicating that the triangle was selected by seed fill.
|
||||
void seed_fill_unselect_all_triangles();
|
||||
|
@ -58,6 +58,20 @@ static std::vector<std::string> get_extruders_names()
|
||||
return extruders_out;
|
||||
}
|
||||
|
||||
static std::vector<int> get_extruder_id_for_volumes(const ModelObject &model_object)
|
||||
{
|
||||
std::vector<int> extruders_idx;
|
||||
extruders_idx.reserve(model_object.volumes.size());
|
||||
for (const ModelVolume *model_volume : model_object.volumes) {
|
||||
if (!model_volume->is_model_part())
|
||||
continue;
|
||||
|
||||
extruders_idx.emplace_back(model_volume->extruder_id());
|
||||
}
|
||||
|
||||
return extruders_idx;
|
||||
}
|
||||
|
||||
void GLGizmoMmuSegmentation::init_extruders_data()
|
||||
{
|
||||
m_original_extruders_names = get_extruders_names();
|
||||
@ -114,12 +128,15 @@ void GLGizmoMmuSegmentation::set_painter_gizmo_data(const Selection &selection)
|
||||
if (m_state != On)
|
||||
return;
|
||||
|
||||
ModelObject *model_object = m_c->selection_info()->model_object();
|
||||
int prev_extruders_count = int(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
|
||||
if (prev_extruders_count != wxGetApp().extruders_edited_cnt())
|
||||
this->init_model_triangle_selectors();
|
||||
} else if (model_object != nullptr && get_extruder_id_for_volumes(*model_object) != m_original_volumes_extruder_idxs) {
|
||||
this->init_model_triangle_selectors();
|
||||
}
|
||||
}
|
||||
|
||||
@ -280,8 +297,7 @@ void GLGizmoMmuSegmentation::on_render_input_window(float x, float y, float bott
|
||||
for (ModelVolume *mv : mo->volumes) {
|
||||
if (mv->is_model_part()) {
|
||||
++idx;
|
||||
size_t extruder_id = (mv->extruder_id() > 0) ? mv->extruder_id() - 1 : 0;
|
||||
m_triangle_selectors[idx]->reset(EnforcerBlockerType(extruder_id));
|
||||
m_triangle_selectors[idx]->reset();
|
||||
}
|
||||
}
|
||||
|
||||
@ -395,10 +411,11 @@ 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<TriangleSelectorMmuGui>(*mesh, m_modified_extruders_colors));
|
||||
m_triangle_selectors.back()->deserialize(mv->mmu_segmentation_facets.get_data(), EnforcerBlockerType(extruder_id));
|
||||
int extruder_idx = (mv->extruder_id() > 0) ? mv->extruder_id() - 1 : 0;
|
||||
m_triangle_selectors.emplace_back(std::make_unique<TriangleSelectorMmuGui>(*mesh, m_modified_extruders_colors, m_original_extruders_colors[size_t(extruder_idx)]));
|
||||
m_triangle_selectors.back()->deserialize(mv->mmu_segmentation_facets.get_data());
|
||||
}
|
||||
m_original_volumes_extruder_idxs = get_extruder_id_for_volumes(*mo);
|
||||
}
|
||||
|
||||
void GLGizmoMmuSegmentation::update_from_model_object()
|
||||
@ -468,9 +485,10 @@ void TriangleSelectorMmuGui::render(ImGuiWrapper *imgui)
|
||||
assert(shader->get_name() == "gouraud");
|
||||
|
||||
for (size_t color_idx = 0; color_idx < m_iva_colors.size(); ++color_idx) {
|
||||
const std::array<uint8_t, 3> &color_source = (color_idx == 0) ? m_default_volume_color : m_colors[color_idx - 1];
|
||||
if (render_colors[color_idx]) {
|
||||
std::array<float, 4> color = {float(m_colors[color_idx][0]) / 255.0f, float(m_colors[color_idx][1]) / 255.0f,
|
||||
float(m_colors[color_idx][2]) / 255.0f, 1.f};
|
||||
std::array<float, 4> color = {float(color_source[0]) / 255.0f, float(color_source[1]) / 255.0f,
|
||||
float(color_source[2]) / 255.0f, 1.f};
|
||||
shader->set_uniform("uniform_color", color);
|
||||
m_iva_colors[color_idx].render();
|
||||
}
|
||||
|
@ -7,9 +7,10 @@ namespace Slic3r::GUI {
|
||||
|
||||
class TriangleSelectorMmuGui : public TriangleSelectorGUI {
|
||||
public:
|
||||
explicit TriangleSelectorMmuGui(const TriangleMesh& mesh, const std::vector<std::array<uint8_t, 3>> &colors)
|
||||
: TriangleSelectorGUI(mesh), m_colors(colors) {
|
||||
m_iva_colors = std::vector<GLIndexedVertexArray>(colors.size());
|
||||
explicit TriangleSelectorMmuGui(const TriangleMesh& mesh, const std::vector<std::array<uint8_t, 3>> &colors, const std::array<uint8_t, 3> &default_volume_color)
|
||||
: TriangleSelectorGUI(mesh), m_colors(colors), m_default_volume_color(default_volume_color) {
|
||||
// Plus 1 is because the first position is allocated for non-painted triangles.
|
||||
m_iva_colors = std::vector<GLIndexedVertexArray>(colors.size() + 1);
|
||||
}
|
||||
~TriangleSelectorMmuGui() override = default;
|
||||
|
||||
@ -20,6 +21,7 @@ public:
|
||||
private:
|
||||
const std::vector<std::array<uint8_t, 3>> &m_colors;
|
||||
std::vector<GLIndexedVertexArray> m_iva_colors;
|
||||
const std::array<uint8_t, 3> m_default_volume_color;
|
||||
};
|
||||
|
||||
class GLGizmoMmuSegmentation : public GLGizmoPainterBase
|
||||
@ -37,8 +39,8 @@ protected:
|
||||
std::array<float, 4> get_cursor_sphere_left_button_color() const override;
|
||||
std::array<float, 4> get_cursor_sphere_right_button_color() const override;
|
||||
|
||||
EnforcerBlockerType get_left_button_state_type() const override { return EnforcerBlockerType(m_first_selected_extruder_idx); }
|
||||
EnforcerBlockerType get_right_button_state_type() const override { return EnforcerBlockerType(m_second_selected_extruder_idx); }
|
||||
EnforcerBlockerType get_left_button_state_type() const override { return EnforcerBlockerType(m_first_selected_extruder_idx + 1); }
|
||||
EnforcerBlockerType get_right_button_state_type() const override { return EnforcerBlockerType(m_second_selected_extruder_idx + 1); }
|
||||
|
||||
void on_render_input_window(float x, float y, float bottom_limit) override;
|
||||
std::string on_get_name() const override;
|
||||
@ -52,6 +54,7 @@ protected:
|
||||
std::vector<std::string> m_original_extruders_names;
|
||||
std::vector<std::array<uint8_t, 3>> m_original_extruders_colors;
|
||||
std::vector<std::array<uint8_t, 3>> m_modified_extruders_colors;
|
||||
std::vector<int> m_original_volumes_extruder_idxs;
|
||||
|
||||
private:
|
||||
bool on_init() override;
|
||||
|
Loading…
Reference in New Issue
Block a user