Skip to content
Advertisement

webVR resetPose replacement

I have a webVR project that used resetPose to reset the origin of the scene but apparently is now deprecated. I used it to reset the camera, so the user would look at the center of the scene again.

I assume this function isn’t too hard to replicate: you either have to rotate the scene or the camera to the new origin. However I’m not that experienced with webVR or more importantly THREE.js.

I’ve tried to lookAt the center of the scene with the camera but I think the problem is that the webVR has control over it so I can’t just move it.

Example initialisation of camera and scene

// Create a three.js camera.
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 10000);
camera.name = "Perspective Camera";

var group = new THREE.Group();
group.name = "Camera Group";
group.rotateY(Math.PI);
group.add(camera);
group.position.set(0, configuration.sphereRadius, 0);
group.permanent = true;
scene.add(group);

// Apply VR headset positional data to camera.
controls = new THREE.VRControls(camera);

Advertisement

Answer

According to this issue immersive-web/webxr droped support for resetPose method. They claim that devices have hardware button to force resetting pose or reset pose should be handled by application. Three.js don’t have such method.

Here is simple but dirty way to reset pose (recenter, reset camera) by exiting VR and entering it again.

async function recenter() {
    if (renderer.xr.isPresenting) {
        let session = renderer.xr.getSession();
        let buttonVR = document.getElementById("VRButton");
        await session.end();
        buttonVR.click();
    }
}
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement