Adding persistent WebXR AR anchor creation and event handling to WebXRManager and anchor demo
Related #24792.
Description
Added support for Meta Quest Pro and Quest 2 support for anchor creation and events along with an example.
Compiled and testable place to test example ( simply pull triggers on either controller and it will spawn anchors with boxes that match anchor location and rotation ). Note when anchors lose their known pose I make their associated cube invisible ( @cabanier this seems to happen fairly often, not sure if that is normal for anchors to lose pose, sometimes some cubes are very persistent, usually when I turn my head entirely in a different direction I lose them the easiest ):
https://raw.githack.com/richardanaya/three.js/anchors_test_3/examples/webxr_ar_anchors.html

@Mugen87 ready for you review 🙏🏽
Compiled and testable place to test example ( simply pull triggers on either controller and it will spawn anchors with boxes that match anchor location and rotation ). Note when anchors lose their known pose I make their associated cube invisible ( @cabanier this seems to happen fairly often, not sure if that is normal for anchors to lose pose, sometimes some cubes are very persistent, usually when I turn my head entirely in a different direction I lose them the easiest ):
I have not seen that in my testing. Can you record this? I'll talk to our team that is working on anchors.
@cabanier persistent anchors implemented with restore and delete functions and updated example to use local storage to restore uuids across sessions.
https://raw.githack.com/richardanaya/three.js/anchors_test_2/examples/webxr_ar_anchors.html
The demo works right now, hitting trigger adds a new persistent cube until you reach your max then it clears all the anchors ( this seemed the simplest demo I could imagine ). Exiting and refreshing and re-entering you will see your cubes re-appear.
I seem to be having a strange error around deletion of anchors. if I start fresh in a session (even with restored anchors), I can delete any and all anchors. But, if I add five persistent anchors ( the limit ) and then delete one of those persistent anchors I get some error.
Super cool to see this work though!
Can you reproduce with this WebXR sample: https://cabanier.github.io/webxr-samples-1/anchors.html
Video of current demo:
https://user-images.githubusercontent.com/294042/199188523-1b7b0f1a-02bc-42a7-a3d1-6f24b0cb0233.mp4
Can you reproduce with this WebXR sample: https://cabanier.github.io/webxr-samples-1/anchors.html
yep, looks like
@Mugen87 @cabanier to the best of my knowledge this PR is as far as I can take it
I seem to be having a strange error around deletion of anchors. if I start fresh in a session (even with restored anchors), I can delete any and all anchors. But, if I add five persistent anchors ( the limit ) and then delete one of those persistent anchors I get some error.
Thanks! I was able to reproduce what you're seeing. It will be fixed in 24.3 of the Quest browser.
Added documentation.
@cabanier perhaps you might verify, but to my knowledge I don't think i'm doing anything that would have to change for this PR for a future release of Oculus Browser. Perhaps this PR might be viable for 147 release?
Fixed some merge conflicts.
@cabanier I've been having a challenging issue i'm not sure how to get around. I'm able to my browser in a situation where:
-
trackedAnchorsis zero length - i'm unable to create a new persisted anchor because i've reached the max limit
I clear all my browser settings/history ( as per https://developer.oculus.com/documentation/web/webxr-mixed-reality/ ), but I come back and still the first anchor I create causes a "max anchors reached".
I'm not quite sure how to get out of this state, or find these missing older anchors that i've persisted.
I also changed the API of this PR to have two functions createAnchor and createPersistentAnchor. They have different return types and it didn't feel right returning a single anchor in one scenario, and an anchor and uuid in another situation.
-
createAnchorreturnsPromise<XRAnchor> -
createPersistentAnchorreturnsPromise<[XRAnchor, string]>
Usage would be:
const [ anchor, uuid ] = await createPersistentAnchor( ... );
You can clear the persistent anchor by deleting the browser history. I agree that there should be a nicer way to do so. We could either return the list of persistent anchors or allow you to delete all of them in a single call.
@cabanier it might have been subtle in my prior message, but I actually wasn't able to clear out my anchors by clearing my history. I verify all my site data say zero and look that history is zero. Close and restart browser. First trigger gives me "you have maxed out anchors". Not sure where to report that. This is with latest 24.3.
That said the latest demo preview is at:
https://raw.githack.com/richardanaya/three.js/anchors_test_3/examples/webxr_ar_anchors.html
@cabanier it might have been subtle in my prior message, but I actually wasn't able to clear out my anchors by clearing my history. I verify all my site data say zero and look that history is zero. Close and restart browser. First trigger gives me "you have maxed out anchors". Not sure where to report that. This is with latest 24.3.
That said the latest demo preview is at:
https://raw.githack.com/richardanaya/three.js/anchors_test_3/examples/webxr_ar_anchors.html
Make sure you scroll down in the dialog to clear the history. It might be hidden :-\
https://user-images.githubusercontent.com/294042/20233970-d9d9576e-b423-4bcb-9155-89b4ececb1fd.mp4
@cabanier pretty sure i did the area you refer
@cabanier oh, forgot to mention, my 2 cents for WebXR api , having a 'getAllPersistentAnchorHandles' to return all the uuids of the anchors (not the anchors themselves) would prevent us from having to store them in localStorage to retrieve them on startup to restore :) I don't think putting them on trackedAnchors makes sense until they have been restored. And as you are aware, if I had this function I could programmatically clear out known persistent anchors.
Can you file an issue in the real world geometry repo?
getAllPersistentAnchorHandles
https://github.com/immersive-web/real-world-geometry/issues/37 done :)
@cabanier Finally got the browser update :)
Note to others reading this: make sure your Oculus Quest browser is up to date at 24.4 to support latest openXR spec for XRSession.persistentAnchors:
- added new function
getPersistentAnchors - This allowed me to radically simplify my example to no longer use local storage.
- I ended up removing the function
createPersistentAnchor. This function was actually surprisingly troublesome in scenarios where the anchor was successfully created by the persistent handle was not. It made more sense for me to have the anchor creation and persistence as two separate steps. - Verified that 'clear local storage' is now working.
- renamed some of the other functions to be more explicit they are involved in manipulating persistent anchors.
- Updated test at: https://raw.githack.com/richardanaya/three.js/anchors_test_3/examples/webxr_ar_anchors.html
https://user-images.githubusercontent.com/294042/206881641-4ae3b78a-442b-4c5e-84c5-e7c7a10c76bd.mp4
@cabanier I don't think this is really a show stopper, but I did notice a bug where it said I couldn't delete an anchor when I have utilized my full capacity of persisted anchors, it gave me a strange error related to adding an anchor, which was super strange because I had deleted.
Hey all I just wanted to chime in that I am using the fix from richardanaya on a Meta Quest Pro and it's working for me. Thanks for the improvement @richardanaya .
@mrdoob any thoughts on this?