How to use SceneReconstruction with persisted WorldAnchors and AnchorEntities

Hi,

I'm prototyping a visionOS app for which I'm trying to create the following behavior in mixed immersive space:

  • users pinch and drag to position a model entity in the real world starting from the ray-cast of the pinch, meaning that the initial position should be on a MeshAnchor from scene reconstruction (I got that working, even though it's less precise than I expected)

  • once the model entity is positioned, I want to anchor this to the world so that it will always stays there no matter what, from what I understand I need to create and add a WorldAnchor to a WorldTrackingProvider for that

  • after positioning the model entity, users should be able to pinch and drag the entity to change its position and have that be persisted from then onwards

It's not clear to me what the relationship between AnchorEntity(world:) and WorldAnchor is (looks like AnchorEntity(anchor:) isn't available in visionOS). What is the recommended way to keep these together?

Afterwards, what is the recommended way to covert coordinate spaces between repositioned scene coordinate space and the anchor entity hierarchy coordinate space? I tried a DragGesture on the model entity and convert the translation to the scene, that works only when the scene origin hasn't changed. After it has changed, the translation is using the wrong coordinate space.

Thanks for the help!

Geert

I recommend you download & take a look at the "Object placement" developer sample which you can find on https://developer.apple.com/documentation/visionos/tracking-points-in-world-space . That one uses raycasts against planes for initial placement, but that could be easily adapted to use mesh anchors instead. And apart from that it shows a way how to do a lot of the things that you have in mind, such as how to attach objects to world anchors and persist them, how to allow drag gestures to reposition objects etc.

Thanks so much! I somehow missed there was a downloadable example on that page, this looks perfect.

How to use SceneReconstruction with persisted WorldAnchors and AnchorEntities
 
 
Q