Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Assets/MRTK/Providers/OpenXR/MRTK.OpenXR.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"name": "com.unity.xr.openxr",
"expression": "",
"define": "UNITY_OPENXR"
},
{
"name": "com.microsoft.windows.mixedreality.dotnetwinrt",
"expression": "",
"define": "DOTNETWINRT_PRESENT"
}
],
"noEngineReferences": false
Expand Down
39 changes: 37 additions & 2 deletions Assets/MRTK/Providers/OpenXR/Scripts/OpenXREyeGazeDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@
using UnityEngine.XR.OpenXR.Features.Interactions;
#endif // UNITY_OPENXR

#if MSFT_OPENXR
#if WINDOWS_UWP
using Windows.Perception;
using Windows.Perception.People;
using Windows.Perception.Spatial;
using Windows.UI.Input.Spatial;
#elif UNITY_WSA && DOTNETWINRT_PRESENT
using Microsoft.Windows.Perception;
using Microsoft.Windows.Perception.People;
using Microsoft.Windows.Perception.Spatial;
using Microsoft.Windows.UI.Input.Spatial;
#endif
#endif // MSFT_OPENXR

namespace Microsoft.MixedReality.Toolkit.XRSDK.OpenXR
{
[MixedRealityDataProvider(
Expand Down Expand Up @@ -163,12 +177,12 @@ public override void Update()

if (!eyeTrackingDevice.isValid)
{
Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, false);
UpdateEyeTrackingCalibrationStatus(false);
return;
}
}

Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, true);
UpdateEyeTrackingCalibrationStatus(true);

#if UNITY_OPENXR
if (eyeTrackingDevice.TryGetFeatureValue(CommonUsages.isTracked, out bool gazeTracked)
Expand All @@ -191,5 +205,26 @@ public override void Update()
#endif // UNITY_OPENXR
}
}

private void UpdateEyeTrackingCalibrationStatus(bool defaultValue)
{
#if MSFT_OPENXR && (WINDOWS_UWP || (UNITY_WSA && DOTNETWINRT_PRESENT))
if (MixedReality.OpenXR.PerceptionInterop.GetSceneCoordinateSystem(Pose.identity) is SpatialCoordinateSystem worldOrigin)
{
SpatialPointerPose pointerPose = SpatialPointerPose.TryGetAtTimestamp(worldOrigin, PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now));
if (pointerPose != null)
{
EyesPose eyes = pointerPose.Eyes;
if (eyes != null)
{
Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, eyes.IsCalibrationValid);
return;
}
}
}
#endif // MSFT_OPENXR && (WINDOWS_UWP || (UNITY_WSA && DOTNETWINRT_PRESENT))

Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, defaultValue);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
using Unity.Profiling;
using Unity.XR.WindowsMR;
using UnityEngine.XR;

#if WINDOWS_UWP
using Windows.Perception;
using Windows.Perception.People;
using Windows.Perception.Spatial;
using Windows.UI.Input.Spatial;
#elif UNITY_WSA && DOTNETWINRT_PRESENT
using Microsoft.Windows.Perception;
using Microsoft.Windows.Perception.People;
using Microsoft.Windows.Perception.Spatial;
using Microsoft.Windows.UI.Input.Spatial;
#endif
#endif // WMR_2_7_0_OR_NEWER || WMR_4_4_2_OR_NEWER || WMR_5_2_2_OR_NEWER

namespace Microsoft.MixedReality.Toolkit.XRSDK.WindowsMixedReality
Expand Down Expand Up @@ -172,18 +184,18 @@ public override void Update()
centerEye = InputDevices.GetDeviceAtXRNode(XRNode.CenterEye);
if (!centerEye.isValid)
{
Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, false);
UpdateEyeTrackingCalibrationStatus(false);
return;
}
}

if (!centerEye.TryGetFeatureValue(WindowsMRUsages.EyeGazeAvailable, out bool gazeAvailable) || !gazeAvailable)
{
Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, false);
UpdateEyeTrackingCalibrationStatus(false);
return;
}

Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, true);
UpdateEyeTrackingCalibrationStatus(true);

if (centerEye.TryGetFeatureValue(WindowsMRUsages.EyeGazeTracked, out bool gazeTracked)
&& gazeTracked
Expand All @@ -204,6 +216,28 @@ public override void Update()
}
}
}

private void UpdateEyeTrackingCalibrationStatus(bool defaultValue)
{
#if WINDOWS_UWP || (UNITY_WSA && DOTNETWINRT_PRESENT)
SpatialCoordinateSystem worldOrigin = Toolkit.WindowsMixedReality.WindowsMixedRealityUtilities.SpatialCoordinateSystem;
if (worldOrigin != null)
{
SpatialPointerPose pointerPose = SpatialPointerPose.TryGetAtTimestamp(worldOrigin, PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now));
if (pointerPose != null)
{
EyesPose eyes = pointerPose.Eyes;
if (eyes != null)
{
Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, eyes.IsCalibrationValid);
return;
}
}
}
#endif // WINDOWS_UWP || (UNITY_WSA && DOTNETWINRT_PRESENT)

Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, defaultValue);
}
#endif // WMR_2_7_0_OR_NEWER || WMR_4_4_2_OR_NEWER || WMR_5_2_2_OR_NEWER
}
}