From 284721e0de1eedfedb3704e113aeff5bd8cf97c0 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Wed, 22 Sep 2021 21:30:29 +0200 Subject: [PATCH] Fix of #4666 (selection rectangle in SLA gizmo incorrectly handles transformations) --- src/slic3r/GUI/MeshUtils.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/MeshUtils.cpp b/src/slic3r/GUI/MeshUtils.cpp index 576728b24..0f72d0f78 100644 --- a/src/slic3r/GUI/MeshUtils.cpp +++ b/src/slic3r/GUI/MeshUtils.cpp @@ -253,11 +253,10 @@ std::vector MeshRaycaster::get_unobscured_idxs(const Geometry::Transfo std::vector out; const Transform3d& instance_matrix_no_translation_no_scaling = trafo.get_matrix(true,false,true); - Vec3f direction_to_camera = -camera.get_dir_forward().cast(); - Vec3f direction_to_camera_mesh = (instance_matrix_no_translation_no_scaling.inverse().cast() * direction_to_camera).normalized().eval(); - Vec3f scaling = trafo.get_scaling_factor().cast(); - direction_to_camera_mesh = Vec3f(direction_to_camera_mesh(0)*scaling(0), direction_to_camera_mesh(1)*scaling(1), direction_to_camera_mesh(2)*scaling(2)); - const Transform3f inverse_trafo = trafo.get_matrix().inverse().cast(); + Vec3d direction_to_camera = -camera.get_dir_forward(); + Vec3d direction_to_camera_mesh = (instance_matrix_no_translation_no_scaling.inverse() * direction_to_camera).normalized().eval(); + direction_to_camera_mesh = direction_to_camera_mesh.cwiseProduct(trafo.get_scaling_factor()); + const Transform3d inverse_trafo = trafo.get_matrix().inverse(); for (size_t i=0; i MeshRaycaster::get_unobscured_idxs(const Geometry::Transfo // Cast a ray in the direction of the camera and look for intersection with the mesh: std::vector hits; // Offset the start of the ray by EPSILON to account for numerical inaccuracies. - hits = m_emesh.query_ray_hits((inverse_trafo * pt + direction_to_camera_mesh * EPSILON).cast(), - direction_to_camera.cast()); - + hits = m_emesh.query_ray_hits((inverse_trafo * pt.cast() + direction_to_camera_mesh * EPSILON), + direction_to_camera_mesh); if (! hits.empty()) { // If the closest hit facet normal points in the same direction as the ray,