ncollide icon indicating copy to clipboard operation
ncollide copied to clipboard

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

Open clbarnes opened this issue 6 years ago • 1 comments

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 avatar Nov 27 '19 13:11 clbarnes

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

clbarnes avatar May 20 '20 12:05 clbarnes