From 9442cb99f4ffc0570e9f851738ae8c9bccf32759 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 5 Nov 2018 09:34:04 +0100 Subject: [PATCH] Flatten gizmo now correctly processes both instance and volume transformations --- src/slic3r/GUI/GLCanvas3D.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 0009f9e7a..7e1024813 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1500,10 +1500,11 @@ void GLCanvas3D::Selection::flattening_rotate(const Vec3d& normal) for (unsigned int i : m_list) { - Vec3d scaling_factor = m_cache.volumes_data[i].get_volume_scaling_factor(); - scaling_factor = Vec3d(1./scaling_factor(0), 1./scaling_factor(1), 1./scaling_factor(2)); + Transform3d wst = m_cache.volumes_data[i].get_instance_scale_matrix() * m_cache.volumes_data[i].get_volume_scale_matrix(); + Vec3d scaling_factor = Vec3d(1./wst(0,0), 1./wst(1,1), 1./wst(2,2)); - Vec3d transformed_normal = Geometry::assemble_transform(Vec3d::Zero(), m_cache.volumes_data[i].get_volume_rotation(), scaling_factor) * normal; + 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; transformed_normal.normalize(); Vec3d axis = transformed_normal(2) > 0.999f ? Vec3d(1., 0., 0.) : Vec3d(transformed_normal.cross(Vec3d(0., 0., -1.))); @@ -1512,8 +1513,8 @@ void GLCanvas3D::Selection::flattening_rotate(const Vec3d& normal) Transform3d extra_rotation = Transform3d::Identity(); extra_rotation.rotate(Eigen::AngleAxisd(acos(-transformed_normal(2)), axis)); - Vec3d new_rotation = Geometry::extract_euler_angles(extra_rotation * m_cache.volumes_data[i].get_volume_rotation_matrix() ); - (*m_volumes)[i]->set_volume_rotation(new_rotation); + Vec3d new_rotation = Geometry::extract_euler_angles(extra_rotation * m_cache.volumes_data[i].get_instance_rotation_matrix() ); + (*m_volumes)[i]->set_instance_rotation(new_rotation); } m_bounding_box_dirty = true; }