three.jswebxr

Access VR headset orientation in Three.js


How can I access the VR headset orientation in Three.js? The WebXRManager doesn't seem to provide a way to do this.


Solution

  • You can extract the orientation from the camera used for rendering the scene. Try the following when presenting:

    const position = new THREE.Vector3();
    const rotation = new THREE.Quaternion();
    const scale = new THREE.Vector3();
    
    // the following line extracts the position, rotation and scale in world space
    
    camera.matrixWorld.decompose( position, rotation, scale );