three.js icon indicating copy to clipboard operation
three.js copied to clipboard

Adding persistent WebXR AR anchor creation and event handling to WebXRManager and anchor demo

Open richardanaya opened this issue 3 years ago • 24 comments

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

image

richardanaya avatar Oct 30 '22 09:10 richardanaya

@Mugen87 ready for you review 🙏🏽

richardanaya avatar Oct 30 '22 21:10 richardanaya

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 avatar Nov 01 '22 05:11 cabanier

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

Screen Shot 2022-11-01 at 12 46 33 AM

Super cool to see this work though!

richardanaya avatar Nov 01 '22 07:11 richardanaya

Can you reproduce with this WebXR sample: https://cabanier.github.io/webxr-samples-1/anchors.html

cabanier avatar Nov 01 '22 08:11 cabanier

Video of current demo:

https://user-images.githubusercontent.com/294042/199188523-1b7b0f1a-02bc-42a7-a3d1-6f24b0cb0233.mp4

richardanaya avatar Nov 01 '22 08:11 richardanaya

Can you reproduce with this WebXR sample: https://cabanier.github.io/webxr-samples-1/anchors.html

yep, looks like

Screen Shot 2022-11-01 at 1 22 00 AM

richardanaya avatar Nov 01 '22 08:11 richardanaya

@Mugen87 @cabanier to the best of my knowledge this PR is as far as I can take it

richardanaya avatar Nov 01 '22 08:11 richardanaya

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.

cabanier avatar Nov 01 '22 23:11 cabanier

Added documentation.

richardanaya avatar Nov 03 '22 01:11 richardanaya

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

richardanaya avatar Nov 03 '22 03:11 richardanaya

Fixed some merge conflicts.

richardanaya avatar Nov 03 '22 16:11 richardanaya

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

  • trackedAnchors is 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.

  • createAnchor returns Promise<XRAnchor>
  • createPersistentAnchor returns Promise<[XRAnchor, string]>

Usage would be:

const [ anchor, uuid ] = await createPersistentAnchor( ... );

richardanaya avatar Nov 16 '22 02:11 richardanaya

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 avatar Nov 16 '22 03:11 cabanier

@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

richardanaya avatar Nov 16 '22 04:11 richardanaya

@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 :-\

cabanier avatar Nov 16 '22 05:11 cabanier

https://user-images.githubusercontent.com/294042/20233970-d9d9576e-b423-4bcb-9155-89b4ececb1fd.mp4

@cabanier pretty sure i did the area you refer

richardanaya avatar Nov 16 '22 16:11 richardanaya

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

richardanaya avatar Nov 16 '22 23:11 richardanaya

Can you file an issue in the real world geometry repo?

cabanier avatar Nov 16 '22 23:11 cabanier

getAllPersistentAnchorHandles

https://github.com/immersive-web/real-world-geometry/issues/37 done :)

richardanaya avatar Nov 17 '22 01:11 richardanaya

@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

richardanaya avatar Dec 11 '22 00:12 richardanaya

https://user-images.githubusercontent.com/294042/206881641-4ae3b78a-442b-4c5e-84c5-e7c7a10c76bd.mp4

richardanaya avatar Dec 11 '22 01:12 richardanaya

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

richardanaya avatar Dec 11 '22 04:12 richardanaya

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 .

topherzee avatar Jan 06 '23 11:01 topherzee

@mrdoob any thoughts on this?

richardanaya avatar Apr 16 '23 21:04 richardanaya