How to place anchor in the middle of the room

Is it possible to place an anchor in the middle of the room so i can add a box to it and walk around the box in that room?
Reading the docs i only see the examples using Hit Test to place an anchor on the floor.
I think Plane Detection is needed and then get the center point of the room from all directions an add an anchor.
Can someone help me with this question?
@RaananW maybe?

Hi!

Of course. the anchor feature has this function: addAnchorAtPositionAndRotationAsync , which takes a position and rotation and returns a promise of an IWebXRAnchor object. If you don’t want to use hit test, this will be the way to go.

Thank you for the quick reply!
I will read more about the addAnchorAtPositionAndRotationAsync function.
Can you give me a hint on how to get the center position of my room?

center of your room?.. there are different ways you might approach this - you can use mesh detection and calculate the mesh’s bounding box, you could use plane detection on your walls, but it all requires user interaction. Nothing will give you the center right when entering the session.
The simplest would be to ask the user to hit one wall (hit-test), hit the other wall, and then use those vectors to compute the room size, assuming the room is quadratic.

I want to avoid to ask the user since native apps on e.g. meta quest very often simply let objects float right in front of the user when starting the app.
Maybe there is a way with plane detection creating (plane) meshes like in this example Babylon.js Playground
After the meshes are created then compute the center from all meshes from their position.

any of those will require user interaction, as even with plane detection they will need to point at the walls before you have an answer.

but when you have every wall as a (plane) mesh it is possible to get the the center of every mesh with boundingSphere. Isn’t this the same as if the user points in the middel of the wall?

you should do whatever fits your usecase! All i said is that user interaction will anyhow be required.

Ok thank you for the helpful exchange!

1 Like