From 2a2d1d85f8e1dcc46f2d97d3e2970e49824997c5 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Mon, 22 Oct 2018 13:27:53 +0200 Subject: [PATCH] Added mirror factors to .3mf import and enabled import factors --- src/libslic3r/Format/3mf.cpp | 22 ++++++++++++++++++---- src/libslic3r/Model.cpp | 4 ++++ src/libslic3r/Technologies.hpp | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/libslic3r/Format/3mf.cpp b/src/libslic3r/Format/3mf.cpp index bf94db6b14..085f55b9bd 100644 --- a/src/libslic3r/Format/3mf.cpp +++ b/src/libslic3r/Format/3mf.cpp @@ -1249,14 +1249,25 @@ namespace Slic3r { void _3MF_Importer::_apply_transform(ModelInstance& instance, const Transform3d& transform) { - // slic3r ModelInstance cannot be transformed using a matrix - // we extract from the given matrix only the values currently used - // translation Vec3d offset = transform.matrix().block(0, 3, 3, 1); - // scale Eigen::Matrix m3x3 = transform.matrix().block(0, 0, 3, 3); +#if ENABLE_MIRROR + // mirror + // it is impossible to reconstruct the original mirroring factors from a matrix, + // we can only detect if the matrix contains a left handed reference system + // in which case we reorient it back to right handed by mirroring the x axis + Vec3d mirror = Vec3d::Ones(); + if (m3x3.col(0).dot(m3x3.col(1).cross(m3x3.col(2))) < 0.0) + { + mirror(0) = -1.0; + // remove mirror + m3x3.col(0) *= -1.0; + } + + // scale +#endif // ENABLE_MIRROR Vec3d scale(m3x3.col(0).norm(), m3x3.col(1).norm(), m3x3.col(2).norm()); // invalid scale value, return @@ -1273,6 +1284,9 @@ namespace Slic3r { instance.set_offset(offset); instance.set_scaling_factor(scale); instance.set_rotation(rotation); +#if ENABLE_MIRROR + instance.set_mirror(mirror); +#endif // ENABLE_MIRROR } bool _3MF_Importer::_handle_start_config(const char** attributes, unsigned int num_attributes) diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index d001acedb1..331d118337 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -711,9 +711,13 @@ void ModelObject::center_around_origin() if (!this->instances.empty()) { for (ModelInstance *i : this->instances) { +#if ENABLE_MIRROR + i->set_offset(i->get_offset() - shift); +#else // apply rotation and scaling to vector as well before translating instance, // in order to leave final position unaltered i->set_offset(i->get_offset() + i->transform_vector(-shift, true)); +#endif // ENABLE_MIRROR } this->invalidate_bounding_box(); } diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 3f8fd80f0b..d80d6df0d7 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -11,7 +11,7 @@ // New selections #define ENABLE_EXTENDED_SELECTION (1 && ENABLE_1_42_0) // Add mirror components along the three axes in ModelInstance and GLVolume -#define ENABLE_MIRROR (0 && ENABLE_1_42_0) +#define ENABLE_MIRROR (1 && ENABLE_1_42_0) #endif // _technologies_h_