Hello guys,
While playing around with the Augmented reality features of babylonjs, I stumbled upon a bug where some items would get occluded by the depth sensing feature, while others wont. And so for no apparent reason.
Here is a code sandbox reproducing the error and a screen cap : https://playground.babylonjs.com/#KDWCZY#619
In this picture, the skeleton is a default mesh with no particular material. The cube have the standard material.
And here, same code sample but with the standard material commented out, you get this : https://playground.babylonjs.com/#KDWCZY#620
What could be done to work around that ?
Tested on : Samsung s22, Chrome 138, android 15
1 Like
I repro this on my Quest 3. Investigating now.
1 Like
tl;dr Move the material creation outside the onAnchorAddedObservable callback.
The WebXR onAnchorAddedObservable callback is called from the render loop, so creating a material there is unexpected.
Moving the material creation out of the callback/render-loop gets depth occlusion working for it:
https://playground.babylonjs.com/#KDWCZY#622
Thank you @docEdub for your explanation and @Deltakosh for the ping !
I was able to reproduce your fix on my original project 
In my case, the generation of the material was not in a onAnchorAddedObservable callback, but in a function called on user interact.
We can close the ticket, but for the record :
Could it be that any material created after the initialization of the WebXRDepthSensing or after the entering of the XR session are not taken into account for occlusion ?