I have a function in my project that retrieves mesh’s 2D screen position dynamically. I have setup a playground that has almost the same setting as my project here: https://playground.babylonjs.com/#INZ0Z0#584
Open the console, and run the code, you can find box mesh 2D position be logged in console per frame. Zoom in cameral quickly to the max level, you’ll find the 2D position will eventually jumps from a negative value to a huge positive value, see screenshot below:
Then scroll to zoom out, you’ll find the positive value increases for a few frames then jumps back to a negative value and back to how it should behave, see below:
If you comment out box.onBeforeRenderObservable and uncomment box2.onBeforeRenderObservable, you can see the same happens to box2 mesh too, it jumps from a positive value to a negative value when zoom in to max.
Also what I discovered is that in above (#INZ0Z0#579) test playground, onBeforeRenderObservable stops observation once Mesh is out of camera view frustum. Where the playground with issue (#INZ0Z0#584) onBeforeRenderObservable never stops observation event.
Wonder if anyone have any idea what is wrong and what I can do to fix this issue/improve my code?
so we are trying to not render invisible or culled meshes. Here it looks like the blue cube is always considered in frustum cause the camera stops within the mesh.
Yeah I’m thinking the same. Is there a way to make sure it’s considered “not visible” once it exceeds the visible screen viewport, so that observable event can stops working just like #INZ0Z0#579?
The same thing happens in the second PG. You don’t see it only because the box is small, and when fully zoomed in, it happens that we are not inside the cube. But if you make the box bigger you will see the same thing than in the first PG:
We can’t really do anything about this, it all depends on the size of your objects and the position of the camera.
From the point of view of the system, the mesh is still visible because it intersects the camera frustum. You don’t see anything because the material has back face culling enabled by default, but if you disable it you will see that you are inside the cube when you are fully zoomed in:
I think it comes from precision problems during calculation. There are very small values in the transformation matrix, which leads to divergences at some point.
If you enable 64 bits matrices (by setting useHighPrecisionMatrix: true in the options when creating the engine), you don’t really get more precisions: