From f2b986af578e3e2aea5970757d28c731b19669a9 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 2 Feb 2023 11:42:21 +0100 Subject: [PATCH] Method Transformation::reset_scaling_factor() modified to use SVD decomposition of transformation matrix and object manipulator reset button set to use it --- src/libslic3r/Geometry.cpp | 6 ++++++ src/libslic3r/Geometry.hpp | 2 +- src/slic3r/GUI/GUI_ObjectManipulation.cpp | 17 ++++++----------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/libslic3r/Geometry.cpp b/src/libslic3r/Geometry.cpp index ec37766473..c815719b7a 100644 --- a/src/libslic3r/Geometry.cpp +++ b/src/libslic3r/Geometry.cpp @@ -720,6 +720,12 @@ void Transformation::reset() } #if ENABLE_WORLD_COORDINATE +void Transformation::reset_scaling_factor() +{ + const Geometry::TransformationSVD svd(*this); + m_matrix = get_offset_matrix() * Transform3d(svd.u) * Transform3d(svd.v.transpose()); +} + void Transformation::reset_skew() { auto new_scale_factor = [](const Matrix3d& s) { diff --git a/src/libslic3r/Geometry.hpp b/src/libslic3r/Geometry.hpp index 7e1624afc6..531f7cac80 100644 --- a/src/libslic3r/Geometry.hpp +++ b/src/libslic3r/Geometry.hpp @@ -493,7 +493,7 @@ public: #if ENABLE_WORLD_COORDINATE void reset_offset() { set_offset(Vec3d::Zero()); } void reset_rotation() { set_rotation(Vec3d::Zero()); } - void reset_scaling_factor() { set_scaling_factor(Vec3d::Ones()); } + 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 d1f065221e..a80b47d2dd 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -484,24 +484,19 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) : GLCanvas3D* canvas = wxGetApp().plater()->canvas3D(); Selection& selection = canvas->get_selection(); if (selection.is_single_volume_or_modifier()) { - const bool is_left_handed = selection.get_first_volume()->get_volume_transformation().is_left_handed(); - const_cast(selection.get_first_volume())->set_volume_scaling_factor(Vec3d::Ones()); - if (is_left_handed) - const_cast(selection.get_first_volume())->set_volume_mirror({ -1.0 , 1.0, 1.0 }); + Geometry::Transformation trafo = selection.get_first_volume()->get_volume_transformation(); + trafo.reset_scaling_factor(); + const_cast(selection.get_first_volume())->set_volume_transformation(trafo); } else if (selection.is_single_full_instance()) { - const bool is_left_handed = selection.get_first_volume()->get_instance_transformation().is_left_handed(); - for (unsigned int idx : selection.get_volume_idxs()) { - const_cast(selection.get_volume(idx))->set_instance_scaling_factor(Vec3d::Ones()); - if (is_left_handed) - const_cast(selection.get_volume(idx))->set_instance_mirror({ -1.0 , 1.0, 1.0 }); - } + Geometry::Transformation trafo = selection.get_first_volume()->get_instance_transformation(); + trafo.reset_scaling_factor(); + const_cast(selection.get_first_volume())->set_instance_transformation(trafo); } else return; canvas->do_scale(L("Reset scale")); - UpdateAndShow(true); #else Plater::TakeSnapshot snapshot(wxGetApp().plater(), _L("Reset scale"));