Hello everyone. I'm fairly new to Unity and Magic Leap 2 and am trying to build an indoor navigation application using Unity and ML2.
I have scanned my apartment, and it is stored in the Spaces app. When I start my application, it localizes to the scanned space, but I cannot figure out how to achieve a persistent coordinate system. By persistent, I mean I want to get approximately (0,0,0) whenever I reach my desk.
Does ML2 have the capability to transform Camera's transform into a global position or I'd appreciate any other workarounds for this?
In Unity, an apps origin point is determined upon app startup, so it will be different every time you start the app, which will cause digital content to move across different sessions.
To help alleviate this, you can make use of Spatial Anchors!
You can create an Anchor at a specific location in your app, store it, and load it so that it can be used across multiple sessions.
You can then place all of your digital content relative to that spatial anchor and it should be in the same spot across all sessions.
Thank you for your quick response. I appreciate it.
This seems a reasonable approach and I'll give it a try. However, just to make sure, I am going to need the user's (ML2's) position relative to the saved space in each frame (Not Unity's global coordinate). Isn't there any feature to convert the Unity's coordinate to the physical coordinate?
There is no way to get the users head position outside of the Unity coordinate system whilst using a Unity app.
To achieve persistent content positions, you first need to localize into a space on the ML2. Then, you would need to create a spatial anchor in your Unity app and then place all content relative to that anchor.
If you are localized into a space and you load any previously saved anchors you created while in that space, the anchors will be placed in the same location across every app session.
If you have positioned your content relative to these anchors, your content will also be placed in the same location across app sessions.
Since you seem to already be using spaces and localizing into them, another option is to use the currently localized space origin with localizationMapFeature.GetMapOrigin() as your 'anchor' and place all your content relative to that position instead.