Environment
Unity 2022.3, ML2 SDK 2.5.0 OpenXR
Question
How can I programmatically reset the Magic Leap 2's origin coordinates to 0,0,0? The device automatically sets its origin at startup and after tracking loss, but I need to trigger this reset through code.
What I've Tried
csharpCopyprivate XRInputSubsystem _inputSubsystem;
_inputSubsystem = XRGeneralSettings.Instance.Manager.activeLoader.GetLoadedSubsystem<XRInputSubsystem>();
_inputSubsystem.TrySetTrackingOriginMode(TrackingOriginModeFlags.Unbounded);
_inputSubsystem.TryRecenter();
This implementation attempts to reset the origin, but the zero point remains unchanged.
Is there a correct way to force the ML2 to reset its origin to 0,0,0?
I am aware of recenter XR origin at start, but it seems not to do proper zero point reset either by using this to measure the head tracking:
InputDevice hmdDevice = InputDevices.GetDeviceAtXRNode(XRNode.CenterEye);
if (hmdDevice.isValid)
{
if (hmdDevice.TryGetFeatureValue(CommonUsages.devicePosition, out Vector3 position))
{
Log($"Head Position: X:{position.x:F2} Y:{position.y:F2} Z:{position.z:F2}");
}
}
And Magic leap 2 Reference spaces enabled
etucker
December 16, 2024, 7:19pm
2
TryRecenter()
and similar XR calls are designed for VR platforms to reset the user's "forward" direction or "floor level." On Magic Leap, the spatial coordinate system is AR-like, defined relative to the environment. Instead of altering the global origin (0,0,0), use a parent transform like XR Origin
or ARSessionOrigin
:
Capture the current device position to "reset" the origin.
Store this offset as the "new zero."
Example:
var xro = FindObjectOfType<Unity.XR.CoreUtils.XROrigin>();
xro?.MoveCameraToWorldLocation(Vector3.zero);
xro?.MatchOriginUpCameraForward(Vector3.up, Vector3.forward);
This approach redefines app content alignment relative to the global origin without modifying it.
Let me know if you have any questions.
Thank you, this is the same code as in recenter from the startup button.
I found a way to achieve the goal
In case someone is trying to solve this still and want more power.
Search this file and open for info:
C:...\Library\PackageCache\com.unity.xr.core-utils@2.3.0\Runtime\XROrigin.cs
Rotation Controls:
RotateAroundCameraUsingOriginUp(float angleDegrees)
- Rotates around camera using origin's up vector
RotateAroundCameraPosition(Vector3 vector, float angleDegrees)
- Rotates around camera with custom axis
Origin Position & Forward:
MatchOriginUp(Vector3 destinationUp)
- Changes origin's up vector
MatchOriginUpCameraForward(Vector3 destinationUp, Vector3 destinationForward)
- Aligns camera's view direction
MatchOriginUpOriginForward(Vector3 destinationUp, Vector3 destinationForward)
- Aligns physical walking direction
Camera Position Controls:
MoveCameraToWorldLocation(Vector3 desiredWorldLocation)
- Teleports camera
CameraYOffset
property - Adjusts camera height (in Device mode)
Tracking Mode Controls:
RequestedTrackingOriginMode
property - Can be set to:
TrackingOriginMode.NotSpecified
TrackingOriginMode.Device
TrackingOriginMode.Floor
Read-Only Properties:
CurrentTrackingOriginMode
- Current tracking mode
OriginInCameraSpacePos
- Origin position relative to camera
CameraInOriginSpacePos
- Camera position relative to origin
CameraInOriginSpaceHeight
- Camera height relative to origin
Object References:
Camera
property - Get/set the XR camera
Origin
property - Get/set the origin GameObject
CameraFloorOffsetObject
property - Get/set floor offset object
TrackablesParent
property - Parent transform for trackables
1 Like
system
Closed
January 2, 2025, 3:20am
4
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.