Hello!
While porting my exercise project from Three.js to Babylon I noticed a weird behaviour of camera. Despite the fact that I am new to this ecosystem, I dare to think this is a bug.
My project is a yet another simulation of a solar system, so there is a hierarchy of objects: sun, planets, and their moons. Planets’ parent is sun, and moons’ parents are planets they circle around. Nothing unusual.
But unlike other simulation of this sort, all objects are spheres of fixed radius 1. Instead of setting radius to a specific value, I extensively use relative scaling. This approach has the advantage that I can easily focus on various objects just by changing camera.parent
, while having camera.position
fixed. Because the position is relative to its parent, the parent appears to be always of the same size on the screen, no matter if this is sun, a planet or moon.
And while porting this approach to Babylon, I noticed that planets are not rendered fully, and moons at all.
Please check this demo
if you focus on planet, you will see that it partially disappeared. If you focus on moon, it disappears completely.
The cause of this problem is that all properties (position, viewport, mouse wheel controls) of camera respect its parent’s world, except for camera.minZ
, which still uses scene’s world units. And because planet and moon are closer to camera than 1 unit in scene’s world, the renderer does not render them fully,
I fixed this by adding the following (you need to uncomment line #43)
camera.minZ = !camera.parent ? 1 : camera.parent.absoluteScaling.z;
but I believe Babylon should work like this out of the box. That’s why I am reporting this as a bug.
And I am also not sure if my fix is safe, as the documentation says:
minZ: number
(…) This is important to note that the depth buffer are not infinite and the closer it starts the more your scene might encounter depth fighting issue.
like I said, I am new to Babylon…