From 382326ffc85620edbe320e956439caccca9df271 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Wed, 3 Apr 2019 11:12:03 +0200 Subject: [PATCH] Fixed FFF slicing of meshes with left hand oriented transformations applied. Slight optimization of FFF slicing - optimized copy of an object with just a single volume. --- src/libslic3r/PrintObject.cpp | 17 +++++++++-------- src/libslic3r/TriangleMesh.cpp | 7 ++++++- src/libslic3r/TriangleMesh.hpp | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index 6c04c7781..42c6fbf75 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -1790,15 +1790,16 @@ std::vector PrintObject::_slice_volumes(const std::vector &z, if (! volumes.empty()) { // Compose mesh. //FIXME better to perform slicing over each volume separately and then to use a Boolean operation to merge them. - TriangleMesh mesh; - for (const ModelVolume *v : volumes) - { - TriangleMesh vol_mesh(v->mesh); - vol_mesh.transform(v->get_matrix()); + TriangleMesh mesh(volumes.front()->mesh); + mesh.transform(volumes.front()->get_matrix(), true); + for (size_t idx_volume = 1; idx_volume < volumes.size(); ++ idx_volume) { + const ModelVolume &model_volume = *volumes[idx_volume]; + TriangleMesh vol_mesh(model_volume.mesh); + vol_mesh.transform(model_volume.get_matrix(), true); mesh.merge(vol_mesh); } if (mesh.stl.stats.number_of_facets > 0) { - mesh.transform(m_trafo); + mesh.transform(m_trafo, true); // apply XY shift mesh.translate(- unscale(m_copies_shift(0)), - unscale(m_copies_shift(1)), 0); // perform actual slicing @@ -1819,9 +1820,9 @@ std::vector PrintObject::_slice_volume(const std::vector &z, // Compose mesh. //FIXME better to perform slicing over each volume separately and then to use a Boolean operation to merge them. TriangleMesh mesh(volume.mesh); - mesh.transform(volume.get_matrix()); + mesh.transform(volume.get_matrix(), true); if (mesh.stl.stats.number_of_facets > 0) { - mesh.transform(m_trafo); + mesh.transform(m_trafo, true); // apply XY shift mesh.translate(- unscale(m_copies_shift(0)), - unscale(m_copies_shift(1)), 0); // perform actual slicing diff --git a/src/libslic3r/TriangleMesh.cpp b/src/libslic3r/TriangleMesh.cpp index c145380c9..0d9a79978 100644 --- a/src/libslic3r/TriangleMesh.cpp +++ b/src/libslic3r/TriangleMesh.cpp @@ -314,10 +314,15 @@ void TriangleMesh::mirror(const Axis &axis) stl_invalidate_shared_vertices(&this->stl); } -void TriangleMesh::transform(const Transform3d& t) +void TriangleMesh::transform(const Transform3d& t, bool fix_left_handed) { stl_transform(&stl, t); stl_invalidate_shared_vertices(&stl); + if (fix_left_handed && t.matrix().block(0, 0, 3, 3).determinant() < 0.) { + // Left handed transformation is being applied. It is a good idea to flip the faces and their normals. + this->repair(); + stl_reverse_all_facets(&stl); + } } void TriangleMesh::align_to_origin() diff --git a/src/libslic3r/TriangleMesh.hpp b/src/libslic3r/TriangleMesh.hpp index a65a4be75..527846f9d 100644 --- a/src/libslic3r/TriangleMesh.hpp +++ b/src/libslic3r/TriangleMesh.hpp @@ -49,7 +49,7 @@ public: void mirror_x() { this->mirror(X); } void mirror_y() { this->mirror(Y); } void mirror_z() { this->mirror(Z); } - void transform(const Transform3d& t); + void transform(const Transform3d& t, bool fix_left_handed = false); void align_to_origin(); void rotate(double angle, Point* center); TriangleMeshPtrs split() const;