mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 23:05:52 +08:00
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
@ -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)
|
// ray in direction of text projection(from volume zero to z-dir)
|
||||||
std::optional<RaycastManager::Hit> hit_opt = raycast_manager.unproject(point, direction, &cond);
|
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
|
// Try to find closest point when no hit object in emboss direction
|
||||||
if (!hit_opt.has_value())
|
if (!hit_opt.has_value())
|
||||||
|
@ -124,7 +124,15 @@ std::optional<RaycastManager::Hit> RaycastManager::unproject(const Vec3d &point,
|
|||||||
Transform3d tr_inv = transformation.inverse();
|
Transform3d tr_inv = transformation.inverse();
|
||||||
Vec3d mesh_point = tr_inv * point;
|
Vec3d mesh_point = tr_inv * point;
|
||||||
Vec3d mesh_direction = tr_inv.linear() * direction;
|
Vec3d mesh_direction = tr_inv.linear() * direction;
|
||||||
std::vector<AABBMesh::hit_result> hits = mesh.query_ray_hits(mesh_point, mesh_direction);
|
|
||||||
|
// 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) {
|
for (const AABBMesh::hit_result &hit : hits) {
|
||||||
double squared_distance = (mesh_point - hit.position()).squaredNorm();
|
double squared_distance = (mesh_point - hit.position()).squaredNorm();
|
||||||
if (closest.has_value() &&
|
if (closest.has_value() &&
|
||||||
|
@ -106,6 +106,7 @@ public:
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Unproject Ray(point direction) on mesh by MeshRaycasters
|
/// Unproject Ray(point direction) on mesh by MeshRaycasters
|
||||||
|
/// NOTE: It inspect also oposit direction of ray !!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="point">Start point for ray</param>
|
/// <param name="point">Start point for ray</param>
|
||||||
/// <param name="direction">Direction of ray</param>
|
/// <param name="direction">Direction of ray</param>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user