How can I get camera world direction with webxr?
Asked Answered
T

4

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.

Toland answered 1/1, 2020 at 17:14 Comment(2)
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?!Immingle
I am facing the same issue? Did you resolve it?Hectometer
C
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()
Corposant answered 10/1, 2020 at 18:20 Comment(0)
B
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 );
Banditry answered 20/1, 2020 at 19:41 Comment(1)
Actually it does not work with FireFox WebXR devtools. By camerabox you meant attaching a Mesh with a BoxGeometry?Hagioscope
R
1

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

This feature is only working using HTTPS.

Rundgren answered 25/1, 2020 at 11:54 Comment(0)
S
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
Southsouthwest answered 5/8, 2020 at 20:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.