From 1f41a3da7adf2408e7e8ff20104865d095ac49ec Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Fri, 14 Mar 2025 19:43:25 +0800 Subject: [PATCH] FIX:Rotation gizmo coincides with the cut coordinate system in cut gizmo jira: STUDIO-10868 Change-Id: Ifec448e4d0bab518c07c9d198304daa8c0e95999 --- src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.cpp | 4 ++++ src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp | 21 +++++++++++++++----- src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp | 5 ++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.cpp b/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.cpp index de28cd7fa..e768a5d25 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.cpp @@ -1390,6 +1390,10 @@ void GLGizmoAdvancedCut::on_render_rotate_gizmos() { m_gizmos[Z].render(); } else { + Transform3d rotate_tran = Geometry::translation_transform(m_plane_center) * m_rotate_matrix; + for (int i = 0; i < 3; i++) { + m_gizmos[i].set_custom_tran(rotate_tran); + } m_gizmos[X].render(); m_gizmos[Y].render(); m_gizmos[Z].render(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp index fbbdb2fce..d3cc5f9ed 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp @@ -539,9 +539,16 @@ void GLGizmoRotate::init_data_from_selection(const Selection &selection) { selection.get_bounding_box_in_current_reference_system(); m_bounding_box = box; const std::pair sphere = selection.get_bounding_sphere(); - m_center = sphere.first; - m_radius = Offset +sphere.second; - m_orient_matrix = box_trafo; + if (m_custom_tran.has_value()) { + Geometry::Transformation tran(m_custom_tran.value()); + m_center = tran.get_offset(); + m_orient_matrix = tran.get_matrix(); + } else { + m_center = sphere.first; + m_orient_matrix = box_trafo; + } + m_radius = Offset + sphere.second; + m_orient_matrix.translation() = m_center; m_snap_coarse_in_radius = 1.0f / 3.0f; m_snap_coarse_out_radius = 2.0f * m_snap_coarse_in_radius; @@ -550,6 +557,10 @@ void GLGizmoRotate::init_data_from_selection(const Selection &selection) { } +void GLGizmoRotate::set_custom_tran(const Transform3d &tran) { + m_custom_tran = tran; +} + BoundingBoxf3 GLGizmoRotate::get_bounding_box() const { BoundingBoxf3 t_aabb; @@ -566,7 +577,7 @@ BoundingBoxf3 GLGizmoRotate::get_bounding_box() const t_aabb.defined = true; } // end m_circle aabb - + // m_grabber_connection aabb if (m_grabber_connection.model.is_initialized()) { BoundingBoxf3 t_grabber_connection_aabb = m_grabber_connection.model.get_bounding_box(); @@ -586,7 +597,7 @@ BoundingBoxf3 GLGizmoRotate::get_bounding_box() const t_aabb.defined = true; } // end m_grabbers aabb - + // m_cone aabb if (m_cone.is_initialized()) { auto t_cone_aabb = m_cone.get_bounding_box(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp index d2ea6fcda..2699d9256 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp @@ -74,7 +74,7 @@ public: void set_center(const Vec3d &point) { m_custom_center = point; } void set_force_local_coordinate(bool use) { m_force_local_coordinate = use; } void init_data_from_selection(const Selection &selection); - + void set_custom_tran(const Transform3d &tran); BoundingBoxf3 get_bounding_box() const override; protected: @@ -98,6 +98,9 @@ private: Transform3d transform_to_local(const Selection& selection) const; // returns the intersection of the mouse ray with the plane perpendicular to the gizmo axis, in local coordinate Vec3d mouse_position_in_local_plane(const Linef3& mouse_ray, const Selection& selection) const; + +private: + std::optional m_custom_tran; }; class GLGizmoRotate3D : public GLGizmoBase