How to delete points not inside of a volume?

Add Suzanne
Convert Suzanne mesh to volume.
Distribute points in volume.
Set Position offset in Z to have half of the point outside of the volume area.
Convert Suzanne to convex hull and join with the other geometry.

Q1 : How to delete the points that are not within the volume/convex hull region?

Q2 : If instead of distribute points in volume we have another mesh, a single object consisting of 100 mesh islands. How can we detect verts on that object that are not within the volume and then delete all verts of the mesh island that vert belongs to?

We could try sampling the nearest surface of the “volume” mesh and seeing whether we’re looking on the “inside” or “outside” of the mesh, i.e. reading surface normal and comparing to vector from surface to point (with Dot Product). If they look in the same direction return True - that’s selection for Delete Geometry node.

Accumulate that selection value per Island Index to mark whole islands that have at least one point returning True.

(!) However, the issue with this method can be seen at particularly pointy areas, where it’s unclear which normal should be sampled… :person_shrugging:

4 Likes

I usually raycast to test for insideness, but maybe it’s more costly, I have not checked

1 Like

Thing with Raycast is that you need to come up with cast Direction, so I usually treat it as a more complex option.

Hmmm, but since volume is said to be convex anyway, maybe raycasting to center of the object is a simpler and more reliable way… :thinking:

1 Like

I am assuming any possible alternative to boolean is going to be faster than boolean.

I have thousands of pieces of randomly shaped christmas confetti in a glass jar or a box made of a hundred wires (curves). Using boolean to trim away the pieces that go through and poke outside of the container walls is ssslllooooowww.

Without convex hull I most often see a scenario like this where the points are inside the volume mesh but an edge/face is not.

An easy fix is to subdivide the confetti mesh once or twice so there is an actual vertex in the area outside of the volume. But, is it possible to detect if part of the face/edge is outside of the mesh, not just the vertices?

An idea: for each Edge, Raycast from “Edge Vertex” Position1 in the direction of Position2. If the ray hits the Target - then the edge is intersecting the surface… at least once.
That should get you all the islands that have edges go through surface… probably.
Add the selection from outside and delete them all.

Won’t be so easy with faces though.