Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorenricoturri1966 <enricoturri@seznam.cz>2022-05-05 09:14:59 +0300
committerenricoturri1966 <enricoturri@seznam.cz>2022-06-06 09:50:57 +0300
commitf9f7e6e75995165cf8485cab506ada6522233d5b (patch)
tree4a49f26cff7899246c0e49d74fc8b8d398ea1232
parent0e3490620e2b835b7382d23b6d0022205e9293f4 (diff)
Tech ENABLE_TRANSFORMATIONS_BY_MATRICES - Reworked method void Selection::flattening_rotate(const Vec3d& normal) to use matrix multiplication
Fixed conflicts during rebase with master
-rw-r--r--src/slic3r/GUI/Selection.cpp32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp
index 18b3cfaa7..e2a5b4a9d 100644
--- a/src/slic3r/GUI/Selection.cpp
+++ b/src/slic3r/GUI/Selection.cpp
@@ -1158,13 +1158,21 @@ void Selection::flattening_rotate(const Vec3d& normal)
for (unsigned int i : m_list) {
GLVolume& v = *(*m_volumes)[i];
// Normal transformed from the object coordinate space to the world coordinate space.
- const auto &voldata = m_cache.volumes_data[i];
+#if ENABLE_TRANSFORMATIONS_BY_MATRICES
+ const Geometry::Transformation& old_inst_trafo = v.get_instance_transformation();
+ const Vec3d tnormal = old_inst_trafo.get_matrix().matrix().block(0, 0, 3, 3).inverse().transpose() * normal;
+ // Additional rotation to align tnormal with the down vector in the world coordinate space.
+ const Transform3d rotation_matrix = Transform3d(Eigen::Quaterniond().setFromTwoVectors(tnormal, -Vec3d::UnitZ()));
+ v.set_instance_transformation(old_inst_trafo.get_offset_matrix() * rotation_matrix * old_inst_trafo.get_matrix_no_offset());
+#else
+ const auto& voldata = m_cache.volumes_data[i];
Vec3d tnormal = (Geometry::assemble_transform(
- Vec3d::Zero(), voldata.get_instance_rotation(),
+ Vec3d::Zero(), voldata.get_instance_rotation(),
voldata.get_instance_scaling_factor().cwiseInverse(), voldata.get_instance_mirror()) * normal).normalized();
// Additional rotation to align tnormal with the down vector in the world coordinate space.
- auto extra_rotation = Eigen::Quaterniond().setFromTwoVectors(tnormal, - Vec3d::UnitZ());
+ auto extra_rotation = Eigen::Quaterniond().setFromTwoVectors(tnormal, -Vec3d::UnitZ());
v.set_instance_rotation(Geometry::extract_euler_angles(extra_rotation.toRotationMatrix() * m_cache.volumes_data[i].get_instance_rotation_matrix()));
+#endif // ENABLE_TRANSFORMATIONS_BY_MATRICES
}
#if !DISABLE_INSTANCES_SYNCH
@@ -1648,12 +1656,11 @@ void Selection::render(float scale_factor)
else if (coordinates_type == ECoordinatesType::Local && is_single_volume_or_modifier()) {
const GLVolume& v = *get_first_volume();
#if ENABLE_TRANSFORMATIONS_BY_MATRICES
- const Geometry::Transformation inst_trafo = get_first_volume()->get_instance_transformation();
- box = box.transformed(inst_trafo.get_scaling_factor_matrix());
- trafo = inst_trafo.get_matrix_no_scaling_factor();
+ box = v.transformed_convex_hull_bounding_box(v.get_volume_transformation().get_scaling_factor_matrix());
+ trafo = v.get_instance_transformation().get_matrix() * v.get_volume_transformation().get_matrix_no_scaling_factor();
#else
- box = box.transformed(get_first_volume()->get_instance_transformation().get_matrix(true, true, false, true));
- trafo = get_first_volume()->get_instance_transformation().get_matrix(false, false, true, false);
+ box = v.transformed_convex_hull_bounding_box(v.get_instance_transformation().get_matrix(true, true, false, true) * v.get_volume_transformation().get_matrix(true, true, false, true));
+ trafo = v.get_instance_transformation().get_matrix(false, false, true, false) * v.get_volume_transformation().get_matrix(false, false, true, false);
#endif // ENABLE_TRANSFORMATIONS_BY_MATRICES
}
else {
@@ -1663,11 +1670,12 @@ void Selection::render(float scale_factor)
box.merge(v.transformed_convex_hull_bounding_box(v.get_volume_transformation().get_matrix()));
}
#if ENABLE_TRANSFORMATIONS_BY_MATRICES
- box = box.transformed(get_volume(*ids.begin())->get_instance_transformation().get_scaling_factor_matrix());
- trafo = get_volume(*ids.begin())->get_instance_transformation().get_matrix_no_scaling_factor();
+ const Geometry::Transformation inst_trafo = get_first_volume()->get_instance_transformation();
+ box = box.transformed(inst_trafo.get_scaling_factor_matrix());
+ trafo = inst_trafo.get_matrix_no_scaling_factor();
#else
- box = box.transformed(get_volume(*ids.begin())->get_instance_transformation().get_matrix(true, true, false, true));
- trafo = get_volume(*ids.begin())->get_instance_transformation().get_matrix(false, false, true, false);
+ box = box.transformed(get_first_volume()->get_instance_transformation().get_matrix(true, true, false, true));
+ trafo = get_first_volume()->get_instance_transformation().get_matrix(false, false, true, false);
#endif // ENABLE_TRANSFORMATIONS_BY_MATRICES
}