<commit_before>﻿// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.MixedReality.Toolkit.Input;
using Microsoft.MixedReality.Toolkit.Utilities;
using UnityEngine.XR;

#if WMR_2_7_OR_NEWER_ENABLED
using System;
using Unity.Profiling;
using Unity.XR.WindowsMR;
using UnityEngine;
#endif // WMR_2_7_OR_NEWER_ENABLED


namespace Microsoft.MixedReality.Toolkit.XRSDK.WindowsMixedReality
{
    [MixedRealityDataProvider(
        typeof(IMixedRealityInputSystem),
        SupportedPlatforms.WindowsUniversal,
        "XRSDK Windows Mixed Reality Eye Gaze Provider",
        "Profiles/DefaultMixedRealityEyeTrackingProfile.asset", "MixedRealityToolkit.SDK",
        true)]
    public class WindowsMixedRealityEyeGazeDataProvider : BaseEyeGazeDataProvider, IMixedRealityCapabilityCheck
    {
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="inputSystem">The <see cref="Microsoft.MixedReality.Toolkit.Input.IMixedRealityInputSystem"/> instance that receives data from this provider.</param>
        /// <param name="name">Friendly name of the service.</param>
        /// <param name="priority">Service priority. Used to determine order of instantiation.</param>
        /// <param name="profile">The service's configuration profile.</param>
        public WindowsMixedRealityEyeGazeDataProvider(
            IMixedRealityInputSystem inputSystem,
            string name,
            uint priority,
            BaseMixedRealityProfile profile) : base(inputSystem, name, priority, profile) { }

        private InputDevice centerEye = default(InputDevice);

        #region IMixedRealityCapabilityCheck Implementation

        /// <inheritdoc />
        public bool CheckCapability(MixedRealityCapability capability) =>
#if WMR_2_7_OR_NEWER_ENABLED
                                                                          capability == MixedRealityCapability.EyeTracking
                                                                          && centerEye.isValid
                                                                          && centerEye.TryGetFeatureValue(WindowsMRUsages.EyeGazeAvailable, out bool gazeAvailable)
                                                                          && gazeAvailable;
#else
                                                                          false;
#endif // WMR_2_7_OR_NEWER_ENABLED

        #endregion IMixedRealityCapabilityCheck Implementation

#if WMR_2_7_OR_NEWER_ENABLED
        private static readonly ProfilerMarker UpdatePerfMarker = new ProfilerMarker("[MRTK] WindowsMixedRealityEyeGazeDataProvider.Update");

        /// <inheritdoc />
        public override void Update()
        {
            using (UpdatePerfMarker.Auto())
            {
                if (!centerEye.isValid)
                {
                    centerEye = InputDevices.GetDeviceAtXRNode(XRNode.CenterEye);
                    if (!centerEye.isValid)
                    {
                        return;
                    }
                }

                bool gazeAvailable = false;
                if (centerEye.TryGetFeatureValue(WindowsMRUsages.EyeGazeAvailable, out gazeAvailable) && gazeAvailable)
                {
                    Service?.EyeGazeProvider?.UpdateEyeTrackingStatus(this, gazeAvailable);

                    Vector3 eyeGazePosition;
                    Quaternion eyeGazeRotation;
                    if (centerEye.TryGetFeatureValue(WindowsMRUsages.EyeGazePosition, out eyeGazePosition) && centerEye.TryGetFeatureValue(WindowsMRUsages.EyeGazeRotation, out eyeGazeRotation))
                    {
                        Vector3 worldPosition = CameraCache.Main.transform.TransformPoint(eyeGazePosition);
                        Vector3 worldRotation = CameraCache.Main.transform.TransformDirection(eyeGazeRotation * Vector3.forward);

                        Ray newGaze = new Ray(worldPosition, worldRotation);

                        if (SmoothEyeTracking)
                        {
                            newGaze = SmoothGaze(newGaze);
                        }

                        Service?.EyeGazeProvider?.UpdateEyeGaze(this, newGaze, DateTime.UtcNow);
                    }
                }
            }
        }
#endif // WMR_2_7_OR_NEWER_ENABLED
    }
}<commit_msg>Update eye tracking to properly report state<commit_after>﻿// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.MixedReality.Toolkit.Input;
using Microsoft.MixedReality.Toolkit.Utilities;
using UnityEngine.XR;

