mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-12 02:09:02 +08:00
MeshRaycaster: added a function to check for mesh-line intersections
This commit is contained in:
parent
bd43118148
commit
5de69b962e
@ -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> hits = m_emesh.query_ray_hits(point, direction);
|
||||||
std::vector<AABBMesh::hit_result> neg_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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -187,7 +187,9 @@ public:
|
|||||||
|
|
||||||
const AABBMesh &get_aabb_mesh() const { return m_emesh; }
|
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
|
// 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
|
// of indices of points that are visible (i.e. not cut by clipping plane
|
||||||
|
Loading…
x
Reference in New Issue
Block a user