7

I would like to use camera.getWorldDirection() and access to the head-mounted display directions. I was able to do this with the previous webVR API. When I use the new HelioWebXRPolyfill.js from THREE, I am not able to receive current positions.

Cagri
  • 657
  • 2
  • 8
  • 17
  • Camera on new webXR implementation seems to have no link to the actual headset view, it sits aside from it. If i get camera.rotation and I look around using my headset there is no change. I am also looking for an answer to this one?! – T0m Jan 07 '20 at 18:45
  • I am facing the same issue? Did you resolve it? – Stanly Apr 07 '20 at 12:00

4 Answers4

1

It seems that calling renderer.xr.getCamera() isn't fully copying the various camera member properties that camera.getWorldDirection() is expecting to find. I'm not sure where this problem originates (perhaps the polyfill?), but you can get around it by computing direction yourself :

        let xrCamera = this.renderer.xr.getCamera(sceneCamera)
        let e = xrCamera.matrixWorld.elements
        let direction = new THREE.Vector3(-e[8], -e[9], -e[10]).normalize()
ksimeon
  • 241
  • 1
  • 3
  • 9
1

I came up with a simple fix. Just parent a box to the camera and use the camera box in place of the camera.

camera.add( camerabox );

This doesn't work:

var direction = new THREE.Vector3();
camera.getWorldDirection( direction );

This DOES work:

var direction = new THREE.Vector3();
camerabox.getWorldDirection( direction );
Twonky
  • 796
  • 13
  • 31
phil
  • 11
  • 1
  • Actually it does not work with FireFox WebXR devtools. By camerabox you meant attaching a Mesh with a BoxGeometry? – kgz Dec 03 '20 at 16:13
1

According to the WebXR Device API, this should be done using the XRViewerPose object.

This feature is only working using HTTPS.

0

global variable

var cameraVector = new THREE.Vector3();  //define once and reuse it!

in your render loop

let xrCamera = renderer.xr.getCamera(camera);
xrCamera.getWorldDirection(cameraVector);
//heading vector for webXR camera now within cameraVector