HandState.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal
  10. {
  11. using System;
  12. using System.Collections.Generic;
  13. using UnityEngine;
  14. public enum HandEnum
  15. {
  16. None = -1,
  17. RightHand,
  18. LeftHand
  19. }
  20. public enum HandGesture
  21. {
  22. None = -1,
  23. OpenHand,
  24. Grab,
  25. Pinch,
  26. Point,
  27. Victory,
  28. Call,
  29. System,
  30. }
  31. public enum HandJointID
  32. {
  33. Invalid = -1,
  34. Wrist = 0,
  35. Palm,
  36. ThumbMetacarpal,
  37. ThumbProximal,
  38. ThumbDistal,
  39. ThumbTip,
  40. IndexProximal,
  41. IndexMiddle,
  42. IndexDistal,
  43. IndexTip,
  44. MiddleProximal,
  45. MiddleMiddle,
  46. MiddleDistal,
  47. MiddleTip,
  48. RingProximal,
  49. RingMiddle,
  50. RingDistal,
  51. RingTip,
  52. PinkyMetacarpal,
  53. PinkyProximal,
  54. PinkyMiddle,
  55. PinkyDistal,
  56. PinkyTip,
  57. Max = PinkyTip + 1
  58. }
  59. /// <summary> Contains the details of current hand tracking info of left/right hand. </summary>
  60. public class HandState
  61. {
  62. public readonly HandEnum handEnum;
  63. public bool isTracked;
  64. public Pose pointerPose;
  65. public bool pointerPoseValid;
  66. public bool isPinching => currentGesture == HandGesture.Pinch;
  67. public HandGesture currentGesture;
  68. public float confidence;
  69. public readonly Dictionary<HandJointID, Pose> jointsPoseDict = new Dictionary<HandJointID, Pose>();
  70. public HandState(HandEnum handEnum)
  71. {
  72. this.handEnum = handEnum;
  73. Reset();
  74. }
  75. /// <summary> Reset the hand state to default. </summary>
  76. public void Reset()
  77. {
  78. isTracked = false;
  79. pointerPose = Pose.identity;
  80. pointerPoseValid = false;
  81. currentGesture = HandGesture.None;
  82. jointsPoseDict.Clear();
  83. }
  84. /// <summary>
  85. /// Returns the pose of the hand joint ID of this hand state.
  86. /// </summary>
  87. /// <param name="handJointID"></param>
  88. /// <returns></returns>
  89. public Pose GetJointPose(HandJointID handJointID)
  90. {
  91. Pose pose = Pose.identity;
  92. jointsPoseDict.TryGetValue(handJointID, out pose);
  93. return pose;
  94. }
  95. }
  96. }