1
0

SteamVR_Skeleton_Pose.cs 4.9 KB

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