Merge branch 'lh_mmu_thumbnails_SPE-1975'

This commit is contained in:
Lukáš Hejl 2023-10-31 15:36:23 +01:00
commit 7f1d58e08b
3 changed files with 28 additions and 15 deletions

View File

@ -80,6 +80,7 @@
#include "DoubleSlider.hpp"
#include <imgui/imgui_internal.h>
#include <slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.hpp>
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<ColorRGBA> 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;
@ -4926,7 +4928,14 @@ void GLCanvas3D::_render_thumbnail_internal(ThumbnailData& thumbnail_data, const
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();
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;
}

View File

@ -62,7 +62,7 @@ bool GLGizmoMmuSegmentation::on_is_activable() const
return GLGizmoPainterBase::on_is_activable() && wxGetApp().extruders_edited_cnt() > 1;
}
static std::vector<ColorRGBA> get_extruders_colors()
std::vector<ColorRGBA> get_extruders_colors()
{
std::vector<std::string> colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config();
std::vector<ColorRGBA> 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<TriangleSelectorMmGui>(*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<TriangleSelectorMmGui>(*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();
@ -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)) {

View File

@ -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<ColorRGBA>& colors, const ColorRGBA& default_volume_color)
explicit TriangleSelectorMmGui(const TriangleMesh& mesh, const std::vector<ColorRGBA>& 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<std::string, wxString> m_desc;
};
std::vector<ColorRGBA> 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