From 528546b6c8a00205344133621bf1ec4e2ce70419 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 21 Jan 2019 12:53:30 +0100 Subject: [PATCH] Place on bed should now correctly process instance mirror and respect transformations on subvolumes --- src/slic3r/GUI/GLCanvas3D.cpp | 9 ++++++--- src/slic3r/GUI/GLGizmo.cpp | 11 ++++------- src/slic3r/GUI/GLGizmo.hpp | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 24998cd60..cec47c664 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1784,11 +1784,14 @@ void GLCanvas3D::Selection::flattening_rotate(const Vec3d& normal) for (unsigned int i : m_list) { - Transform3d wst = m_cache.volumes_data[i].get_instance_scale_matrix() * m_cache.volumes_data[i].get_volume_scale_matrix(); + Transform3d wst = m_cache.volumes_data[i].get_instance_scale_matrix(); Vec3d scaling_factor = Vec3d(1./wst(0,0), 1./wst(1,1), 1./wst(2,2)); - Vec3d rotation = Geometry::extract_euler_angles(m_cache.volumes_data[i].get_instance_rotation_matrix() * m_cache.volumes_data[i].get_volume_rotation_matrix()); - Vec3d transformed_normal = Geometry::assemble_transform(Vec3d::Zero(), rotation, scaling_factor) * normal; + Transform3d wmt = m_cache.volumes_data[i].get_instance_mirror_matrix(); + Vec3d mirror(wmt(0,0), wmt(1,1), wmt(2,2)); + + Vec3d rotation = Geometry::extract_euler_angles(m_cache.volumes_data[i].get_instance_rotation_matrix()); + Vec3d transformed_normal = Geometry::assemble_transform(Vec3d::Zero(), rotation, scaling_factor, mirror) * normal; transformed_normal.normalize(); Vec3d axis = transformed_normal(2) > 0.999f ? Vec3d(1., 0., 0.) : Vec3d(transformed_normal.cross(Vec3d(0., 0., -1.))); diff --git a/src/slic3r/GUI/GLGizmo.cpp b/src/slic3r/GUI/GLGizmo.cpp index 2ea7e677e..1f37b7aec 100644 --- a/src/slic3r/GUI/GLGizmo.cpp +++ b/src/slic3r/GUI/GLGizmo.cpp @@ -1526,10 +1526,9 @@ void GLGizmoFlatten::update_planes() vol_ch.transform(vol->get_matrix()); ch.merge(vol_ch); } - ch = ch.convex_hull_3d(); m_planes.clear(); - const Transform3d& inst_matrix = m_model_object->instances.front()->get_matrix(); + const Transform3d& inst_matrix = m_model_object->instances.front()->get_matrix(true); // Following constants are used for discarding too small polygons. const float minimal_area = 5.f; // in square mm (world coordinates) @@ -1696,10 +1695,6 @@ void GLGizmoFlatten::update_planes() // Transform back to 3D (and also back to mesh coordinates) polygon = transform(polygon, inst_matrix.inverse() * m.inverse()); - - // make sure the points are in correct order: - if ( ((inst_matrix.inverse() * m.inverse()) * Vec3d(0., 0., 1.)).dot(normal) > 0.) - std::reverse(polygon.begin(),polygon.end()); } // We'll sort the planes by area and only keep the 254 largest ones (because of the picking pass limitations): @@ -1714,6 +1709,7 @@ void GLGizmoFlatten::update_planes() m_volumes_types.push_back(vol->type()); } m_first_instance_scale = m_model_object->instances.front()->get_scaling_factor(); + m_first_instance_mirror = m_model_object->instances.front()->get_mirror(); } @@ -1726,7 +1722,8 @@ bool GLGizmoFlatten::is_plane_update_necessary() const return true; // We want to recalculate when the scale changes - some planes could (dis)appear. - if (! m_model_object->instances.front()->get_scaling_factor().isApprox(m_first_instance_scale)) + if (! m_model_object->instances.front()->get_scaling_factor().isApprox(m_first_instance_scale) + || ! m_model_object->instances.front()->get_mirror().isApprox(m_first_instance_mirror)) return true; for (unsigned int i=0; i < m_model_object->volumes.size(); ++i) diff --git a/src/slic3r/GUI/GLGizmo.hpp b/src/slic3r/GUI/GLGizmo.hpp index ddd57b645..02b637a35 100644 --- a/src/slic3r/GUI/GLGizmo.hpp +++ b/src/slic3r/GUI/GLGizmo.hpp @@ -405,6 +405,7 @@ private: std::vector m_volumes_matrices; std::vector m_volumes_types; Vec3d m_first_instance_scale; + Vec3d m_first_instance_mirror; std::vector m_planes; mutable Vec3d m_starting_center;