How to access and change position/quaternion of the camera with WebXR?

Changing camera position at runtime dosent seem to work, i d like to know how to do it with WebXR.

I dont find any documentation for those.

If possible give me examples for those:

Get left motion controller position.

Get head position.

Set head position.

Get head rotation.

Set head rotation.

Ok so i found out it is xr.input.xrCamera to change position/rotation etc…

now i need to find out how to retrieve controllers positions.

i think it is this.xr.input.controllers[0].grip.position;

adding @RaananW

It is fully documented here:

I would use the observables to get newly updated controllers (and not access directly the .controlelrs public member of xrInput), but it is really up to you.

Thank you, btw it seems that we need to provide another camera just to change its position? any way to do it without copying from another camera?

I am not sure what you mean. You can set the camera’s position when needed, but you do need a “desktop” (universal) camera if you want the scene to render correctly on desktop (and before entering XR)

So i can just set xrCamera.position? and xrCamera.rotationQuaternion?

instead of those kind of stuff:

// if scene.activeCamera is still the non-VR camera:

xrCamera.setTransformationFromNonVRCamera();

// Otherwise, provide the non-vr camera to copy the transformation from:

xrCamera.setTransformationFromNonVRCamera(otherCamera);

// If you want XR o also reset the XR Reference space, set the 2nd variable to true:

xrCamera.setTransformationFromNonVRCamera(otherCamera, true);

This is called automatically when moving from and to XR, but you don’t need to call it yourself

yes i need it to recenter my app, or to teleport, or to do movements from the joystick…

This feature is coming “soon”. But you can implement it yourself, changing the camera’s position on each frame

yea but how do i change camera’s position on each frame then?

onBeforeRender ?
i change there xrCamera.position? and rotation?

exactly :slight_smile:
You can see what the input manager is doing to the universal camera. the same thing can be developed for the webxr camera

well i ll try, maybe i did it wrong last time

1 Like