From 021688fe500536debbe5c058d9961b8e084874f2 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Thu, 12 Aug 2021 10:17:59 +0200 Subject: [PATCH] Fix place on bed and sinking instances: all sinking objects were incorrectly shifted to bed when 'place on face' was applied to any object. --- src/slic3r/GUI/GLCanvas3D.cpp | 17 +++++++++++------ src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp | 2 ++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 93271d796..529056e99 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3455,12 +3455,17 @@ void GLCanvas3D::do_rotate(const std::string& snapshot_type) // stores current min_z of instances std::map, double> min_zs; - if (!snapshot_type.empty()) { - for (int i = 0; i < static_cast(m_model->objects.size()); ++i) { - const ModelObject* obj = m_model->objects[i]; - for (int j = 0; j < static_cast(obj->instances.size()); ++j) { + for (int i = 0; i < static_cast(m_model->objects.size()); ++i) { + const ModelObject* obj = m_model->objects[i]; + for (int j = 0; j < static_cast(obj->instances.size()); ++j) { + if (snapshot_type.empty() && m_selection.get_object_idx() == i) { + // This means we are flattening this object. In that case pretend + // that it is not sinking (even if it is), so it is placed on bed + // later on (whatever is sinking will be left sinking). + min_zs[{ i, j }] = SINKING_Z_THRESHOLD; + } else min_zs[{ i, j }] = obj->instance_bounding_box(j).min.z(); - } + } } @@ -3502,7 +3507,7 @@ void GLCanvas3D::do_rotate(const std::string& snapshot_type) ModelObject* m = m_model->objects[i.first]; const double shift_z = m->get_instance_min_z(i.second); // leave sinking instances as sinking - if (min_zs.empty() || min_zs.find({ i.first, i.second })->second >= SINKING_Z_THRESHOLD || shift_z > SINKING_Z_THRESHOLD) { + if (min_zs.find({ i.first, i.second })->second >= SINKING_Z_THRESHOLD || shift_z > SINKING_Z_THRESHOLD) { const Vec3d shift(0.0, 0.0, -shift_z); m_selection.translate(i.first, i.second, shift); m->translate_instance(i.second, shift); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp index 094805abc..3e5c12eec 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp @@ -42,6 +42,8 @@ std::string GLGizmoFlatten::on_get_name() const bool GLGizmoFlatten::on_is_activable() const { + // This is assumed in GLCanvas3D::do_rotate, do not change this + // without updating that function too. return m_parent.get_selection().is_single_full_instance(); }