diff options
author | Enrico Turri <enricoturri@seznam.cz> | 2018-09-04 15:43:14 +0300 |
---|---|---|
committer | Enrico Turri <enricoturri@seznam.cz> | 2018-09-04 15:43:14 +0300 |
commit | 6b1b2bad76b87cfd9e1f5ef511e11a6ce0b5ddeb (patch) | |
tree | 6c3114a796de1c334eca3994587df0b999c9c418 /xs/src/libslic3r | |
parent | ab1517caf59e1b4b3bf5af12a75812e144f11e42 (diff) | |
parent | 15b13405141ca7481f156d204a917fab38c30dc1 (diff) |
Merge branch 'dev' of https://github.com/prusa3d/Slic3r into dev
Diffstat (limited to 'xs/src/libslic3r')
-rw-r--r-- | xs/src/libslic3r/Model.cpp | 70 | ||||
-rw-r--r-- | xs/src/libslic3r/Model.hpp | 2 | ||||
-rw-r--r-- | xs/src/libslic3r/TriangleMesh.cpp | 9 | ||||
-rw-r--r-- | xs/src/libslic3r/TriangleMesh.hpp | 1 |
4 files changed, 42 insertions, 40 deletions
diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 1cd3b1413..36c210844 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -672,20 +672,18 @@ void ModelObject::center_around_origin() // First align to origin on XYZ, then center it on XY. Vec3d size = bb.size(); - size(2) = 0.; - Vec3d shift3 = - bb.min - 0.5 * size; - // Unaligned vector, for the Rotation2D to work on Visual Studio 2013. - Eigen::Vector2d shift2 = to_2d(shift3); - - this->translate(shift3); - this->origin_translation += shift3; - + size(2) = 0.0; + Vec3d shift = -bb.min - 0.5 * size; + + this->translate(shift); + this->origin_translation += shift; + if (!this->instances.empty()) { for (ModelInstance *i : this->instances) { // apply rotation and scaling to vector as well before translating instance, // in order to leave final position unaltered - Eigen::Rotation2Dd rot(i->rotation); - i->offset -= rot * shift2 * i->scaling_factor; + Vec3d i_shift = i->world_matrix(true) * shift; + i->offset -= to_2d(i_shift); } this->invalidate_bounding_box(); } @@ -861,12 +859,7 @@ void ModelObject::check_instances_print_volume_state(const BoundingBoxf3& print_ { for (ModelInstance* inst : this->instances) { - Transform3d m = Transform3d::Identity(); - m.translate(Vec3d(inst->offset(0), inst->offset(1), 0.0)); - m.rotate(Eigen::AngleAxisd(inst->rotation, Vec3d::UnitZ())); - m.scale(inst->scaling_factor); - - BoundingBoxf3 bb = vol->get_convex_hull().transformed_bounding_box(m); + BoundingBoxf3 bb = vol->get_convex_hull().transformed_bounding_box(inst->world_matrix()); if (print_volume.contains(bb)) inst->print_volume_state = ModelInstance::PVS_Inside; @@ -995,26 +988,17 @@ size_t ModelVolume::split(unsigned int max_extruders) void ModelInstance::transform_mesh(TriangleMesh* mesh, bool dont_translate) const { - mesh->rotate_z(this->rotation); // rotate around mesh origin - mesh->scale(this->scaling_factor); // scale around mesh origin - if (!dont_translate) - mesh->translate(this->offset(0), this->offset(1), 0); + mesh->transform(world_matrix(dont_translate).cast<float>()); } BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mesh, bool dont_translate) const { // Rotate around mesh origin. - double c = cos(this->rotation); - double s = sin(this->rotation); - BoundingBoxf3 bbox; - for (int i = 0; i < mesh->stl.stats.number_of_facets; ++ i) { - const stl_facet &facet = mesh->stl.facet_start[i]; - for (int j = 0; j < 3; ++ j) { - const stl_vertex &v = facet.vertex[j]; - bbox.merge(Vec3d(c * v(0) - s * v(1), s * v(0) + c * v(1), v(2))); - } - } - if (! empty(bbox)) { + TriangleMesh copy(*mesh); + copy.transform(world_matrix(dont_translate, false, true).cast<float>()); + BoundingBoxf3 bbox = copy.bounding_box(); + + if (!empty(bbox)) { // Scale the bounding box uniformly. if (std::abs(this->scaling_factor - 1.) > EPSILON) { bbox.min *= this->scaling_factor; @@ -1031,13 +1015,7 @@ BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mes BoundingBoxf3 ModelInstance::transform_bounding_box(const BoundingBoxf3 &bbox, bool dont_translate) const { - Transform3d matrix = Transform3d::Identity(); - if (!dont_translate) - matrix.translate(Vec3d(offset(0), offset(1), 0.0)); - - matrix.rotate(Eigen::AngleAxisd(rotation, Vec3d::UnitZ())); - matrix.scale(scaling_factor); - return bbox.transformed(matrix); + return bbox.transformed(world_matrix(dont_translate)); } void ModelInstance::transform_polygon(Polygon* polygon) const @@ -1046,4 +1024,20 @@ void ModelInstance::transform_polygon(Polygon* polygon) const polygon->scale(this->scaling_factor); // scale around polygon origin } +Transform3d ModelInstance::world_matrix(bool dont_translate, bool dont_rotate, bool dont_scale) const +{ + Transform3d m = Transform3d::Identity(); + + if (!dont_translate) + m.translate(Vec3d(offset(0), offset(1), 0.0)); + + if (!dont_rotate) + m.rotate(Eigen::AngleAxisd(rotation, Vec3d::UnitZ())); + + if (!dont_scale) + m.scale(scaling_factor); + + return m; +} + } diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index f8a36527d..66b53618a 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -243,6 +243,8 @@ public: // To be called on an external polygon. It does not translate the polygon, only rotates and scales. void transform_polygon(Polygon* polygon) const; + Transform3d world_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false) const; + bool is_printable() const { return print_volume_state == PVS_Inside; } private: diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index 6840bc96e..6d40731f8 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -264,7 +264,7 @@ void TriangleMesh::rotate(float angle, const Vec3d& axis) Vec3f axis_norm = axis.cast<float>().normalized(); Transform3f m = Transform3f::Identity(); m.rotate(Eigen::AngleAxisf(angle, axis_norm)); - stl_transform(&stl, (float*)m.data()); + stl_transform(&stl, m); } void TriangleMesh::mirror(const Axis &axis) @@ -279,6 +279,11 @@ void TriangleMesh::mirror(const Axis &axis) stl_invalidate_shared_vertices(&this->stl); } +void TriangleMesh::transform(const Transform3f& t) +{ + stl_transform(&stl, t); +} + void TriangleMesh::align_to_origin() { this->translate( @@ -523,9 +528,9 @@ BoundingBoxf3 TriangleMesh::transformed_bounding_box(const Transform3d& t) const src_vertices(0, v_id) = (double)facet_ptr->vertex[i](0); src_vertices(1, v_id) = (double)facet_ptr->vertex[i](1); src_vertices(2, v_id) = (double)facet_ptr->vertex[i](2); + ++v_id; } facet_ptr += 1; - ++v_id; } } diff --git a/xs/src/libslic3r/TriangleMesh.hpp b/xs/src/libslic3r/TriangleMesh.hpp index 666252887..aebed4a2e 100644 --- a/xs/src/libslic3r/TriangleMesh.hpp +++ b/xs/src/libslic3r/TriangleMesh.hpp @@ -48,6 +48,7 @@ public: void mirror_x() { this->mirror(X); } void mirror_y() { this->mirror(Y); } void mirror_z() { this->mirror(Z); } + void transform(const Transform3f& t); void align_to_origin(); void rotate(double angle, Point* center); TriangleMeshPtrs split() const; |