Click on mesh and get coordinates - raycasting x BVH

Hi guys, we have a problem: we need to estimate click coordinates on a complex mesh (1M+ vertices, 3D scans). Simple raycasting is working, but of course is very slow. So we have tried BVH. It works great, but a problem here is its memory intensive and causing mobile devices to crash. As we need only to estimate the click coordinates it looks to me like an overkill to use BVH magic. So my question, isnt there any way how to make basic raycasting faster for this purpose (estimating click coordinates)? We do not need the performance of BVH, just a bit faster raycasting. Could someone help please?

I am no expert in this field, but have you tried creating a bvh using simplified geometry, or creating hitboxes?

Here is a demo of a photogrammetry model. Since the model had many vertices, raycasting was slow. So I created a hit box around it that roughly estimates the wall boundaries. No need to use BVH.

Double click the wall to change the OrbitControls target.

1 Like

The memory requirements for the BVH scales with the depth of the BVH being generated. If you set maxDepth to a smaller value or maxLeafTris to a larger value you can limit how deep the BVH is generated to. Of course the shallower the BVH is the less of a performance improvement you’ll see but you can find a balance that works for you. You can also generate the BVH beforehand and load it separately.

Over all, though, these kinds of spatial data structures are the way to improve raycasting performance.