From e3d648c8025edfd0465ae543c58a21846f04e685 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 18 May 2022 10:58:27 +0200 Subject: [PATCH] Tech ENABLE_TRANSFORMATIONS_BY_MATRICES - Reoworked calculation of volume matrix for newly added modifiers and parts Fixed conflicts during rebase with master --- src/libslic3r/Geometry.cpp | 6 ++---- src/libslic3r/Geometry.hpp | 2 ++ src/slic3r/GUI/GUI_ObjectList.cpp | 14 +++++++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/libslic3r/Geometry.cpp b/src/libslic3r/Geometry.cpp index a611e10c0..6e593af94 100644 --- a/src/libslic3r/Geometry.cpp +++ b/src/libslic3r/Geometry.cpp @@ -764,6 +764,7 @@ Transformation Transformation::operator * (const Transformation& other) const return Transformation(get_matrix() * other.get_matrix()); } +#if !ENABLE_TRANSFORMATIONS_BY_MATRICES Transformation Transformation::volume_to_bed_transformation(const Transformation& instance_transformation, const BoundingBoxf3& bbox) { Transformation out; @@ -771,11 +772,7 @@ Transformation Transformation::volume_to_bed_transformation(const Transformation if (instance_transformation.is_scaling_uniform()) { // No need to run the non-linear least squares fitting for uniform scaling. // Just set the inverse. -#if ENABLE_TRANSFORMATIONS_BY_MATRICES - out.set_matrix(instance_transformation.get_matrix_no_offset().inverse()); -#else out.set_from_transform(instance_transformation.get_matrix(true).inverse()); -#endif // ENABLE_TRANSFORMATIONS_BY_MATRICES } else if (is_rotation_ninety_degrees(instance_transformation.get_rotation())) { // Anisotropic scaling, rotation by multiples of ninety degrees. @@ -823,6 +820,7 @@ Transformation Transformation::volume_to_bed_transformation(const Transformation return out; } +#endif // !ENABLE_TRANSFORMATIONS_BY_MATRICES // For parsing a transformation matrix from 3MF / AMF. Transform3d transform3d_from_string(const std::string& transform_str) diff --git a/src/libslic3r/Geometry.hpp b/src/libslic3r/Geometry.hpp index 0d804c52c..725ced361 100644 --- a/src/libslic3r/Geometry.hpp +++ b/src/libslic3r/Geometry.hpp @@ -509,10 +509,12 @@ public: Transformation operator * (const Transformation& other) const; +#if !ENABLE_TRANSFORMATIONS_BY_MATRICES // Find volume transformation, so that the chained (instance_trafo * volume_trafo) will be as close to identity // as possible in least squares norm in regard to the 8 corners of bbox. // Bounding box is expected to be centered around zero in all axes. static Transformation volume_to_bed_transformation(const Transformation& instance_transformation, const BoundingBoxf3& bbox); +#endif // !ENABLE_TRANSFORMATIONS_BY_MATRICES private: friend class cereal::access; diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index ecf015b6d..73946786d 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -1584,9 +1584,15 @@ void ObjectList::load_modifier(const wxArrayString& input_files, ModelObject& mo new_volume->source.mesh_offset = model.objects.front()->volumes.front()->source.mesh_offset; if (from_galery) { +#if ENABLE_TRANSFORMATIONS_BY_MATRICES + new_volume->set_transformation(v->get_instance_transformation().get_matrix_no_offset().inverse()); + // Transform the new modifier to be aligned with the print bed. + const BoundingBoxf3 mesh_bb = new_volume->mesh().bounding_box(); +#else // Transform the new modifier to be aligned with the print bed. const BoundingBoxf3 mesh_bb = new_volume->mesh().bounding_box(); new_volume->set_transformation(Geometry::Transformation::volume_to_bed_transformation(inst_transform, mesh_bb)); +#endif // ENABLE_TRANSFORMATIONS_BY_MATRICES // Set the modifier position. // Translate the new modifier to be pickable: move to the left front corner of the instance's bounding box, lift to print bed. const Vec3d offset = Vec3d(instance_bb.max.x(), instance_bb.min.y(), instance_bb.min.z()) + 0.5 * mesh_bb.size() - instance_offset; @@ -1655,9 +1661,15 @@ void ObjectList::load_generic_subobject(const std::string& type_name, const Mode // First (any) GLVolume of the selected instance. They all share the same instance matrix. const GLVolume* v = selection.get_first_volume(); +#if ENABLE_TRANSFORMATIONS_BY_MATRICES + new_volume->set_transformation(v->get_instance_transformation().get_matrix_no_offset().inverse()); // Transform the new modifier to be aligned with the print bed. - const BoundingBoxf3 mesh_bb = new_volume->mesh().bounding_box(); + const BoundingBoxf3 mesh_bb = new_volume->mesh().bounding_box(); +#else + // Transform the new modifier to be aligned with the print bed. + const BoundingBoxf3 mesh_bb = new_volume->mesh().bounding_box(); new_volume->set_transformation(Geometry::Transformation::volume_to_bed_transformation(v->get_instance_transformation(), mesh_bb)); +#endif // ENABLE_TRANSFORMATIONS_BY_MATRICES // Set the modifier position. auto offset = (type_name == "Slab") ? // Slab: Lift to print bed