Hiding an object for one eye only?

Hey babylon gurus. I’m relatively new to the framework. Moving from pure WebXR coding.

Here’s what I’m trying to do: “Only show a sphere to one single view(left eye)”.
It was quite easy to do in WebXR by plugging into the “onXRFrame” callback and altering left eye’s view on every frame.

With babylon, I’ve tried doing a similar thing by plugging into xr.baseExperience.sessionManager.onXRFrameObservable.add(observer);

However I don’t have control over when the scene gets drawn so there is not much I can do.

Any suggestions here? Has anyone tried to do something similar?

Welcome aboard!

Adding @RaananW who is our WebXR guru!

1 Like

Only one eye! Of course :slight_smile:

Babylon offers you a callback whenever a camera is being rendered. WebXR has technically two cameras, alternating on each frame. What you can do is:

scene.onBeforeCameraRenderObservable.add((camera) => {
                    let isRightCamera = camera.isRightCamera;
                    // do your magic!

Note that “isRightCamera” (and isLeftCamera) will only be true when in XR (or in other stereo-rig environment). It will be false on desktop.


@RaananW, OMG this forum is LIVE!)) Almost instant reply. I spent hours looking for the solution. Much appreciated, going to try this right away.

EDIT: Worked like a charm!!! MUCH MUCH MUCH appreciated. You’ve saved me time my friend!

BTW can you point me to a specific resource where I can read more about the way these “two” cameras work??

1 Like

you’d be surprised how much alive this forum actually is :slight_smile:

That’s a good question. I can suggest the code itself - Babylon.js/webXRCamera.ts at master · BabylonJS/Babylon.js (github.com) , but there is no direct documentation about how rig cameras actually work.

1 Like