#if WMR_2_7_OR_NEWER_ENABLED
using System;
using Unity.Profiling;
using Unity.XR.WindowsMR;
using UnityEngine;
#endif // WMR_2_7_OR_NEWER_ENABLED


namespace Microsoft.MixedReality.Toolkit.XRSDK.WindowsMixedReality
{
    [MixedRealityDataProvider(
        typeof(IMixedRealityInputSystem),
        SupportedPlatforms.WindowsUniversal,
        "XRSDK Windows Mixed Reality Eye Gaze Provider",
        "Profiles/DefaultMixedRealityEyeTrackingProfile.asset", "MixedRealityToolkit.SDK",
        true)]
    public class WindowsMixedRealityEyeGazeDataProvider : BaseEyeGazeDataProvider, IMixedRealityCapabilityCheck
    {
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="inputSystem">The <see cref="Microsoft.MixedReality.Toolkit.Input.IMixedRealityInputSystem"/> instance that receives data from this provider.</param>
        /// <param name="name">Friendly name of the service.</param>
        /// <param name="priority">Service priority. Used to determine order of instantiation.</param>
        /// <param name="profile">The service's configuration profile.</param>
        public WindowsMixedRealityEyeGazeDataProvider(
            IMixedRealityInputSystem inputSystem,
            string name,
            uint priority,
            BaseMixedRealityProfile profile) : base(inputSystem, name, priority, profile) { }

        private InputDevice centerEye = default(InputDevice);

        #region IMixedRealityCapabilityCheck Implementation

        /// <inheritdoc />
        public bool CheckCapability(MixedRealityCapability capability) =>
#if WMR_2_7_OR_NEWER_ENABLED
                                                                          capability == MixedRealityCapability.EyeTracking
                                                                          && centerEye.isValid
                                                                          && centerEye.TryGetFeatureValue(WindowsMRUsages.EyeGazeAvailable, out bool gazeAvailable)
                                                                          && gazeAvailable;
#else
                                                                          false;
#endif // WMR_2_7_OR_NEWER_ENABLED

        #endregion IMixedRealityCapabilityCheck Implementation

#if WMR_2_7_OR_NEWER_ENABLED
        private static readonly ProfilerMarker UpdatePerfMarker = new ProfilerMarker("[MRTK] WindowsMixedRealityEyeGazeDataProvider.Update");

        /// <inheritdoc />
        public override void Update()
        {
            using (UpdatePerfMarker.Auto())
            {
                if (!centerEye.isValid)
                {
                    centerEye = InputDevices.GetDeviceAtXRNode(XRNode.CenterEye);
                    if (!centerEye.isValid)
                    {
                        return;
                    }
                }

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

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

                if (centerEye.TryGetFeatureValue(WindowsMRUsages.EyeGazeTracked, out bool gazeTracked) && gazeTracked)
                {
                    Vector3 eyeGazePosition;
                    Quaternion eyeGazeRotation;
                    if (centerEye.TryGetFeatureValue(WindowsMRUsages.EyeGazePosition, out eyeGazePosition) && centerEye.TryGetFeatureValue(WindowsMRUsages.EyeGazeRotation, out eyeGazeRotation))
                    {
                        Ray newGaze = new Ray(eyeGazePosition, eyeGazeRotation * Vector3.forward);

                        if (SmoothEyeTracking)
                        {
                            newGaze = SmoothGaze(newGaze);
                        }

                        Service?.EyeGazeProvider?.UpdateEyeGaze(this, newGaze, DateTime.UtcNow);
                    }
                }
            }
        }
#endif // WMR_2_7_OR_NEWER_ENABLED
    }
}
{'fraction_non_alphanumeric': 0.07339449541284404, 'fraction_numerical': 0.0034403669724770644, 'mean_word_length': 1.7951923076923078, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1468647', 'n_tokens_mistral': 2197, 'n_tokens_neox': 2076, 'n_words': 389}