dimforge / ncollide

2 and 3-dimensional collision detection library in Rust.
https://ncollide.org
Apache License 2.0
921 stars 105 forks source link

Point-in-mesh containment check which treats mesh as solid #317

Open clbarnes opened 4 years ago

clbarnes commented 4 years ago

This could use ray casting.

Workaround

fn mesh_contains_point<T: RealField>(mesh: &TriMesh<T>, point: &Point3<T>) -> bool {
    if !mesh.aabb().contains_local_point(point) {
        return false;
    }

    match mesh.toi_and_normal_with_ray(
        &Isometry3::identity(),
        &Ray::new(*point, Vector::new(T::one(), T::zero(), T::zero())),
        false,  // unused
    ) {
        Some(intersection) => mesh.is_backface(intersection.feature),
        None => false,
    }
}

Issues

  1. Assumes mesh is well-formed (watertight and correctly wound)
  2. Depends on ray casting for point queries, which is not necessarily ideal for keeping things modular
clbarnes commented 4 years ago

Note some weirdness around handling of intersection with edges in that workaround.