WebXR Anchors
Implementation of an experimental draft spec: https://github.com/immersive-web/anchors/blob/main/explainer.md
It is available in Chrome for Android 89, with enabled chrome://flags#webxr-incubations flag.
Anchors provide an ability to specify a point in the world that need to be updated to correctly reflect the evolving understanding of the world by the underlying AR system, such that the anchor remains aligned with the same place in the physical world. Anchors tend to persist better relative to the real world, especially during a longer session with lots of movement.
In the future Spec might update and they will provide cross-session anchors support.
New APIs:
// pc.XrManager
app.xr.anchors // interface to access anchors
// pc.Anchors
anchors.supported // true if plane detection is supported
anchors.list // a list of pc.Anchor's
anchors.create(position, rotation, function(err, anchor) { }) // method to create anchor with specific position, optional rotation and optional callback.
anchors.on('add', (anchor) => { }); // fired when new anchor is created
anchors.on('destroy', (anchor) => { }); // fired when anchor is destroyed
anchors.on('error', (err) => { }); // fired when there was an error, potentially related to anchor creation
// pc.XrAnchor
anchor.destroy() // destroy an anchor
anchor.getPosition() // get world position of an anchor
anchor.getRotation() // get world rotation of an anchor
anchor.on('change', function() { }); // fired when anchor position and/or rotation has been changed
anchor.once('destroy', function() { }); // fired when anchor has been destroyed
Test project:
https://playcanvas.com/project/785123/overview/webxr-ar-anchors This project relies on Hit Test API and allows to place anchors by tapping on surfaces.
Test Build:
https://playcanv.as/p/Skq3Ry1K/ Ensure you have chrome://flags#webxr-incubations enabled
I confirm I have signed the Contributor License Agreement.
Help, #typescriptproblems. Not sure how to deal with this problem. :(
@Maksims Looks like the issue is:
Error: build/playcanvas.d.ts(17586,66): error TS2694: Namespace '"build/playcanvas".callbacks' has no exported member 'XrAnchorCreate'.
In callback.js, it's missing XrAnchorCreate
Add something like this to callbacks.js
/**
* @callback callbacks.XrAnchorCreate
* @description Callback used by {@link XrAnchors#create}.
* @param {Error|null} err - The Error object if failed to create an anchor or null.
* @param {XrAnchor|null} xrAnchor - The anchor that is tracked against real world geometry.
*/
PS Sorry about the late reply, only just saw that you needed help 😅
More merge conflicts here too @Maksims. 😄
Updated this PR to be mergeable, but get two errors with TypeScript Declarations (#typescriptissues....). Not sure how to fix it or what to do with these two issues. It complains about two classes that are global and come from WebXR APIs.