When to use resetToCurrentRotation()?

When I’m in VR mode (google cardbord with an android phone), I want to use:
When I use it in the console, it works perfectly, but I have not found the good event to call it.
If I call it inside ‘onEnteringVR’ event, it doesn’t work the first time, so I have to plug it inside a setTimeout of 1sec to make it work properly…

So is there an event to call it ? Do I miss something ?

Many thanks !!

Welcome to the BJS forum, DA!

No replies yet, huh? Darn. Let’s bump it to the top of the list… see if we get any percolation. :slight_smile:

1 Like

Pinging @trevordev

onEnteringVR is called right before the entering vr event occurs (not after) this is why I believe resetToCurrentRotation is failing unless you add the timeout.

The scene has a request present complete event, could you try this?

            // VR started
            // make your calls here

let me know if that doesnt work. Another option is to add a button that the user can press to reset rotation.


Thank you @trevordev !

It works perfectly with the HTC Vive !!

But I want to make it work with Google cardboard too, and looking at engine.ts, the event is never triggered because scene.getEngine()._vrDisplay is undefined in this case…
Furthermore engine.enableVR() is never called too without device detected…

Do you have any solution which does not imply to add a button ?

Does onEnteringVR work in the cardboard case? If so I could try to add an onAfterEnteringVR observable to the webVR helper that will fire at the right time depending on cardboard or vr hmd.

No it doesn’t work on "onEnteringVR ". Yep "onAfterEnteringVR " event seems to be a very good solution !

1 Like

Sounds good, created this so i don’t forget add onAfterEnteringVR event · Issue #5835 · BabylonJS/Babylon.js · GitHub

1 Like

Thank you @trevordev !!

@devAxeon Im looking at this now, when you use setTimeout does it work as expected for cardboard and when using just a desktop? Im seeing some weird behavior where the camera keeps spinning. I’m thinking there is a bug when using the fallback non-hmd camera. Eg. this playground https://playground.babylonjs.com/#TAFSN0#155 .

Effectively, the camera turns itself if “createDeviceOrientationCamera” is false when creating vrHelper on desktop and there’s no orientation device plugged.

But using custom orientation in chrome’s devTool sensors tab, it seems to work… So I think it misses a condition waiting for the first sensor move…

In my case, I let createDeviceOrientationCamera to true, and I’m just using:

    }, 1000);

Don’t know if it help…

I created a PR which I think should work: onAfterEnterVR by TrevorDev · Pull Request #5871 · BabylonJS/Babylon.js · GitHub although Im having trouble understanding how you are using resetToCurrentRotation.

You can see in the PR that when not using the webVR camera it will fire the afterEnterVR event when the next frame is rendered

this._scene.onAfterRenderObservable.addOnce(() => {
    this.onAfterEnteringVRObservable.notifyObservers({success: true});

can you verify this works for your usecase?

I tried this:

    scene.onAfterRenderObservable.addOnce(() => {

But that was not working…
I think we have to wait for the first rendering with both eyes…

Is it possible ?

Ok, I think I repro’d this correctly now :slight_smile:

This PG should work https://playground.babylonjs.com/#TAFSN0#162


Ill update my PR, let me know if that doesn’t work for you

1 Like

This is exactly what I was missing !!
Thank you very much @trevordev !!