SteamVR_Skeleton_Pose.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. using System;
  3. using System.Collections;
  4. using UnityEngine;
  5. using Valve.VR;
  6. using System.Linq;
  7. namespace Valve.VR
  8. {
  9. public class SteamVR_Skeleton_Pose : ScriptableObject
  10. {
  11. public SteamVR_Skeleton_Pose_Hand leftHand = new SteamVR_Skeleton_Pose_Hand(SteamVR_Input_Sources.LeftHand);
  12. public SteamVR_Skeleton_Pose_Hand rightHand = new SteamVR_Skeleton_Pose_Hand(SteamVR_Input_Sources.RightHand);
  13. protected const int leftHandInputSource = (int)SteamVR_Input_Sources.LeftHand;
  14. protected const int rightHandInputSource = (int)SteamVR_Input_Sources.RightHand;
  15. public SteamVR_Skeleton_Pose_Hand GetHand(int hand)
  16. {
  17. if (hand == leftHandInputSource)
  18. return leftHand;
  19. else if (hand == rightHandInputSource)
  20. return rightHand;
  21. return null;
  22. }
  23. public SteamVR_Skeleton_Pose_Hand GetHand(SteamVR_Input_Sources hand)
  24. {
  25. if (hand == SteamVR_Input_Sources.LeftHand)
  26. return leftHand;
  27. else if (hand == SteamVR_Input_Sources.RightHand)
  28. return rightHand;
  29. return null;
  30. }
  31. }
  32. [Serializable]
  33. public class SteamVR_Skeleton_Pose_Hand
  34. {
  35. public SteamVR_Input_Sources inputSource;
  36. public SteamVR_Skeleton_FingerExtensionTypes thumbFingerMovementType = SteamVR_Skeleton_FingerExtensionTypes.Static;
  37. public SteamVR_Skeleton_FingerExtensionTypes indexFingerMovementType = SteamVR_Skeleton_FingerExtensionTypes.Static;
  38. public SteamVR_Skeleton_FingerExtensionTypes middleFingerMovementType = SteamVR_Skeleton_FingerExtensionTypes.Static;
  39. public SteamVR_Skeleton_FingerExtensionTypes ringFingerMovementType = SteamVR_Skeleton_FingerExtensionTypes.Static;
  40. public SteamVR_Skeleton_FingerExtensionTypes pinkyFingerMovementType = SteamVR_Skeleton_FingerExtensionTypes.Static;
  41. /// <summary>
  42. /// Get extension type for a particular finger. Thumb is 0, Index is 1, etc.
  43. /// </summary>
  44. public SteamVR_Skeleton_FingerExtensionTypes GetFingerExtensionType(int finger)
  45. {
  46. if (finger == 0)
  47. return thumbFingerMovementType;
  48. if (finger == 1)
  49. return indexFingerMovementType;
  50. if (finger == 2)
  51. return middleFingerMovementType;
  52. if (finger == 3)
  53. return ringFingerMovementType;
  54. if (finger == 4)
  55. return pinkyFingerMovementType;
  56. //default to static
  57. Debug.LogWarning("Finger not in range!");
  58. return SteamVR_Skeleton_FingerExtensionTypes.Static;
  59. }
  60. public bool ignoreRootPoseData = true;
  61. public bool ignoreWristPoseData = true;
  62. public Vector3 position;
  63. public Quaternion rotation;
  64. public Vector3[] bonePositions;
  65. public Quaternion[] boneRotations;
  66. public SteamVR_Skeleton_Pose_Hand(SteamVR_Input_Sources source)
  67. {
  68. inputSource = source;
  69. }
  70. public SteamVR_Skeleton_FingerExtensionTypes GetMovementTypeForBone(int boneIndex)
  71. {
  72. int fingerIndex = SteamVR_Skeleton_JointIndexes.GetFingerForBone(boneIndex);
  73. switch (fingerIndex)
  74. {
  75. case SteamVR_Skeleton_FingerIndexes.thumb:
  76. return thumbFingerMovementType;
  77. case SteamVR_Skeleton_FingerIndexes.index:
  78. return indexFingerMovementType;
  79. case SteamVR_Skeleton_FingerIndexes.middle:
  80. return middleFingerMovementType;
  81. case SteamVR_Skeleton_FingerIndexes.ring:
  82. return ringFingerMovementType;
  83. case SteamVR_Skeleton_FingerIndexes.pinky:
  84. return pinkyFingerMovementType;
  85. }
  86. return SteamVR_Skeleton_FingerExtensionTypes.Static;
  87. }
  88. }
  89. public enum SteamVR_Skeleton_FingerExtensionTypes
  90. {
  91. Static,
  92. Free,
  93. Extend,
  94. Contract,
  95. }
  96. public class SteamVR_Skeleton_FingerExtensionTypeLists
  97. {
  98. private SteamVR_Skeleton_FingerExtensionTypes[] _enumList;
  99. public SteamVR_Skeleton_FingerExtensionTypes[] enumList
  100. {
  101. get
  102. {
  103. if (_enumList == null)
  104. _enumList = (SteamVR_Skeleton_FingerExtensionTypes[])System.Enum.GetValues(typeof(SteamVR_Skeleton_FingerExtensionTypes));
  105. return _enumList;
  106. }
  107. }
  108. private string[] _stringList;
  109. public string[] stringList
  110. {
  111. get
  112. {
  113. if (_stringList == null)
  114. _stringList = enumList.Select(element => element.ToString()).ToArray();
  115. return _stringList;
  116. }
  117. }
  118. }
  119. }