question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebXRManager - Allow changing/setting the reference space

See original GitHub issue
Description of the problem

As a dev, I’d like to align the XR view to an arbitrary space. It would help to be able to set an offset reference space for the WebXRManager, to be used when reading the getViewerPose and getPose from the XRFrame.

Proposing:

// add an override reference space to use for reading XR poses
renderer.xr.setOffsetReferenceSpace(space: XRReferenceSpace);

// reset to the initial reference space
renderer.xr.resetReferenceSpace();

WebXRManager.onAnimationFrame : if there is an offsetReferenceSpace set, prefer that space while reading the poses for the player/controllers during the onAnimationFrame

frame.getViewerPose(offsetReferenceSpace || referenceSpace)
frame.getPose(offsetReferenceSpace || referenceSpace)

Usage:

// Shift to an arbitrary position/alignment!

// From the base tracking space.
const baseReferenceSpace: XRReferenceSpace = renderer.xr.getReferenceSpace();

// offset the rotation by 30 degress
const playerRotation = new Quaternion().setFromAxisAngle(new Vector3(0, 1, 0), MathUtils.DEG2RAD * 30);
const offsetRotation = { x: playerRotation.x, y: playerRotation.y, z: playerRotation.z, w: playerRotation.w };

// offset the tracking to center on our player
const playerPosition = new Vector3(100, 1, 30);
const offsetPosition = { x: playerPosition.x, y: playerPosition.y, z: playerPosition.z, w: 1 };

const transform = new XRRigidTransform(offsetPosition, offsetRotation);
const viewerSpace = baseReferenceSpace.getOffsetReferenceSpace(transform);

renderer.xr.setOffsetReferenceSpace(viewerSpace);

This will enable use of the native webxr XRRigidTransform and XRReferenceSpace for locomotion/movement without requiring the controllers + cameras conform to a specific hierarchy with the camera.parent to be placed at the guess of the floor location.

The controllers already support alternate reference frames now by way of the WebXRController.update(inputSource, frame, referenceSpace) call, which is great, however without a way to set a referenceSpace on the WebXRManager: 1: It only has a visible effect on the view if done in the scene.onBeforeRender (?) 2: Shifting the controllers to a custom reference space duplicates the updates for everything in that hierarchy, which was more perf impactful than I’d imagined when using the XRControllerModelFactory controllers attached.

Note: It is technically possible to use XRTransforms/XRReferenceSpace style currently, but requires a lot of ugly workarounds and intimate knowledge of what WebGLRenderer/WebXRManager is doing and when.

  • Noticing that the WebXRManager onAnimationFrameCallback includes the XRFrame in the callback, and storing/referencing the XRFrame in your setAnimationLoop.
  • Inserting a callback into scene.onBeforeRender to read the frame.getViewerPose(myCustomReferenceSpace), and apply to the cameras.
  • very fragile!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:13
  • Comments:20 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
sophiabaldonadocommented, Feb 19, 2021

I’m interested in setting an offset reference space, as well. Will #20949 be reopened?

1reaction
Mugen87commented, Apr 20, 2022

Fixed via #20949.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebXRManager – three.js docs
Returns the reference space. # .getSession () : XRSession. Returns the XRSession object which allows a more fine-grained management of active WebXR sessions...
Read more >
Geometry and reference spaces in WebXR - Web APIs | MDN
The following code snippet shows two simple functions, degreesToRadians() and radiansToDegrees() , which convert back and forth between the two ...
Read more >
docs/api/en/renderers/webxr/WebXRManager.html - three.js
[page:String referenceSpaceType] — The reference space type to set. Can be used to configure a spatial relationship with the user's physical environment.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found