From c903414005c20ceec4aba6684a8ad68525eebe1e Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 3 May 2022 11:13:43 +0200 Subject: [PATCH] Cut WIP: Improved can_perform_cut() --- src/slic3r/GUI/Gizmos/GLGizmoCut.cpp | 13 +++++-------- src/slic3r/GUI/Gizmos/GLGizmoCut.hpp | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp index 6fafdbf9b5..09e59d2393 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp @@ -752,7 +752,7 @@ BoundingBoxf3 GLGizmoCut3D::bounding_box() const return ret; } -BoundingBoxf3 GLGizmoCut3D::transformed_bounding_box() const +BoundingBoxf3 GLGizmoCut3D::transformed_bounding_box(bool revert_move /*= false*/) const { // #ysFIXME !!! BoundingBoxf3 ret; @@ -774,8 +774,9 @@ BoundingBoxf3 GLGizmoCut3D::transformed_bounding_box() const const auto rot_z = Geometry::assemble_transform(Vec3d::Zero(), Vec3d(0, 0, -rotation.z()), Vec3d::Ones(), Vec3d::Ones()); const auto rot_y = Geometry::assemble_transform(Vec3d::Zero(), Vec3d(0, -rotation.y(), 0), Vec3d::Ones(), Vec3d::Ones()); const auto rot_x = Geometry::assemble_transform(Vec3d::Zero(), Vec3d(-rotation.x(), 0, 0), Vec3d::Ones(), Vec3d::Ones()); + const auto move2 = Geometry::assemble_transform(m_plane_center, Vec3d::Zero(), Vec3d::Ones(), Vec3d::Ones() ); - const auto cut_matrix = rot_x * rot_y * rot_z * move; + const auto cut_matrix = (revert_move ? move2 : Transform3d::Identity()) * rot_x * rot_y * rot_z * move; for (unsigned int i : idxs) { const GLVolume* volume = selection.get_volume(i); @@ -1202,12 +1203,8 @@ bool GLGizmoCut3D::can_perform_cut() const if (m_has_invalid_connector || (!m_keep_upper && !m_keep_lower)) return false; - BoundingBoxf3 box = bounding_box(); - double dist = (m_plane_center - box.center()).norm(); - if (dist > box.radius()) - return false; - - return true; + const BoundingBoxf3 tbb = transformed_bounding_box(true); + return tbb.contains(m_plane_center); } void GLGizmoCut3D::perform_cut(const Selection& selection) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp b/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp index f8935d61fc..400018897e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp @@ -123,7 +123,7 @@ public: void update_clipper_on_render(); BoundingBoxf3 bounding_box() const; - BoundingBoxf3 transformed_bounding_box() const; + BoundingBoxf3 transformed_bounding_box(bool revert_move = false) const; protected: bool on_init() override;