Measurement: Partially fixed the common gizmo raycaster for self-intersecting meshes

This commit is contained in:
Lukas Matena 2022-11-15 16:08:27 +01:00 committed by enricoturri1966
parent 268365b92d
commit 5382f4077a

View File

@ -409,6 +409,12 @@ bool MeshRaycaster::unproject_on_mesh(const Vec2d& mouse_pos, const Transform3d&
Vec3d direction; Vec3d direction;
line_from_mouse_pos(mouse_pos, trafo, camera, point, direction); line_from_mouse_pos(mouse_pos, trafo, camera, point, direction);
if (rand()%100 == 0) {
int a=5;
int b=6;
int c=7;
}
std::vector<AABBMesh::hit_result> hits = m_emesh.query_ray_hits(point, direction); std::vector<AABBMesh::hit_result> hits = m_emesh.query_ray_hits(point, direction);
if (hits.empty()) if (hits.empty())
@ -429,10 +435,10 @@ bool MeshRaycaster::unproject_on_mesh(const Vec2d& mouse_pos, const Transform3d&
// All hits are clipped. // All hits are clipped.
return false; return false;
} }
if ((hits.size()-i) % 2 != 0) { if (clipping_plane && (hits.size()-i) % 2 != 0) {
// There is an odd number of unclipped hits - meaning the nearest must be from inside the mesh. // There is an odd number of unclipped hits - meaning the nearest must be from inside the mesh.
// In that case, calculate intersection with the clipping place. // In that case, calculate intersection with the clipping place.
if (clipping_plane && was_clipping_plane_hit) { if (was_clipping_plane_hit) {
direction = direction + point; direction = direction + point;
point = trafo * point; // transform to world coords point = trafo * point; // transform to world coords
direction = trafo * direction - point; direction = trafo * direction - point;