From 4846b504a2977dc31fe8db3855356cc2cc621466 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 19 May 2022 12:19:18 +0200 Subject: [PATCH] Tech ENABLE_TRANSFORMATIONS_BY_MATRICES - Improved detection and removal of skew in matrices Fixed conflicts during rebase with master --- src/slic3r/GUI/GUI_ObjectManipulation.cpp | 30 ++++---------- src/slic3r/GUI/Selection.cpp | 50 +++++++++++++++-------- 2 files changed, 43 insertions(+), 37 deletions(-) diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index ff8fe940c..c6ca3f746 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -944,18 +944,12 @@ void ObjectManipulation::update_reset_buttons_visibility() const Geometry::Transformation& trafo = volume->get_instance_transformation(); rotation = trafo.get_rotation_matrix(); scale = trafo.get_scaling_factor_matrix(); - if (trafo.has_skew()) - // the instance transform contains skew - skew = trafo; - else { - // the world transform contains skew - const Selection::IndicesList& idxs = selection.get_volume_idxs(); - for (unsigned int id : idxs) { - const Geometry::Transformation world_trafo(selection.get_volume(id)->world_matrix()); - if (world_trafo.has_skew()) { - skew = world_trafo; - break; - } + const Selection::IndicesList& idxs = selection.get_volume_idxs(); + for (unsigned int id : idxs) { + const Geometry::Transformation world_trafo(selection.get_volume(id)->world_matrix()); + if (world_trafo.has_skew()) { + skew = world_trafo; + break; } } #else @@ -971,15 +965,9 @@ void ObjectManipulation::update_reset_buttons_visibility() const Geometry::Transformation& trafo = volume->get_volume_transformation(); rotation = trafo.get_rotation_matrix(); scale = trafo.get_scaling_factor_matrix(); - if (trafo.has_skew()) - // the volume transform contains skew - skew = trafo; - else { - // the world transform contains skew - const Geometry::Transformation world_trafo(volume->world_matrix()); - if (world_trafo.has_skew()) - skew = world_trafo; - } + const Geometry::Transformation world_trafo(volume->world_matrix()); + if (world_trafo.has_skew()) + skew = world_trafo; #else rotation = volume->get_volume_rotation(); scale = volume->get_volume_scaling_factor(); diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index be6abeee3..02edd9c31 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -1495,23 +1495,41 @@ void Selection::reset_skew() for (unsigned int i : m_list) { GLVolume& v = *(*m_volumes)[i]; const VolumeCache& volume_data = m_cache.volumes_data[i]; - const Geometry::Transformation& inst_trafo = volume_data.get_instance_transform(); - const Geometry::Transformation& vol_trafo = volume_data.get_volume_transform(); - const Geometry::Transformation world_trafo = inst_trafo * vol_trafo; - if (!inst_trafo.has_skew() && !vol_trafo.has_skew() && world_trafo.has_skew()) { - Geometry::Transformation mod_world_trafo = Geometry::Transformation(world_trafo.get_matrix_no_offset()); - mod_world_trafo.reset_skew(); - v.set_volume_transformation(vol_trafo.get_offset_matrix() * inst_trafo.get_matrix_no_offset().inverse() * mod_world_trafo.get_matrix()); + Geometry::Transformation inst_trafo = volume_data.get_instance_transform(); + Geometry::Transformation vol_trafo = volume_data.get_volume_transform(); + Geometry::Transformation world_trafo = inst_trafo * vol_trafo; + if (world_trafo.has_skew()) { + if (!inst_trafo.has_skew() && !vol_trafo.has_skew()) { + // = [I][V] + world_trafo.reset_offset(); + world_trafo.reset_skew(); + v.set_volume_transformation(vol_trafo.get_offset_matrix() * inst_trafo.get_matrix_no_offset().inverse() * world_trafo.get_matrix()); + } + else { + // = + // = [V] + // = [I] + if (inst_trafo.has_skew()) { + inst_trafo.reset_skew(); + v.set_instance_transformation(inst_trafo); + } + if (vol_trafo.has_skew()) { + vol_trafo.reset_skew(); + v.set_volume_transformation(vol_trafo); + } + } } - else if (m_mode == Instance && inst_trafo.has_skew()) { - Geometry::Transformation trafo = inst_trafo; - trafo.reset_skew(); - v.set_instance_transformation(trafo); - } - else if (m_mode == Volume && vol_trafo.has_skew()) { - Geometry::Transformation trafo = vol_trafo; - trafo.reset_skew(); - v.set_volume_transformation(trafo); + else { + // [W] = [I][V] + // [W] = + if (inst_trafo.has_skew()) { + inst_trafo.reset_skew(); + v.set_instance_transformation(inst_trafo); + } + if (vol_trafo.has_skew()) { + vol_trafo.reset_skew(); + v.set_volume_transformation(vol_trafo); + } } }