From 6831b7094a47a1dfcc6a283b9156f3026adf0b0c Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Mon, 3 Apr 2023 16:02:26 +0200 Subject: [PATCH 1/2] Trying to fix transformation assembly problem for arrange polyogon --- src/libslic3r/Model.cpp | 13 +++++++------ src/libslic3r/Model.hpp | 13 ++++++++++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 6c350e7b4..f0ad7e1e0 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -2406,11 +2406,12 @@ arrangement::ArrangePolygon ModelInstance::get_arrange_polygon() const { // static const double SIMPLIFY_TOLERANCE_MM = 0.1; - Vec3d rotation = get_rotation(); - rotation.z() = 0.; - Transform3d trafo_instance = Geometry::assemble_transform(get_offset().z() * Vec3d::UnitZ(), rotation, get_scaling_factor(), get_mirror()); +// Vec3d rotation = get_rotation(); +// rotation.z() = 0.; +// Transform3d trafo_instance = Geometry::assemble_transform(get_offset().z() * Vec3d::UnitZ(), rotation, get_scaling_factor(), get_mirror()); - Polygon p = get_object()->convex_hull_2d(trafo_instance); + + Polygon p = get_object()->convex_hull_2d(this->get_matrix()); // if (!p.points.empty()) { // Polygons pp{p}; @@ -2420,8 +2421,8 @@ arrangement::ArrangePolygon ModelInstance::get_arrange_polygon() const arrangement::ArrangePolygon ret; ret.poly.contour = std::move(p); - ret.translation = Vec2crd{scaled(get_offset(X)), scaled(get_offset(Y))}; - ret.rotation = get_rotation(Z); + ret.translation = Vec2crd::Zero(); //Vec2crd{scaled(get_offset(X)), scaled(get_offset(Y))}; + ret.rotation = 0.; return ret; } diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index 55aceeeb2..d29ce3525 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -1170,9 +1170,16 @@ public: void apply_arrange_result(const Vec2d& offs, double rotation) { // write the transformation data into the model instance - set_rotation(Z, rotation); - set_offset(X, unscale(offs(X))); - set_offset(Y, unscale(offs(Y))); +// set_rotation(Z, rotation); +// set_offset(X, unscale(offs(X))); +// set_offset(Y, unscale(offs(Y))); + auto trafo = get_transformation().get_matrix(); + trafo.translate(to_3d(unscaled(offs), 0.)); + trafo.rotate(Eigen::AngleAxisd(rotation, Vec3d::UnitZ())); + m_transformation.set_matrix(trafo); + +// set_rotation(Z, get_rotation().z() + rotation); +// set_offset(get_offset() + to_3d(unscaled(offs), 0.)); this->object->invalidate_bounding_box(); } From 362267431be2d271ef0ccd13cf4abf673cf9a51f Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 4 Apr 2023 14:39:45 +0200 Subject: [PATCH 2/2] Fix transformation assembly problem for arrange polyogon --- src/libslic3r/Model.cpp | 19 +++++++++++++------ src/libslic3r/Model.hpp | 16 +--------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index f0ad7e1e0..837f32479 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -2405,11 +2405,6 @@ void ModelInstance::transform_polygon(Polygon* polygon) const arrangement::ArrangePolygon ModelInstance::get_arrange_polygon() const { // static const double SIMPLIFY_TOLERANCE_MM = 0.1; - -// Vec3d rotation = get_rotation(); -// rotation.z() = 0.; -// Transform3d trafo_instance = Geometry::assemble_transform(get_offset().z() * Vec3d::UnitZ(), rotation, get_scaling_factor(), get_mirror()); - Polygon p = get_object()->convex_hull_2d(this->get_matrix()); @@ -2421,12 +2416,24 @@ arrangement::ArrangePolygon ModelInstance::get_arrange_polygon() const arrangement::ArrangePolygon ret; ret.poly.contour = std::move(p); - ret.translation = Vec2crd::Zero(); //Vec2crd{scaled(get_offset(X)), scaled(get_offset(Y))}; + ret.translation = Vec2crd::Zero(); ret.rotation = 0.; return ret; } +void ModelInstance::apply_arrange_result(const Vec2d &offs, double rotation) +{ + // write the transformation data into the model instance + auto trafo = get_transformation().get_matrix(); + auto tr = Transform3d::Identity(); + tr.translate(to_3d(unscaled(offs), 0.)); + trafo = tr * Eigen::AngleAxisd(rotation, Vec3d::UnitZ()) * trafo; + m_transformation.set_matrix(trafo); + + this->object->invalidate_bounding_box(); +} + indexed_triangle_set FacetsAnnotation::get_facets(const ModelVolume& mv, EnforcerBlockerType type) const { TriangleSelector selector(mv.mesh()); diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index d29ce3525..ea22b968d 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -1167,21 +1167,7 @@ public: arrangement::ArrangePolygon get_arrange_polygon() const; // Apply the arrange result on the ModelInstance - void apply_arrange_result(const Vec2d& offs, double rotation) - { - // write the transformation data into the model instance -// set_rotation(Z, rotation); -// set_offset(X, unscale(offs(X))); -// set_offset(Y, unscale(offs(Y))); - auto trafo = get_transformation().get_matrix(); - trafo.translate(to_3d(unscaled(offs), 0.)); - trafo.rotate(Eigen::AngleAxisd(rotation, Vec3d::UnitZ())); - m_transformation.set_matrix(trafo); - -// set_rotation(Z, get_rotation().z() + rotation); -// set_offset(get_offset() + to_3d(unscaled(offs), 0.)); - this->object->invalidate_bounding_box(); - } + void apply_arrange_result(const Vec2d& offs, double rotation); protected: friend class Print;