Mesh hiding based on camera rotation

Hi,

I am trying to implement a logic to hide a model based on the camera rotation. And need to have a suggestion on my implementation if there is a better way.

the ask is → there will be two models, one is a placement model like a table and the other one is a model sit on top of the placement. So I would like to hide the placement model when the camera rotate below the placement.

Here is the sample playground I prepare - Babylon.js Playground

Thank you in advance.

What you can do is testing if the angle between a direction from a point of the face of the base of the fan and the view direction to this point is lower or greater than 90° (so if the dot product is positive or negative):

https://playground.babylonjs.com/#I5K7WC#3

In this PG the white line is the direction to check with the view direction. origin is the point on the face you want to test for visibility.

The advantage of the method is that you can pick any point and direction. For eg, in this PG the barrel disappears when the front face of the fan is not visible:

https://playground.babylonjs.com/#I5K7WC#2

3 Likes

@Evgeni_Popov Ah… It is way better. Thank you so much!