diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index 30345c6fac..edb0bfb0cd 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -2980,11 +2980,6 @@ std::optional priv::calc_surface_offset(const ModelVolume &volume, Raycas // ray in direction of text projection(from volume zero to z-dir) std::optional hit_opt = raycast_manager.unproject(point, direction, &cond); - // start point lay on surface could appear slightly behind surface - std::optional hit_opt_opposit = raycast_manager.unproject(point, -direction, &cond); - if (!hit_opt.has_value() || - (hit_opt_opposit.has_value() && hit_opt->squared_distance > hit_opt_opposit->squared_distance)) - hit_opt = hit_opt_opposit; // Try to find closest point when no hit object in emboss direction if (!hit_opt.has_value()) diff --git a/src/slic3r/Utils/RaycastManager.cpp b/src/slic3r/Utils/RaycastManager.cpp index 4667be3e9c..4132fd647f 100644 --- a/src/slic3r/Utils/RaycastManager.cpp +++ b/src/slic3r/Utils/RaycastManager.cpp @@ -124,8 +124,16 @@ std::optional RaycastManager::unproject(const Vec3d &point, Transform3d tr_inv = transformation.inverse(); Vec3d mesh_point = tr_inv * point; Vec3d mesh_direction = tr_inv.linear() * direction; - std::vector hits = mesh.query_ray_hits(mesh_point, mesh_direction); - for (const AABBMesh::hit_result &hit : hits) { + + // Need for detect that actual point position is on correct place + Vec3d point_positive = mesh_point - mesh_direction; + Vec3d point_negative = mesh_point + mesh_direction; + + // Throw ray to both directions of ray + std::vector hits = mesh.query_ray_hits(point_positive, mesh_direction); + std::vector hits_neg = mesh.query_ray_hits(point_negative, -mesh_direction); + hits.insert(hits.end(), std::make_move_iterator(hits_neg.begin()), std::make_move_iterator(hits_neg.end())); + for (const AABBMesh::hit_result &hit : hits) { double squared_distance = (mesh_point - hit.position()).squaredNorm(); if (closest.has_value() && closest->squared_distance < squared_distance) diff --git a/src/slic3r/Utils/RaycastManager.hpp b/src/slic3r/Utils/RaycastManager.hpp index a29977150c..a185f63077 100644 --- a/src/slic3r/Utils/RaycastManager.hpp +++ b/src/slic3r/Utils/RaycastManager.hpp @@ -106,6 +106,7 @@ public: /// /// Unproject Ray(point direction) on mesh by MeshRaycasters + /// NOTE: It inspect also oposit direction of ray !! /// /// Start point for ray /// Direction of ray