I'm trying to generate a point cloud representing the volume of an arbitrary mesh. My approach is to create a uniform grid of sample points within the object bounding box, and then call closest_point_on_mesh for each of them discard the ones outside.
Here's my function for working out if a sample point is within the mesh or not:
def IsPointInsideObject(point, object): (success, closestPoint, closestFaceNormal, closestFaceIndex) = object.closest_point_on_mesh(point) result = True if success and (closestPoint - point).dot(closestFaceNormal) > 0 else False return result It does a good job mostly, but I always have these extra points which falsely report true:
Looking into it, I think it's because the closest point sits right on an edge between faces, and so closest_point_on_mesh returns a face whose normal is pointing in the wrong direction.
Has anyone done something similar and found a way around this? I could maybe add a random jitter to my sample points in the hope of picking the right face, but I'd prefer to keep the grid uniform.
Or is there a better way to work out if a point's inside a mesh?
