Check if object is visible


#1

Hi,

We would like to show a button on the object if it is visible on the screen. It’d be okay even if it is partially visible.

One approach that we came up with is to raycast to the bounding box center of that object and check if it is hidden by anything. But sometimes, when mesh is torus for example, the ray goes through the center and we don’t see the button on that object.

The button currently is absolutely positioned HTML button (by projecting the bounding box center onto camera).

One approach that we are thinking of is to raycast to a random vertex of the mesh, but that would also not give us satisfying results.

Another approach is modify raycaster so that it checks if the ray intersects the bounding box, not the object itself, but I envision scenarios where it will fail.

The only reliable way I think is to check the depth buffer but there is no way to co-relate it back to the object.

Can someone please help us here?


#2

One way to solve this is to put the torus inside an invisible bounding box and raycast against the box instead.


#3

That’s what I meant when I said

Another approach is modify raycaster so that it checks if the ray intersects the bounding box, not the object itself, but I envision scenarios where it will fail.

but the problem with that will be because we have coaxial bounding box. If the torus is rotated by 45 deg let’s say, then small objects near that will get hidden. Please look at the image below to get an idea of what I’m talking about.

The red cube we see here is actually inside the bounding box of the torus.

This is actually real scenario for us, since we have lights (real life lights) on walls. We need to show a button on the lights.