# Cleaning up hidden mesh instances with geometry nodes

I've been playing with geometry nodes recently, and I'm finding it tricky to get an optimised mesh.

I'm generating a simple block terrain, however, the problem is the mesh instances build on top of each other. I attempted to use Boolean Union and proximity but that gives patchy results and also melts the CPU.

Is there a cleaner way to remove mesh instances which aren't visible or a way to calculate two faces next to each other and remove them?

Attached is an image of the underside to show the problem

Hope that makes sense, thank you

I assume from your example that you are instantiating cubic shapes here...

Try the following:

1. First convert the instances into a mesh with Realize Instances and capture the positions of the points with Capture Attribute.

2. Then scale the elements a little bit smaller.

3. Remove all horizontal faces, except the ones at the top. To do this use the node Raycast and send a ray from the center of the faces in the direction $$(0,0,1)$$ (pointing upwards). If you don't have a Hit it means it's an intermediate face and can be deleted. In addition, combine this selection with the faces whose normals are also pointing upwards, so that the side faces are not additionally selected.

4. Then send a ray from the remaining faces in the direction of the normals. However, move the position a little bit in the direction of the normals, so that you don't hit your own face. Note that the Ray Length here must be smaller than the length of a single object (!). If you have a Hit, it means that the face was originally adjacent to a face of another previously instantiated object and can be deleted.

5. Finally, restore the positions of the original points and apply the node Merge by Distance to merge the remaining mesh.

(Blender 3.2+)

• That is a smart variation of how it's usually done in video games ! May 16, 2023 at 12:20