From 5fc056edfbc27693675f9119057f72cbe7c40628 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 24 Oct 2023 10:27:56 +0800 Subject: [PATCH] Some refactoring into GLGizmoSlaSupports::render_points() (cherry picked from commit prusa3d/PrusaSlicer@5621f00ee694e6aaedb83b190c855395a0df2dc6) --- src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 25 +++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index 48031ead3f..a981d15c72 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -118,10 +118,10 @@ void GLGizmoSlaSupports::on_render_for_picking() void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) { - size_t cache_size = m_editing_mode ? m_editing_cache.size() : m_normal_cache.size(); + const size_t cache_size = m_editing_mode ? m_editing_cache.size() : m_normal_cache.size(); - bool has_points = (cache_size != 0); - bool has_holes = (! m_c->hollowed_mesh()->get_hollowed_mesh() + const bool has_points = (cache_size != 0); + const bool has_holes = (! m_c->hollowed_mesh()->get_hollowed_mesh() && ! m_c->selection_info()->model_object()->sla_drain_holes.empty()); if (! has_points && ! has_holes) @@ -135,9 +135,9 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) ScopeGuard guard([shader]() { shader->stop_using(); }); const GLVolume* vol = selection.get_volume(*selection.get_volume_idxs().begin()); - const Transform3d& instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse(); + const Transform3d instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse(); const Transform3d& instance_matrix = vol->get_instance_transformation().get_matrix(); - float z_shift = m_c->selection_info()->get_sla_shift(); + const float z_shift = m_c->selection_info()->get_sla_shift(); glsafe(::glPushMatrix()); glsafe(::glTranslated(0.0, 0.0, z_shift)); @@ -146,7 +146,7 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) ColorRGBA render_color; for (size_t i = 0; i < cache_size; ++i) { const sla::SupportPoint& support_point = m_editing_mode ? m_editing_cache[i].support_point : m_normal_cache[i]; - const bool& point_selected = m_editing_mode ? m_editing_cache[i].selected : false; + const bool point_selected = m_editing_mode ? m_editing_cache[i].selected : false; if (is_mesh_point_clipped(support_point.pos.cast())) continue; @@ -180,7 +180,7 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) // Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. glsafe(::glPushMatrix()); - glsafe(::glTranslatef(support_point.pos(0), support_point.pos(1), support_point.pos(2))); + glsafe(::glTranslatef(support_point.pos.x(), support_point.pos.y(), support_point.pos.z())); glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data())); if (vol->is_left_handed()) @@ -195,12 +195,11 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) Eigen::Quaterniond q; q.setFromTwoVectors(Vec3d{0., 0., 1.}, instance_scaling_matrix_inverse * m_editing_cache[i].normal.cast()); - Eigen::AngleAxisd aa(q); - glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis()(0), aa.axis()(1), aa.axis()(2))); - + const Eigen::AngleAxisd aa(q); + glsafe(::glPushMatrix()); + glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis().x(), aa.axis().y(), aa.axis().z())); const double cone_radius = 0.25; // mm const double cone_height = 0.75; - glsafe(::glPushMatrix()); glsafe(::glTranslatef(0.f, 0.f, cone_height + support_point.head_front_radius * RenderPointScale)); glsafe(::glRotated(180., 1., 0., 0.)); glsafe(::glScaled(cone_radius, cone_radius, cone_height)); @@ -208,11 +207,9 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) glsafe(::glPopMatrix()); } - glsafe(::glPushMatrix()); const double radius = (double)support_point.head_front_radius * RenderPointScale; glsafe(::glScaled(radius, radius, radius)); m_sphere.render(); - glsafe(::glPopMatrix()); if (vol->is_left_handed()) glFrontFace(GL_CCW); @@ -241,7 +238,7 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) Eigen::Quaterniond q; q.setFromTwoVectors(Vec3d{0., 0., 1.}, instance_scaling_matrix_inverse * (-drain_hole.normal).cast()); - Eigen::AngleAxisd aa(q); + const Eigen::AngleAxisd aa(q); glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis().x(), aa.axis().y(), aa.axis().z())); glsafe(::glTranslated(0., 0., -drain_hole.height)); glsafe(::glScaled(drain_hole.radius, drain_hole.radius, drain_hole.height + sla::HoleStickOutLength));