MeshRaycaster: added a function to check for mesh-line intersections

This commit is contained in:
Lukas Matena 2023-07-31 16:04:41 +02:00
parent bd43118148
commit 5de69b962e
2 changed files with 9 additions and 4 deletions

View File

@ -465,14 +465,17 @@ bool MeshRaycaster::unproject_on_mesh(const Vec2d& mouse_pos, const Transform3d&
bool MeshRaycaster::is_valid_intersection(Vec3d point, Vec3d direction, const Transform3d& trafo) const
bool MeshRaycaster::intersects_line(Vec3d point, Vec3d direction, const Transform3d& trafo) const
{
point = trafo.inverse() * point;
Transform3d trafo_inv = trafo.inverse();
Vec3d to = trafo_inv * (point + direction);
point = trafo_inv * point;
direction = (to-point).normalized();
std::vector<AABBMesh::hit_result> hits = m_emesh.query_ray_hits(point, direction);
std::vector<AABBMesh::hit_result> neg_hits = m_emesh.query_ray_hits(point, -direction);
return !hits.empty() && !neg_hits.empty();
return !hits.empty() || !neg_hits.empty();
}

View File

@ -187,7 +187,9 @@ public:
const AABBMesh &get_aabb_mesh() const { return m_emesh; }
bool is_valid_intersection(Vec3d point, Vec3d direction, const Transform3d& trafo) const;
// Given a point and direction in world coords, returns whether the respective line
// intersects the mesh if it is transformed into world by trafo.
bool intersects_line(Vec3d point, Vec3d direction, const Transform3d& trafo) const;
// Given a vector of points in woorld coordinates, this returns vector
// of indices of points that are visible (i.e. not cut by clipping plane