Skip to content

Commit 6ceb3b5

Browse files
authored
Expose eye calibration state when using XR SDK (#11269)
* Update to properly expose calibration state when using XR SDK * Add a null check * Remove DOTNETWINRT_PRESENT from OpenXR The method for querying the scene coordinate system doesn't work in-editor anyway
1 parent 7503ecc commit 6ceb3b5

File tree

2 files changed

+67
-5
lines changed

2 files changed

+67
-5
lines changed

Assets/MRTK/Providers/OpenXR/Scripts/OpenXREyeGazeDataProvider.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
using UnityEngine.XR.OpenXR.Features.Interactions;
1515
#endif // UNITY_OPENXR
1616

17+
#if MSFT_OPENXR && WINDOWS_UWP
18+
using Windows.Perception;
19+
using Windows.Perception.People;
20+
using Windows.Perception.Spatial;
21+
using Windows.UI.Input.Spatial;
22+
#endif // MSFT_OPENXR && WINDOWS_UWP
23+
1724
namespace Microsoft.MixedReality.Toolkit.XRSDK.OpenXR
1825
{
1926
[MixedRealityDataProvider(
@@ -163,12 +170,12 @@ public override void Update()
163170

164171
if (!eyeTrackingDevice.isValid)
165172
{
166-
Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, false);
173+
UpdateEyeTrackingCalibrationStatus(false);
167174
return;
168175
}
169176
}
170177

171-
Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, true);
178+
UpdateEyeTrackingCalibrationStatus(true);
172179

173180
#if UNITY_OPENXR
174181
if (eyeTrackingDevice.TryGetFeatureValue(CommonUsages.isTracked, out bool gazeTracked)
@@ -191,5 +198,26 @@ public override void Update()
191198
#endif // UNITY_OPENXR
192199
}
193200
}
201+
202+
private void UpdateEyeTrackingCalibrationStatus(bool defaultValue)
203+
{
204+
#if MSFT_OPENXR && WINDOWS_UWP
205+
if (MixedReality.OpenXR.PerceptionInterop.GetSceneCoordinateSystem(Pose.identity) is SpatialCoordinateSystem worldOrigin)
206+
{
207+
SpatialPointerPose pointerPose = SpatialPointerPose.TryGetAtTimestamp(worldOrigin, PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now));
208+
if (pointerPose != null)
209+
{
210+
EyesPose eyes = pointerPose.Eyes;
211+
if (eyes != null)
212+
{
213+
Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, eyes.IsCalibrationValid);
214+
return;
215+
}
216+
}
217+
}
218+
#endif // MSFT_OPENXR && WINDOWS_UWP
219+
220+
Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, defaultValue);
221+
}
194222
}
195223
}

Assets/MRTK/Providers/WindowsMixedReality/XRSDK/WindowsMixedRealityEyeGazeDataProvider.cs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
using Unity.Profiling;
1313
using Unity.XR.WindowsMR;
1414
using UnityEngine.XR;
15+
16+
#if WINDOWS_UWP
17+
using Windows.Perception;
18+
using Windows.Perception.People;
19+
using Windows.Perception.Spatial;
20+
using Windows.UI.Input.Spatial;
21+
#elif UNITY_WSA && DOTNETWINRT_PRESENT
22+
using Microsoft.Windows.Perception;
23+
using Microsoft.Windows.Perception.People;
24+
using Microsoft.Windows.Perception.Spatial;
25+
using Microsoft.Windows.UI.Input.Spatial;
26+
#endif
1527
#endif // WMR_2_7_0_OR_NEWER || WMR_4_4_2_OR_NEWER || WMR_5_2_2_OR_NEWER
1628

1729
namespace Microsoft.MixedReality.Toolkit.XRSDK.WindowsMixedReality
@@ -172,18 +184,18 @@ public override void Update()
172184
centerEye = InputDevices.GetDeviceAtXRNode(XRNode.CenterEye);
173185
if (!centerEye.isValid)
174186
{
175-
Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, false);
187+
UpdateEyeTrackingCalibrationStatus(false);
176188
return;
177189
}
178190
}
179191

180192
if (!centerEye.TryGetFeatureValue(WindowsMRUsages.EyeGazeAvailable, out bool gazeAvailable) || !gazeAvailable)
181193
{
182-
Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, false);
194+
UpdateEyeTrackingCalibrationStatus(false);
183195
return;
184196
}
185197

186-
Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, true);
198+
UpdateEyeTrackingCalibrationStatus(true);
187199

188200
if (centerEye.TryGetFeatureValue(WindowsMRUsages.EyeGazeTracked, out bool gazeTracked)
189201
&& gazeTracked
@@ -204,6 +216,28 @@ public override void Update()
204216
}
205217
}
206218
}
219+
220+
private void UpdateEyeTrackingCalibrationStatus(bool defaultValue)
221+
{
222+
#if WINDOWS_UWP || (UNITY_WSA && DOTNETWINRT_PRESENT)
223+
SpatialCoordinateSystem worldOrigin = Toolkit.WindowsMixedReality.WindowsMixedRealityUtilities.SpatialCoordinateSystem;
224+
if (worldOrigin != null)
225+
{
226+
SpatialPointerPose pointerPose = SpatialPointerPose.TryGetAtTimestamp(worldOrigin, PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now));
227+
if (pointerPose != null)
228+
{
229+
EyesPose eyes = pointerPose.Eyes;
230+
if (eyes != null)
231+
{
232+
Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, eyes.IsCalibrationValid);
233+
return;
234+
}
235+
}
236+
}
237+
#endif // WINDOWS_UWP || (UNITY_WSA && DOTNETWINRT_PRESENT)
238+
239+
Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, defaultValue);
240+
}
207241
#endif // WMR_2_7_0_OR_NEWER || WMR_4_4_2_OR_NEWER || WMR_5_2_2_OR_NEWER
208242
}
209243
}

0 commit comments

Comments
 (0)