// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Microsoft.MixedReality.Toolkit.Input;
using Microsoft.MixedReality.Toolkit.Utilities;
using Microsoft.MixedReality.Toolkit.WindowsMixedReality;
using System;
using System.Collections.Generic;
using Unity.Profiling;
using UnityEngine;
using UnityEngine.XR;
#if WINDOWS_UWP
#if WMR_ENABLED
using UnityEngine.XR.WindowsMR;
#endif // WMR_ENABLED
using Windows.UI.Input.Spatial;
#endif // WINDOWS_UWP
namespace Microsoft.MixedReality.Toolkit.XRSDK.WindowsMixedReality
{
///
/// XR SDK implementation of Windows Mixed Reality articulated hands.
///
[MixedRealityController(
SupportedControllerType.ArticulatedHand,
new[] { Handedness.Left, Handedness.Right },
supportedUnityXRPipelines: SupportedUnityXRPipelines.XRSDK)]
public class WindowsMixedRealityXRSDKArticulatedHand : BaseWindowsMixedRealityXRSDKSource, IMixedRealityHand
{
///
/// Constructor.
///
public WindowsMixedRealityXRSDKArticulatedHand(
TrackingState trackingState,
Handedness controllerHandedness,
IMixedRealityInputSource inputSource = null,
MixedRealityInteractionMapping[] interactions = null)
: base(trackingState, controllerHandedness, inputSource, interactions, new ArticulatedHandDefinition(inputSource, controllerHandedness))
{
handDefinition = Definition as ArticulatedHandDefinition;
handMeshProvider = (controllerHandedness == Handedness.Left) ? WindowsMixedRealityHandMeshProvider.Left : WindowsMixedRealityHandMeshProvider.Right;
handMeshProvider.SetInputSource(inputSource);
}
private readonly ArticulatedHandDefinition handDefinition;
private readonly WindowsMixedRealityHandMeshProvider handMeshProvider;
private MixedRealityPose[] jointPoses = null;
private static readonly HandFinger[] handFingers = Enum.GetValues(typeof(HandFinger)) as HandFinger[];
private readonly List fingerBones = new List();
// The rotation offset between the reported grip pose of a hand and the palm joint orientation.
// These values were calculated by comparing the platform's reported grip pose and palm pose.
private static readonly Quaternion rightPalmOffset = new Quaternion(Mathf.Sqrt(0.125f), Mathf.Sqrt(0.125f), -Mathf.Sqrt(1.5f) / 2.0f, Mathf.Sqrt(1.5f) / 2.0f);
private static readonly Quaternion leftPalmOffset = new Quaternion(Mathf.Sqrt(0.125f), -Mathf.Sqrt(0.125f), Mathf.Sqrt(1.5f) / 2.0f, Mathf.Sqrt(1.5f) / 2.0f);
#if WINDOWS_UWP && WMR_ENABLED
private readonly List