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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.