Frustum picking for hardware instanced entities

I’m trying to implement a drag based multi select feature. I had previously done this using the pc picker but now we’re instancing our meshes so this method doesn’t give us the right entities anymore (not to mention it’s not great performance wise).

My idea on how to build this is to create a custom frustum based on the rectangular drag area on the screen and then conduct intersection tests for all entities in the scene based on this frustum. I’d probably use bounding sphere for the first pass and do some higher res intersection test if the bounding sphere intersects the frustum.

I’ve been struggling to get the frustum setup properly. I have the 4 rectangular touch coordinates in screen space for the drag and have been trying to create a new frustum from a mat4 but haven’t figured it out yet.

Would love some pointers or suggestions on other approaches to this issue.

Hi @joshb,

You can use the Frustum of the active camera, it contains useful methods that you can query with a bounding instance for visibility:

const isVisible = cameraComp.frustum.containsSphere(sphereBounding);

Thanks @Leonidas but unless I’m missing something I don’t think that will work for this purpose.

Below is an image for more context. In this scenario I’d only want to select the green circle and not the red. The camera’s frustum sees both of them so it would select both. That’s why I was essentially trying to create a new frustum that represents the area of the rectangular selection.

1 Like