From 87187a35fe7d0c8af23c141b6daee6736caa1025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Sat, 21 Oct 2023 08:51:46 +0200 Subject: [PATCH 1/2] Don't set view_model_matrix, projection_matrix, and view_normal_matrix in TriangleSelectorMmGui::render() because they are already set inside GLGizmoMmuSegmentation::render_triangles(). --- src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp index 622ea89740..88bfa49da9 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp @@ -592,13 +592,8 @@ void TriangleSelectorMmGui::render(ImGuiWrapper* imgui, const Transform3d& matri auto *shader = wxGetApp().get_current_shader(); if (!shader) return; + assert(shader->get_name() == "mm_gouraud"); - const Camera& camera = wxGetApp().plater()->get_camera(); - const Transform3d& view_matrix = camera.get_view_matrix(); - shader->set_uniform("view_model_matrix", view_matrix * matrix); - shader->set_uniform("projection_matrix", camera.get_projection_matrix()); - const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); - shader->set_uniform("view_normal_matrix", view_normal_matrix); for (size_t color_idx = 0; color_idx < m_gizmo_scene.triangle_indices.size(); ++color_idx) { if (m_gizmo_scene.has_VBOs(color_idx)) { From 7c22d7a842dd968fdd6ca0a475aea232540b6761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Sat, 21 Oct 2023 08:54:56 +0200 Subject: [PATCH 2/2] SPE-1975: Show multi-material painting in thumbnails. --- src/slic3r/GUI/GLCanvas3D.cpp | 19 ++++++++++++++----- .../GUI/Gizmos/GLGizmoMmuSegmentation.cpp | 6 +++--- .../GUI/Gizmos/GLGizmoMmuSegmentation.hpp | 11 ++++++++++- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 013c07e892..883cebb173 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -80,6 +80,7 @@ #include "DoubleSlider.hpp" #include +#include static constexpr const float TRACKBALLSIZE = 0.8f; @@ -4901,7 +4902,7 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const camera.apply_projection(volumes_box, near_z, far_z); - GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); + GLShaderProgram* shader = wxGetApp().get_shader("mm_gouraud"); if (shader == nullptr) return; @@ -4912,11 +4913,12 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const glsafe(::glEnable(GL_DEPTH_TEST)); shader->start_using(); - shader->set_uniform("emission_factor", 0.0f); const Transform3d& projection_matrix = camera.get_projection_matrix(); - for (GLVolume* vol : visible_volumes) { + const ModelObjectPtrs &model_objects = GUI::wxGetApp().model().objects; + std::vector extruders_colors = get_extruders_colors(); + for (GLVolume *vol : visible_volumes) { vol->model.set_color((vol->printable && !vol->is_outside) ? vol->color : ColorRGBA::GRAY()); // the volume may have been deactivated by an active gizmo const bool is_active = vol->is_active; @@ -4925,8 +4927,15 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const shader->set_uniform("view_model_matrix", view_matrix * model_matrix); shader->set_uniform("projection_matrix", projection_matrix); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); - shader->set_uniform("view_normal_matrix", view_normal_matrix); - vol->render(); + shader->set_uniform("view_normal_matrix", view_normal_matrix); + + const ModelVolume &model_volume = *model_objects[vol->object_idx()]->volumes[vol->volume_idx()]; + const size_t extruder_idx = get_extruder_color_idx(model_volume); + TriangleSelectorMmGui ts(model_volume.mesh(), extruders_colors, extruders_colors[extruder_idx]); + ts.deserialize(model_volume.mmu_segmentation_facets.get_data(), true); + ts.request_update_render_data(); + ts.render(nullptr, model_matrix); + vol->is_active = is_active; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp index 88bfa49da9..1e60c118b6 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp @@ -62,7 +62,7 @@ bool GLGizmoMmuSegmentation::on_is_activable() const return GLGizmoPainterBase::on_is_activable() && wxGetApp().extruders_edited_cnt() > 1; } -static std::vector get_extruders_colors() +std::vector get_extruders_colors() { std::vector colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config(); std::vector ret; @@ -543,8 +543,8 @@ void GLGizmoMmuSegmentation::init_model_triangle_selectors() // This mesh does not account for the possible Z up SLA offset. const TriangleMesh *mesh = &mv->mesh(); - int extruder_idx = (mv->extruder_id() > 0) ? mv->extruder_id() - 1 : 0; - m_triangle_selectors.emplace_back(std::make_unique(*mesh, m_modified_extruders_colors, m_original_extruders_colors[size_t(extruder_idx)])); + size_t extruder_idx = get_extruder_color_idx(*mv); + m_triangle_selectors.emplace_back(std::make_unique(*mesh, m_modified_extruders_colors, m_original_extruders_colors[extruder_idx])); // Reset of TriangleSelector is done inside TriangleSelectorMmGUI's constructor, so we don't need it to perform it again in deserialize(). m_triangle_selectors.back()->deserialize(mv->mmu_segmentation_facets.get_data(), false); m_triangle_selectors.back()->request_update_render_data(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.hpp index d0a34e0e40..1bc01ba1bb 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.hpp @@ -70,9 +70,11 @@ public: class TriangleSelectorMmGui : public TriangleSelectorGUI { public: + TriangleSelectorMmGui() = delete; // Plus 1 in the initialization of m_gizmo_scene is because the first position is allocated for non-painted triangles, and the indices above colors.size() are allocated for seed fill. - TriangleSelectorMmGui(const TriangleMesh& mesh, const std::vector& colors, const ColorRGBA& default_volume_color) + explicit TriangleSelectorMmGui(const TriangleMesh& mesh, const std::vector& colors, const ColorRGBA& default_volume_color) : TriangleSelectorGUI(mesh), m_colors(colors), m_default_volume_color(default_volume_color), m_gizmo_scene(2 * (colors.size() + 1)) {} + ~TriangleSelectorMmGui() override = default; void render(ImGuiWrapper* imgui, const Transform3d& matrix) override; @@ -152,6 +154,13 @@ private: std::map m_desc; }; +std::vector get_extruders_colors(); + +inline size_t get_extruder_color_idx(const ModelVolume &model_volume) +{ + return (model_volume.extruder_id() > 0) ? model_volume.extruder_id() - 1 : 0; +} + } // namespace Slic3r