From d98fd64534570e406cabef8895fc98c34687d18f Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 2 Feb 2023 12:40:28 +0100 Subject: [PATCH] Method Transformation::reset_rotation() modified to use SVD decomposition of transformation matrix and object manipulator reset button set to use it --- src/libslic3r/Geometry.cpp | 7 +++++++ src/libslic3r/Geometry.hpp | 2 +- src/slic3r/GUI/GUI_ObjectManipulation.cpp | 22 ++++++++++++++++------ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/libslic3r/Geometry.cpp b/src/libslic3r/Geometry.cpp index c815719b7a..f3b8926d92 100644 --- a/src/libslic3r/Geometry.cpp +++ b/src/libslic3r/Geometry.cpp @@ -720,6 +720,13 @@ void Transformation::reset() } #if ENABLE_WORLD_COORDINATE +void Transformation::reset_rotation() +{ + const Geometry::TransformationSVD svd(*this); + const Transform3d mirror = is_left_handed() ? Geometry::scale_transform({ -1.0, 1.0, 1.0 }) : Transform3d::Identity(); + m_matrix = get_offset_matrix() * mirror * Transform3d(svd.v * svd.s * svd.v.transpose()); +} + void Transformation::reset_scaling_factor() { const Geometry::TransformationSVD svd(*this); diff --git a/src/libslic3r/Geometry.hpp b/src/libslic3r/Geometry.hpp index 531f7cac80..f7b08b9b29 100644 --- a/src/libslic3r/Geometry.hpp +++ b/src/libslic3r/Geometry.hpp @@ -492,7 +492,7 @@ public: void reset(); #if ENABLE_WORLD_COORDINATE void reset_offset() { set_offset(Vec3d::Zero()); } - void reset_rotation() { set_rotation(Vec3d::Zero()); } + void reset_rotation(); void reset_scaling_factor(); void reset_mirror() { set_mirror(Vec3d::Ones()); } void reset_skew(); diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index a80b47d2dd..1d6212ce58 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -448,14 +448,21 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) : Selection& selection = canvas->get_selection(); #if ENABLE_WORLD_COORDINATE - if (selection.is_single_volume_or_modifier()) + if (selection.is_single_volume_or_modifier()) { + GLVolume* vol = const_cast(selection.get_first_volume()); + Geometry::Transformation trafo = vol->get_volume_transformation(); + trafo.reset_rotation(); + vol->set_volume_transformation(trafo); + } #else if (selection.is_single_volume() || selection.is_single_modifier()) -#endif // ENABLE_WORLD_COORDINATE const_cast(selection.get_first_volume())->set_volume_rotation(Vec3d::Zero()); +#endif // ENABLE_WORLD_COORDINATE else if (selection.is_single_full_instance()) { + Geometry::Transformation trafo = selection.get_first_volume()->get_instance_transformation(); + trafo.reset_rotation(); for (unsigned int idx : selection.get_volume_idxs()) { - const_cast(selection.get_volume(idx))->set_instance_rotation(Vec3d::Zero()); + const_cast(selection.get_volume(idx))->set_instance_transformation(trafo); } } else @@ -484,14 +491,17 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) : GLCanvas3D* canvas = wxGetApp().plater()->canvas3D(); Selection& selection = canvas->get_selection(); if (selection.is_single_volume_or_modifier()) { - Geometry::Transformation trafo = selection.get_first_volume()->get_volume_transformation(); + GLVolume* vol = const_cast(selection.get_first_volume()); + Geometry::Transformation trafo = vol->get_volume_transformation(); trafo.reset_scaling_factor(); - const_cast(selection.get_first_volume())->set_volume_transformation(trafo); + vol->set_volume_transformation(trafo); } else if (selection.is_single_full_instance()) { Geometry::Transformation trafo = selection.get_first_volume()->get_instance_transformation(); trafo.reset_scaling_factor(); - const_cast(selection.get_first_volume())->set_instance_transformation(trafo); + for (unsigned int idx : selection.get_volume_idxs()) { + const_cast(selection.get_volume(idx))->set_instance_transformation(trafo); + } } else return;