Checking mesh visibility with dot

Hi,

I’m trying to hide some meshes (box and sphere) when a single-face plane (disc) mesh become invisible (tilt camera). I’ve tried the similar example from this forum but it didn’t work for me.

Here is slightly modified sample code:

Thanks for any advise.

Hello @val , how are you doing?

I did a small update to your demo:
Box Examples | Babylon.js Playground (babylonjs.com)

It’s very similar to what you were doing, but I’m using the forward value of the disk mesh instead of the calculating it by the relative position of the mesh. The problem with using relative position is that you want to use vector component that is perpendicular to the plane.

2 Likes

Thank you @srzerbetto for you explanation.

Your code works fine!

I did tried .forward - but without success, because I missed that the .forward is in the world space, and I wrongly assumed that it is in the local space.

Thank you once more for your help!

1 Like

Hi @srzerbetto, how are you?

I just noticed that there is a problem when moving camera up. The dot remains positive while the disk is hidden. It’s easy to reproduce - just set disk at the center almost horizontally (so its barely visible) and zoom out, then move the viewport up (with right mouse button) above the eyepoint so the disk disappears - other objects remain in scene and dot remains unchanghed.

Thank you

P.S. I’m not sure that the simple dot comparison can make that magic. I think this approach is valid only to check if the mesh is visible against the near plane of the frustum indeed. Probably, there should be check against viewport bounds.

Yep dot can only check angles between vectors, it won’t take their positions into account