PavolHejný

WebVR starting with enableVR()

Recommended Posts

Hi,

I am creating WebVR app with Babylon.js (using Firefox, SteamVR and HTC Vive).  Can I somehow start VR without users initial click.


When i create WebVRFreeCamera:

const camera = new BABYLON.WebVRFreeCamera("camera", BABYLON.Vector3.Zero(), scene);

I can start VR with:

scene.onPointerDown = function () {
    camera.attachControl(document.getElementById('scene'), true);
};

or

scene.onPointerDown = function () {
    camera.getEngine().enableVR();
};

but when i do it without onPointerDown callback it does not work:

const camera = new BABYLON.WebVRFreeCamera("camera", BABYLON.Vector3.Zero(), scene);
camera.getEngine().enableVR();

 

Also when i wrap it with setTimeout it does not work:

const camera = new BABYLON.WebVRFreeCamera("camera", BABYLON.Vector3.Zero(), scene);
scene.onPointerDown = function () {
    setTimeout(()=>{
            camera.getEngine().enableVR();
        },100);
};

Does enableVR method needs onPointerDown event context. Or where is the problem?

Thanks a lot for your advice.

Share this post


Link to post
Share on other sites

If the user is actually wearing the headset, you can start webvr automatically by listening to the vrdisplayactive.

The code looks like the following:

window.addEventListener('vrdisplayactivate', () => {
    vrHelper.enterVR();
});

The supermedium browser will need you to automatically start webvr once the user puts on the headset.

The behavior for each browser is different though.
This is the observations I noticed:

- Supermedium honors this event always.

- Firefox honors this event but you do need to click that button (to give the permission) once in the beginning. Imo this is the correct behavior.

- Edge seems to ignore it :)

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.