Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebXR Anchors #3091

Merged
merged 38 commits into from
Aug 10, 2023
Merged

WebXR Anchors #3091

merged 38 commits into from
Aug 10, 2023

Conversation

Maksims
Copy link
Contributor

@Maksims Maksims commented Apr 14, 2021

Implementation of an experimental draft spec: https://github.com/immersive-web/anchors/blob/main/explainer.md

It is available in Chrome for Android.

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.

Current WebXR Anchors spec provides persistence features - Anchors can provide persistent UID, that can be used to restore them between sessions. But currently Chrome for Android 115 - does not support it.

New APIs:

// pc.XrManager
app.xr.anchors // interface to access anchors

// pc.Anchors
anchors.supported // true if anchors are 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/

I confirm I have signed the Contributor License Agreement.

@Maksims
Copy link
Contributor Author

Maksims commented Apr 14, 2021

Help, #typescriptproblems. Not sure how to deal with this problem. :(

@Maksims Maksims changed the title Webxr anchors WebXR Anchors Apr 21, 2021
@yaustar
Copy link
Contributor

yaustar commented May 20, 2021

@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 😅

@yaustar yaustar requested a review from a team May 20, 2021 15:57
@yaustar yaustar added area: xr XR related issue enhancement labels May 20, 2021
@willeastcott
Copy link
Contributor

More merge conflicts here too @Maksims. 😄

src/xr/xr-anchor.js Outdated Show resolved Hide resolved
src/xr/xr-anchor.js Outdated Show resolved Hide resolved
src/xr/xr-anchor.js Outdated Show resolved Hide resolved
src/xr/xr-anchor.js Outdated Show resolved Hide resolved
src/xr/xr-anchor.js Outdated Show resolved Hide resolved
src/xr/xr-anchor.js Outdated Show resolved Hide resolved
src/xr/xr-anchors.js Outdated Show resolved Hide resolved
src/xr/xr-anchors.js Outdated Show resolved Hide resolved
src/xr/xr-anchors.js Outdated Show resolved Hide resolved
src/xr/xr-anchors.js Outdated Show resolved Hide resolved
src/xr/xr-anchors.js Outdated Show resolved Hide resolved
src/xr/xr-anchors.js Outdated Show resolved Hide resolved
@Maksims
Copy link
Contributor Author

Maksims commented Aug 8, 2023

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.

Copy link
Contributor

@willeastcott willeastcott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with final round of feedback. I'll merge when those are addressed. Thanks! 🚀

Maksims and others added 4 commits August 10, 2023 12:35
Co-authored-by: Will Eastcott <will@playcanvas.com>
Co-authored-by: Will Eastcott <will@playcanvas.com>
Co-authored-by: Will Eastcott <will@playcanvas.com>
@willeastcott willeastcott merged commit dcd21ca into playcanvas:main Aug 10, 2023
7 checks passed
@Maksims Maksims deleted the webxr-anchors branch August 10, 2023 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants