Overlap point position with rays inside of Raycast manager
Fix unstability of text origin position when start use surface
This commit is contained in:
parent
971f2a08e2
commit
95c6f83b1b
3 changed files with 11 additions and 7 deletions
|
@ -2980,11 +2980,6 @@ std::optional<Vec3d> priv::calc_surface_offset(const ModelVolume &volume, Raycas
|
|||
|
||||
// ray in direction of text projection(from volume zero to z-dir)
|
||||
std::optional<RaycastManager::Hit> hit_opt = raycast_manager.unproject(point, direction, &cond);
|
||||
// start point lay on surface could appear slightly behind surface
|
||||
std::optional<RaycastManager::Hit> 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())
|
||||
|
|
|
@ -124,8 +124,16 @@ std::optional<RaycastManager::Hit> 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<AABBMesh::hit_result> 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<AABBMesh::hit_result> hits = mesh.query_ray_hits(point_positive, mesh_direction);
|
||||
std::vector<AABBMesh::hit_result> 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)
|
||||
|
|
|
@ -106,6 +106,7 @@ public:
|
|||
|
||||
/// <summary>
|
||||
/// Unproject Ray(point direction) on mesh by MeshRaycasters
|
||||
/// NOTE: It inspect also oposit direction of ray !!
|
||||
/// </summary>
|
||||
/// <param name="point">Start point for ray</param>
|
||||
/// <param name="direction">Direction of ray</param>
|
||||
|
|
Loading…
Reference in a new issue