1
0

SteamVR_Action_Skeleton.cs 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459
  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. using UnityEngine;
  3. using System.Collections;
  4. using System;
  5. using System.Runtime.InteropServices;
  6. using System.Collections.Generic;
  7. using System.Text;
  8. namespace Valve.VR
  9. {
  10. [Serializable]
  11. /// <summary>
  12. /// Skeleton Actions are our best approximation of where your hands are while holding vr controllers and pressing buttons. We give you 31 bones to help you animate hand models.
  13. /// For more information check out this blog post: https://steamcommunity.com/games/250820/announcements/detail/1690421280625220068
  14. /// </summary>
  15. public class SteamVR_Action_Skeleton : SteamVR_Action_Pose_Base<SteamVR_Action_Skeleton_Source_Map, SteamVR_Action_Skeleton_Source>, ISteamVR_Action_Skeleton_Source, ISerializationCallbackReceiver
  16. {
  17. public const int numBones = 31;
  18. public delegate void ActiveChangeHandler(SteamVR_Action_Skeleton fromAction, bool active);
  19. public delegate void ChangeHandler(SteamVR_Action_Skeleton fromAction);
  20. public delegate void UpdateHandler(SteamVR_Action_Skeleton fromAction);
  21. public delegate void TrackingChangeHandler(SteamVR_Action_Skeleton fromAction, ETrackingResult trackingState);
  22. public delegate void ValidPoseChangeHandler(SteamVR_Action_Skeleton fromAction, bool validPose);
  23. public delegate void DeviceConnectedChangeHandler(SteamVR_Action_Skeleton fromAction, bool deviceConnected);
  24. /// <summary>Event fires when the active state (ActionSet active and binding active) changes</summary>
  25. public event ActiveChangeHandler onActiveChange
  26. { add { sourceMap[SteamVR_Input_Sources.Any].onActiveChange += value; } remove { sourceMap[SteamVR_Input_Sources.Any].onActiveChange -= value; } }
  27. /// <summary>Event fires when the active state of the binding changes</summary>
  28. public event ActiveChangeHandler onActiveBindingChange
  29. { add { sourceMap[SteamVR_Input_Sources.Any].onActiveBindingChange += value; } remove { sourceMap[SteamVR_Input_Sources.Any].onActiveBindingChange -= value; } }
  30. /// <summary>Event fires when the state of the pose or bones moves more than the changeTolerance</summary>
  31. public event ChangeHandler onChange
  32. { add { sourceMap[SteamVR_Input_Sources.Any].onChange += value; } remove { sourceMap[SteamVR_Input_Sources.Any].onChange -= value; } }
  33. /// <summary>Event fires when the action is updated</summary>
  34. public event UpdateHandler onUpdate
  35. { add { sourceMap[SteamVR_Input_Sources.Any].onUpdate += value; } remove { sourceMap[SteamVR_Input_Sources.Any].onUpdate -= value; } }
  36. /// <summary>Event fires when the state of the tracking system that is used to create pose data (position, rotation, etc) changes</summary>
  37. public event TrackingChangeHandler onTrackingChanged
  38. { add { sourceMap[SteamVR_Input_Sources.Any].onTrackingChanged += value; } remove { sourceMap[SteamVR_Input_Sources.Any].onTrackingChanged -= value; } }
  39. /// <summary>Event fires when the state of the pose data retrieved for this action changes validity (good/bad data from the tracking source)</summary>
  40. public event ValidPoseChangeHandler onValidPoseChanged
  41. { add { sourceMap[SteamVR_Input_Sources.Any].onValidPoseChanged += value; } remove { sourceMap[SteamVR_Input_Sources.Any].onValidPoseChanged -= value; } }
  42. /// <summary>Event fires when the device bound to this action is connected or disconnected</summary>
  43. public event DeviceConnectedChangeHandler onDeviceConnectedChanged
  44. { add { sourceMap[SteamVR_Input_Sources.Any].onDeviceConnectedChanged += value; } remove { sourceMap[SteamVR_Input_Sources.Any].onDeviceConnectedChanged -= value; } }
  45. public SteamVR_Action_Skeleton() { }
  46. /// <summary>
  47. /// <strong>[Should not be called by user code]</strong>
  48. /// Updates the skeleton action data
  49. /// </summary>
  50. public virtual void UpdateValue(bool skipStateAndEventUpdates)
  51. {
  52. sourceMap[SteamVR_Input_Sources.Any].UpdateValue(skipStateAndEventUpdates);
  53. }
  54. /// <summary>
  55. /// <strong>[Should not be called by user code]</strong>
  56. /// Updates the skeleton action data without firing events
  57. /// </summary>
  58. public void UpdateValueWithoutEvents()
  59. {
  60. sourceMap[SteamVR_Input_Sources.Any].UpdateValue(true);
  61. }
  62. /// <summary>
  63. /// Update a transform's local position and local roation to match the pose from the most recent update
  64. /// </summary>
  65. /// <param name="transformToUpdate">The transform of the object to be updated</param>
  66. public void UpdateTransform(Transform transformToUpdate)
  67. {
  68. base.UpdateTransform(SteamVR_Input_Sources.Any, transformToUpdate);
  69. }
  70. #region skeleton source properties
  71. /// <summary>An array of the positions of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.</summary>
  72. public Vector3[] bonePositions { get { return sourceMap[SteamVR_Input_Sources.Any].bonePositions; } }
  73. /// <summary>An array of the rotations of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.</summary>
  74. public Quaternion[] boneRotations { get { return sourceMap[SteamVR_Input_Sources.Any].boneRotations; } }
  75. /// <summary>From the previous update: An array of the positions of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.</summary>
  76. public Vector3[] lastBonePositions { get { return sourceMap[SteamVR_Input_Sources.Any].lastBonePositions; } }
  77. /// <summary>From the previous update: An array of the rotations of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.</summary>
  78. public Quaternion[] lastBoneRotations { get { return sourceMap[SteamVR_Input_Sources.Any].lastBoneRotations; } }
  79. /// <summary>The range of motion the we're using to get bone data from. With Controller being your hand while holding the controller.</summary>
  80. public EVRSkeletalMotionRange rangeOfMotion
  81. {
  82. get { return sourceMap[SteamVR_Input_Sources.Any].rangeOfMotion; }
  83. set { sourceMap[SteamVR_Input_Sources.Any].rangeOfMotion = value; }
  84. }
  85. /// <summary>The space to get bone data in. Parent space by default</summary>
  86. public EVRSkeletalTransformSpace skeletalTransformSpace
  87. {
  88. get { return sourceMap[SteamVR_Input_Sources.Any].skeletalTransformSpace; }
  89. set { sourceMap[SteamVR_Input_Sources.Any].skeletalTransformSpace = value; }
  90. }
  91. /// <summary>The type of summary data that will be retrieved by default. FromAnimation is smoothed data to based on the skeletal animation system. FromDevice is as recent from the device as we can get - may be different data from smoothed. </summary>
  92. public EVRSummaryType summaryDataType
  93. {
  94. get { return sourceMap[SteamVR_Input_Sources.Any].summaryDataType; }
  95. set { sourceMap[SteamVR_Input_Sources.Any].summaryDataType = value; }
  96. }
  97. /// <summary>
  98. /// Get the accuracy level of the skeletal tracking data.
  99. /// <para/>* Estimated: Body part location can’t be directly determined by the device. Any skeletal pose provided by the device is estimated based on the active buttons, triggers, joysticks, or other input sensors. Examples include the Vive Controller and gamepads.
  100. /// <para/>* Partial: Body part location can be measured directly but with fewer degrees of freedom than the actual body part.Certain body part positions may be unmeasured by the device and estimated from other input data.Examples include Knuckles or gloves that only measure finger curl
  101. /// <para/>* Full: Body part location can be measured directly throughout the entire range of motion of the body part.Examples include hi-end mocap systems, or gloves that measure the rotation of each finger segment.
  102. /// </summary>
  103. public EVRSkeletalTrackingLevel skeletalTrackingLevel
  104. {
  105. get { return sourceMap[SteamVR_Input_Sources.Any].skeletalTrackingLevel; }
  106. }
  107. /// <summary>A 0-1 value representing how curled the thumb is. 0 being straight, 1 being fully curled.</summary>
  108. public float thumbCurl { get { return sourceMap[SteamVR_Input_Sources.Any].thumbCurl; } }
  109. /// <summary>A 0-1 value representing how curled the index finger is. 0 being straight, 1 being fully curled.</summary>
  110. public float indexCurl { get { return sourceMap[SteamVR_Input_Sources.Any].indexCurl; } }
  111. /// <summary>A 0-1 value representing how curled the middle finger is. 0 being straight, 1 being fully curled.</summary>
  112. public float middleCurl { get { return sourceMap[SteamVR_Input_Sources.Any].middleCurl; } }
  113. /// <summary>A 0-1 value representing how curled the ring finger is. 0 being straight, 1 being fully curled.</summary>
  114. public float ringCurl { get { return sourceMap[SteamVR_Input_Sources.Any].ringCurl; } }
  115. /// <summary>A 0-1 value representing how curled the pinky finger is. 0 being straight, 1 being fully curled.</summary>
  116. public float pinkyCurl { get { return sourceMap[SteamVR_Input_Sources.Any].pinkyCurl; } }
  117. /// <summary>A 0-1 value representing the size of the gap between the thumb and index fingers</summary>
  118. public float thumbIndexSplay { get { return sourceMap[SteamVR_Input_Sources.Any].thumbIndexSplay; } }
  119. /// <summary>A 0-1 value representing the size of the gap between the index and middle fingers</summary>
  120. public float indexMiddleSplay { get { return sourceMap[SteamVR_Input_Sources.Any].indexMiddleSplay; } }
  121. /// <summary>A 0-1 value representing the size of the gap between the middle and ring fingers</summary>
  122. public float middleRingSplay { get { return sourceMap[SteamVR_Input_Sources.Any].middleRingSplay; } }
  123. /// <summary>A 0-1 value representing the size of the gap between the ring and pinky fingers</summary>
  124. public float ringPinkySplay { get { return sourceMap[SteamVR_Input_Sources.Any].ringPinkySplay; } }
  125. /// <summary>[Previous Update] A 0-1 value representing how curled the thumb is. 0 being straight, 1 being fully curled.</summary>
  126. public float lastThumbCurl { get { return sourceMap[SteamVR_Input_Sources.Any].lastThumbCurl; } }
  127. /// <summary>[Previous Update] A 0-1 value representing how curled the index finger is. 0 being straight, 1 being fully curled.</summary>
  128. public float lastIndexCurl { get { return sourceMap[SteamVR_Input_Sources.Any].lastIndexCurl; } }
  129. /// <summary>[Previous Update] A 0-1 value representing how curled the middle finger is. 0 being straight, 1 being fully curled.</summary>
  130. public float lastMiddleCurl { get { return sourceMap[SteamVR_Input_Sources.Any].lastMiddleCurl; } }
  131. /// <summary>[Previous Update] A 0-1 value representing how curled the ring finger is. 0 being straight, 1 being fully curled.</summary>
  132. public float lastRingCurl { get { return sourceMap[SteamVR_Input_Sources.Any].lastRingCurl; } }
  133. /// <summary>[Previous Update] A 0-1 value representing how curled the pinky finger is. 0 being straight, 1 being fully curled.</summary>
  134. public float lastPinkyCurl { get { return sourceMap[SteamVR_Input_Sources.Any].lastPinkyCurl; } }
  135. /// <summary>[Previous Update] A 0-1 value representing the size of the gap between the thumb and index fingers</summary>
  136. public float lastThumbIndexSplay { get { return sourceMap[SteamVR_Input_Sources.Any].lastThumbIndexSplay; } }
  137. /// <summary>[Previous Update] A 0-1 value representing the size of the gap between the index and middle fingers</summary>
  138. public float lastIndexMiddleSplay { get { return sourceMap[SteamVR_Input_Sources.Any].lastIndexMiddleSplay; } }
  139. /// <summary>[Previous Update] A 0-1 value representing the size of the gap between the middle and ring fingers</summary>
  140. public float lastMiddleRingSplay { get { return sourceMap[SteamVR_Input_Sources.Any].lastMiddleRingSplay; } }
  141. /// <summary>[Previous Update] A 0-1 value representing the size of the gap between the ring and pinky fingers</summary>
  142. public float lastRingPinkySplay { get { return sourceMap[SteamVR_Input_Sources.Any].lastRingPinkySplay; } }
  143. /// <summary>0-1 values representing how curled the specified finger is. 0 being straight, 1 being fully curled. For indexes see: SteamVR_Skeleton_FingerIndexes</summary>
  144. public float[] fingerCurls { get { return sourceMap[SteamVR_Input_Sources.Any].fingerCurls; } }
  145. /// <summary>0-1 values representing how splayed the specified finger and it's next index'd finger is. For indexes see: SteamVR_Skeleton_FingerIndexes</summary>
  146. public float[] fingerSplays { get { return sourceMap[SteamVR_Input_Sources.Any].fingerSplays; } }
  147. /// <summary>[Previous Update] 0-1 values representing how curled the specified finger is. 0 being straight, 1 being fully curled. For indexes see: SteamVR_Skeleton_FingerIndexes</summary>
  148. public float[] lastFingerCurls { get { return sourceMap[SteamVR_Input_Sources.Any].lastFingerCurls; } }
  149. /// <summary>[Previous Update] 0-1 values representing how splayed the specified finger and it's next index'd finger is. For indexes see: SteamVR_Skeleton_FingerIndexes</summary>
  150. public float[] lastFingerSplays { get { return sourceMap[SteamVR_Input_Sources.Any].lastFingerSplays; } }
  151. /// <summary>Separate from "changed". If the pose for this skeleton action has changed (root position/rotation)</summary>
  152. public bool poseChanged { get { return sourceMap[SteamVR_Input_Sources.Any].poseChanged; } }
  153. /// <summary>Skips processing the full per bone data and only does the summary data</summary>
  154. public bool onlyUpdateSummaryData { get { return sourceMap[SteamVR_Input_Sources.Any].onlyUpdateSummaryData; } set { sourceMap[SteamVR_Input_Sources.Any].onlyUpdateSummaryData = value; } }
  155. #endregion
  156. #region pose functions with SteamVR_Input_Sources.Any
  157. /// <summary>True if this action is bound and the ActionSet is active</summary>
  158. public bool GetActive()
  159. {
  160. return sourceMap[SteamVR_Input_Sources.Any].active;
  161. }
  162. /// <summary>True if the ActionSet that contains this action is active</summary>
  163. public bool GetSetActive()
  164. {
  165. return actionSet.IsActive(SteamVR_Input_Sources.Any);
  166. }
  167. /// <summary>
  168. /// SteamVR keeps a log of past poses so you can retrieve old poses or estimated poses in the future by passing in a secondsFromNow value that is negative or positive.
  169. /// </summary>
  170. /// <param name="secondsFromNow">The time offset in the future (estimated) or in the past (previously recorded) you want to get data from</param>
  171. /// <returns>true if we successfully returned a pose</returns>
  172. public bool GetVelocitiesAtTimeOffset(float secondsFromNow, out Vector3 velocity, out Vector3 angularVelocity)
  173. {
  174. return sourceMap[SteamVR_Input_Sources.Any].GetVelocitiesAtTimeOffset(secondsFromNow, out velocity, out angularVelocity);
  175. }
  176. /// <summary>
  177. /// SteamVR keeps a log of past poses so you can retrieve old poses or estimated poses in the future by passing in a secondsFromNow value that is negative or positive.
  178. /// </summary>
  179. /// <param name="secondsFromNow">The time offset in the future (estimated) or in the past (previously recorded) you want to get data from</param>
  180. /// <returns>true if we successfully returned a pose</returns>
  181. public bool GetPoseAtTimeOffset(float secondsFromNow, out Vector3 position, out Quaternion rotation, out Vector3 velocity, out Vector3 angularVelocity)
  182. {
  183. return sourceMap[SteamVR_Input_Sources.Any].GetPoseAtTimeOffset(secondsFromNow, out position, out rotation, out velocity, out angularVelocity);
  184. }
  185. /// <summary>The local position of the pose relative to the universe origin</summary>
  186. public Vector3 GetLocalPosition()
  187. {
  188. return sourceMap[SteamVR_Input_Sources.Any].localPosition;
  189. }
  190. /// <summary>The local rotation of the pose relative to the universe origin</summary>
  191. public Quaternion GetLocalRotation()
  192. {
  193. return sourceMap[SteamVR_Input_Sources.Any].localRotation;
  194. }
  195. /// <summary>The local velocity of the pose relative to the universe origin</summary>
  196. public Vector3 GetVelocity()
  197. {
  198. return sourceMap[SteamVR_Input_Sources.Any].velocity;
  199. }
  200. /// <summary>The local angular velocity of the pose relative to the universe origin</summary>
  201. public Vector3 GetAngularVelocity()
  202. {
  203. return sourceMap[SteamVR_Input_Sources.Any].angularVelocity;
  204. }
  205. /// <summary>True if the device bound to this action is connected</summary>
  206. public bool GetDeviceIsConnected()
  207. {
  208. return sourceMap[SteamVR_Input_Sources.Any].deviceIsConnected;
  209. }
  210. /// <summary>True if the pose retrieved for this action is valid (good data from the tracking source)</summary>
  211. public bool GetPoseIsValid()
  212. {
  213. return sourceMap[SteamVR_Input_Sources.Any].poseIsValid;
  214. }
  215. /// <summary>The state of the tracking system that is used to create pose data (position, rotation, etc)</summary>
  216. public ETrackingResult GetTrackingResult()
  217. {
  218. return sourceMap[SteamVR_Input_Sources.Any].trackingState;
  219. }
  220. /// <summary>The last local position of the pose relative to the universe origin</summary>
  221. public Vector3 GetLastLocalPosition()
  222. {
  223. return sourceMap[SteamVR_Input_Sources.Any].lastLocalPosition;
  224. }
  225. /// <summary>The last local rotation of the pose relative to the universe origin</summary>
  226. public Quaternion GetLastLocalRotation()
  227. {
  228. return sourceMap[SteamVR_Input_Sources.Any].lastLocalRotation;
  229. }
  230. /// <summary>The last local velocity of the pose relative to the universe origin</summary>
  231. public Vector3 GetLastVelocity()
  232. {
  233. return sourceMap[SteamVR_Input_Sources.Any].lastVelocity;
  234. }
  235. /// <summary>The last local angular velocity of the pose relative to the universe origin</summary>
  236. public Vector3 GetLastAngularVelocity()
  237. {
  238. return sourceMap[SteamVR_Input_Sources.Any].lastAngularVelocity;
  239. }
  240. /// <summary>True if the device bound to this action was connected during the previous update</summary>
  241. public bool GetLastDeviceIsConnected()
  242. {
  243. return sourceMap[SteamVR_Input_Sources.Any].lastDeviceIsConnected;
  244. }
  245. /// <summary>True if the pose was valid during the previous update</summary>
  246. public bool GetLastPoseIsValid()
  247. {
  248. return sourceMap[SteamVR_Input_Sources.Any].lastPoseIsValid;
  249. }
  250. /// <summary>The tracking state for this pose during the previous update</summary>
  251. public ETrackingResult GetLastTrackingResult()
  252. {
  253. return sourceMap[SteamVR_Input_Sources.Any].lastTrackingState;
  254. }
  255. #endregion
  256. /// <summary>
  257. /// The number of bones in the skeleton for this action
  258. /// </summary>
  259. public int boneCount { get { return (int)GetBoneCount(); } }
  260. /// <summary>
  261. /// Gets the bone positions in local space. This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
  262. /// </summary>
  263. /// <param name="copy">This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array</param>
  264. public Vector3[] GetBonePositions(bool copy = false)
  265. {
  266. if (copy)
  267. return (Vector3[])sourceMap[SteamVR_Input_Sources.Any].bonePositions.Clone();
  268. return sourceMap[SteamVR_Input_Sources.Any].bonePositions;
  269. }
  270. /// <summary>
  271. /// Gets the bone rotations in local space. This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
  272. /// </summary>
  273. /// <param name="copy">This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array</param>
  274. public Quaternion[] GetBoneRotations(bool copy = false)
  275. {
  276. if (copy)
  277. return (Quaternion[])sourceMap[SteamVR_Input_Sources.Any].boneRotations.Clone();
  278. return sourceMap[SteamVR_Input_Sources.Any].boneRotations;
  279. }
  280. /// <summary>
  281. /// Gets the bone positions in local space from the previous update. This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
  282. /// </summary>
  283. /// <param name="copy">This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array</param>
  284. public Vector3[] GetLastBonePositions(bool copy = false)
  285. {
  286. if (copy)
  287. return (Vector3[])sourceMap[SteamVR_Input_Sources.Any].lastBonePositions.Clone();
  288. return sourceMap[SteamVR_Input_Sources.Any].lastBonePositions;
  289. }
  290. /// <summary>
  291. /// Gets the bone rotations in local space from the previous update. This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
  292. /// </summary>
  293. /// <param name="copy">This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array</param>
  294. public Quaternion[] GetLastBoneRotations(bool copy = false)
  295. {
  296. if (copy)
  297. return (Quaternion[])sourceMap[SteamVR_Input_Sources.Any].lastBoneRotations.Clone();
  298. return sourceMap[SteamVR_Input_Sources.Any].lastBoneRotations;
  299. }
  300. /// <summary>
  301. /// Set the range of the motion of the bones in this skeleton. Options are "With Controller" as if your hand is holding your VR controller.
  302. /// Or "Without Controller" as if your hand is empty. This will set the range for the following update.
  303. /// </summary>
  304. public void SetRangeOfMotion(EVRSkeletalMotionRange range)
  305. {
  306. sourceMap[SteamVR_Input_Sources.Any].rangeOfMotion = range;
  307. }
  308. /// <summary>
  309. /// Sets the space that you'll get bone data back in. Options are relative to the Model and relative to the Parent bone
  310. /// </summary>
  311. /// <param name="space">the space that you'll get bone data back in. Options are relative to the Model and relative to the Parent bone.</param>
  312. public void SetSkeletalTransformSpace(EVRSkeletalTransformSpace space)
  313. {
  314. sourceMap[SteamVR_Input_Sources.Any].skeletalTransformSpace = space;
  315. }
  316. /// <summary>
  317. /// Returns the total number of bones in the skeleton
  318. /// </summary>
  319. public uint GetBoneCount()
  320. {
  321. return sourceMap[SteamVR_Input_Sources.Any].GetBoneCount();
  322. }
  323. /// <summary>
  324. /// Returns the order of bones in the hierarchy
  325. /// </summary>
  326. public int[] GetBoneHierarchy()
  327. {
  328. return sourceMap[SteamVR_Input_Sources.Any].GetBoneHierarchy();
  329. }
  330. /// <summary>
  331. /// Returns the name of the bone
  332. /// </summary>
  333. public string GetBoneName(int boneIndex)
  334. {
  335. return sourceMap[SteamVR_Input_Sources.Any].GetBoneName(boneIndex);
  336. }
  337. /// <summary>
  338. /// Returns an array of positions/rotations that represent the state of each bone in a reference pose.
  339. /// </summary>
  340. /// <param name="transformSpace">What to get the position/rotation data relative to, the model, or the bone's parent</param>
  341. /// <param name="referencePose">Which reference pose to return</param>
  342. /// <returns></returns>
  343. public SteamVR_Utils.RigidTransform[] GetReferenceTransforms(EVRSkeletalTransformSpace transformSpace, EVRSkeletalReferencePose referencePose)
  344. {
  345. return sourceMap[SteamVR_Input_Sources.Any].GetReferenceTransforms(transformSpace, referencePose);
  346. }
  347. /// <summary>
  348. /// Get the accuracy level of the skeletal tracking data.
  349. /// </summary>
  350. /// <returns>
  351. /// <list type="bullet">
  352. /// <item><description>Estimated: Body part location can’t be directly determined by the device. Any skeletal pose provided by the device is estimated based on the active buttons, triggers, joysticks, or other input sensors. Examples include the Vive Controller and gamepads. </description></item>
  353. /// <item><description>Partial: Body part location can be measured directly but with fewer degrees of freedom than the actual body part.Certain body part positions may be unmeasured by the device and estimated from other input data.Examples include Knuckles or gloves that only measure finger curl</description></item>
  354. /// <item><description>Full: Body part location can be measured directly throughout the entire range of motion of the body part.Examples include hi-end mocap systems, or gloves that measure the rotation of each finger segment.</description></item>
  355. /// </list>
  356. /// </returns>
  357. public EVRSkeletalTrackingLevel GetSkeletalTrackingLevel()
  358. {
  359. return sourceMap[SteamVR_Input_Sources.Any].GetSkeletalTrackingLevel();
  360. }
  361. /// <summary>
  362. /// Returns the finger curl data that we calculate each update. This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
  363. /// </summary>
  364. /// <param name="copy">This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array</param>
  365. public float[] GetFingerCurls(bool copy = false)
  366. {
  367. if (copy)
  368. return (float[])sourceMap[SteamVR_Input_Sources.Any].fingerCurls.Clone();
  369. else
  370. return sourceMap[SteamVR_Input_Sources.Any].fingerCurls;
  371. }
  372. /// <summary>
  373. /// Returns the finger curl data from the previous update. This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
  374. /// </summary>
  375. /// <param name="copy">This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array</param>
  376. public float[] GetLastFingerCurls(bool copy = false)
  377. {
  378. if (copy)
  379. return (float[])sourceMap[SteamVR_Input_Sources.Any].lastFingerCurls.Clone();
  380. else
  381. return sourceMap[SteamVR_Input_Sources.Any].lastFingerCurls;
  382. }
  383. /// <summary>
  384. /// Returns the finger splay data that we calculate each update. This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
  385. /// </summary>
  386. /// <param name="copy">This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array</param>
  387. public float[] GetFingerSplays(bool copy = false)
  388. {
  389. if (copy)
  390. return (float[])sourceMap[SteamVR_Input_Sources.Any].fingerSplays.Clone();
  391. else
  392. return sourceMap[SteamVR_Input_Sources.Any].fingerSplays;
  393. }
  394. /// <summary>
  395. /// Returns the finger splay data from the previous update. This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
  396. /// </summary>
  397. /// <param name="copy">This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array</param>
  398. public float[] GetLastFingerSplays(bool copy = false)
  399. {
  400. if (copy)
  401. return (float[])sourceMap[SteamVR_Input_Sources.Any].lastFingerSplays.Clone();
  402. else
  403. return sourceMap[SteamVR_Input_Sources.Any].lastFingerSplays;
  404. }
  405. /// <summary>
  406. /// Returns a value indicating how much the passed in finger is currently curled.
  407. /// </summary>
  408. /// <param name="finger">The index of the finger to return a curl value for. 0-4. thumb, index, middle, ring, pinky</param>
  409. /// <returns>0-1 value. 0 being straight, 1 being fully curled.</returns>
  410. public float GetFingerCurl(int finger)
  411. {
  412. return sourceMap[SteamVR_Input_Sources.Any].fingerCurls[finger];
  413. }
  414. /// <summary>
  415. /// Returns a value indicating how the size of the gap between fingers.
  416. /// </summary>
  417. /// <param name="fingerGapIndex">The index of the finger gap to return a splay value for. 0 being the gap between thumb and index, 1 being the gap between index and middle, 2 being the gap between middle and ring, and 3 being the gap between ring and pinky.</param>
  418. /// <returns>0-1 value. 0 being no gap, 1 being "full" gap</returns>
  419. public float GetSplay(int fingerGapIndex)
  420. {
  421. return sourceMap[SteamVR_Input_Sources.Any].fingerSplays[fingerGapIndex];
  422. }
  423. /// <summary>
  424. /// Returns a value indicating how much the passed in finger is currently curled.
  425. /// </summary>
  426. /// <param name="finger">The finger to return a curl value for</param>
  427. /// <returns>0-1 value. 0 being straight, 1 being fully curled.</returns>
  428. public float GetFingerCurl(SteamVR_Skeleton_FingerIndexEnum finger)
  429. {
  430. return GetFingerCurl((int)finger);
  431. }
  432. /// <summary>
  433. /// Returns a value indicating how the size of the gap between fingers.
  434. /// </summary>
  435. /// <param name="fingerGapIndex">The finger gap to return a splay value for.</param>
  436. /// <returns>0-1 value. 0 being no gap, 1 being "full" gap</returns>
  437. public float GetSplay(SteamVR_Skeleton_FingerSplayIndexEnum fingerSplay)
  438. {
  439. return GetSplay((int)fingerSplay);
  440. }
  441. /// <summary>
  442. /// Returns a value indicating how much the passed in finger was curled during the previous update
  443. /// </summary>
  444. /// <param name="finger">The index of the finger to return a curl value for. 0-4. thumb, index, middle, ring, pinky</param>
  445. /// <returns>0-1 value. 0 being straight, 1 being fully curled.</returns>
  446. public float GetLastFingerCurl(int finger)
  447. {
  448. return sourceMap[SteamVR_Input_Sources.Any].lastFingerCurls[finger];
  449. }
  450. /// <summary>
  451. /// Returns a value indicating the size of the gap between fingers during the previous update
  452. /// </summary>
  453. /// <param name="fingerGapIndex">The index of the finger gap to return a splay value for. 0 being the gap between thumb and index, 1 being the gap between index and middle, 2 being the gap between middle and ring, and 3 being the gap between ring and pinky.</param>
  454. /// <returns>0-1 value. 0 being no gap, 1 being "full" gap</returns>
  455. public float GetLastSplay(int fingerGapIndex)
  456. {
  457. return sourceMap[SteamVR_Input_Sources.Any].lastFingerSplays[fingerGapIndex];
  458. }
  459. /// <summary>
  460. /// Returns a value indicating how much the passed in finger was curled during the previous update
  461. /// </summary>
  462. /// <param name="finger">The finger to return a curl value for</param>
  463. /// <returns>0-1 value. 0 being straight, 1 being fully curled.</returns>
  464. public float GetLastFingerCurl(SteamVR_Skeleton_FingerIndexEnum finger)
  465. {
  466. return GetLastFingerCurl((int)finger);
  467. }
  468. /// <summary>
  469. /// Returns a value indicating the size of the gap between fingers during the previous update
  470. /// </summary>
  471. /// <param name="fingerGapIndex">The finger gap to return a splay value for. </param>
  472. /// <returns>0-1 value. 0 being no gap, 1 being "full" gap</returns>
  473. public float GetLastSplay(SteamVR_Skeleton_FingerSplayIndexEnum fingerSplay)
  474. {
  475. return GetLastSplay((int)fingerSplay);
  476. }
  477. /// <summary>
  478. /// Gets the localized name of the device that the action corresponds to. Include as many EVRInputStringBits as you want to add to the localized string
  479. /// </summary>
  480. /// <param name="localizedParts">
  481. /// <list type="bullet">
  482. /// <item><description>VRInputString_Hand - Which hand the origin is in. ex: "Left Hand". </description></item>
  483. /// <item><description>VRInputString_ControllerType - What kind of controller the user has in that hand. ex: "Vive Controller". </description></item>
  484. /// <item><description>VRInputString_InputSource - What part of that controller is the origin. ex: "Trackpad". </description></item>
  485. /// <item><description>VRInputString_All - All of the above. ex: "Left Hand Vive Controller Trackpad". </description></item>
  486. /// </list>
  487. /// </param>
  488. public string GetLocalizedName(params EVRInputStringBits[] localizedParts)
  489. {
  490. return sourceMap[SteamVR_Input_Sources.Any].GetLocalizedOriginPart(localizedParts);
  491. }
  492. /// <summary>Fires an event when a device is connected or disconnected.</summary>
  493. /// <param name="functionToCall">The method you would like to be called when a device is connected. Should take a SteamVR_Action_Pose as a param</param>
  494. public void AddOnDeviceConnectedChanged(DeviceConnectedChangeHandler functionToCall)
  495. {
  496. sourceMap[SteamVR_Input_Sources.Any].onDeviceConnectedChanged += functionToCall;
  497. }
  498. /// <summary>Stops executing the function setup by the corresponding AddListener</summary>
  499. /// <param name="functionToStopCalling">The method you would like to stop calling when a device is connected. Should take a SteamVR_Action_Pose as a param</param>
  500. public void RemoveOnDeviceConnectedChanged(DeviceConnectedChangeHandler functionToStopCalling)
  501. {
  502. sourceMap[SteamVR_Input_Sources.Any].onDeviceConnectedChanged -= functionToStopCalling;
  503. }
  504. /// <summary>Fires an event when the tracking of the device has changed</summary>
  505. /// <param name="functionToCall">The method you would like to be called when tracking has changed. Should take a SteamVR_Action_Pose as a param</param>
  506. public void AddOnTrackingChanged(TrackingChangeHandler functionToCall)
  507. {
  508. sourceMap[SteamVR_Input_Sources.Any].onTrackingChanged += functionToCall;
  509. }
  510. /// <summary>Stops executing the function setup by the corresponding AddListener</summary>
  511. /// <param name="functionToStopCalling">The method you would like to stop calling when tracking has changed. Should take a SteamVR_Action_Pose as a param</param>
  512. public void RemoveOnTrackingChanged(TrackingChangeHandler functionToStopCalling)
  513. {
  514. sourceMap[SteamVR_Input_Sources.Any].onTrackingChanged -= functionToStopCalling;
  515. }
  516. /// <summary>Fires an event when the device now has a valid pose or no longer has a valid pose</summary>
  517. /// <param name="functionToCall">The method you would like to be called when the pose has become valid or invalid. Should take a SteamVR_Action_Pose as a param</param>
  518. public void AddOnValidPoseChanged(ValidPoseChangeHandler functionToCall)
  519. {
  520. sourceMap[SteamVR_Input_Sources.Any].onValidPoseChanged += functionToCall;
  521. }
  522. /// <summary>Stops executing the function setup by the corresponding AddListener</summary>
  523. /// <param name="functionToStopCalling">The method you would like to stop calling when the pose has become valid or invalid. Should take a SteamVR_Action_Pose as a param</param>
  524. public void RemoveOnValidPoseChanged(ValidPoseChangeHandler functionToStopCalling)
  525. {
  526. sourceMap[SteamVR_Input_Sources.Any].onValidPoseChanged -= functionToStopCalling;
  527. }
  528. /// <summary>Executes a function when this action's bound state changes</summary>
  529. public void AddOnActiveChangeListener(ActiveChangeHandler functionToCall)
  530. {
  531. sourceMap[SteamVR_Input_Sources.Any].onActiveChange += functionToCall;
  532. }
  533. /// <summary>Stops executing the function setup by the corresponding AddListener</summary>
  534. /// <param name="functionToStopCalling">The local function that you've setup to receive update events</param>
  535. public void RemoveOnActiveChangeListener(ActiveChangeHandler functionToStopCalling)
  536. {
  537. sourceMap[SteamVR_Input_Sources.Any].onActiveChange -= functionToStopCalling;
  538. }
  539. /// <summary>Executes a function when the state of this action changes</summary>
  540. /// <param name="functionToCall">A local function that receives the boolean action who's state has changed, the corresponding input source, and the new value</param>
  541. public void AddOnChangeListener(ChangeHandler functionToCall)
  542. {
  543. sourceMap[SteamVR_Input_Sources.Any].onChange += functionToCall;
  544. }
  545. /// <summary>Stops executing the function setup by the corresponding AddListener</summary>
  546. /// <param name="functionToStopCalling">The local function that you've setup to receive on change events</param>
  547. public void RemoveOnChangeListener(ChangeHandler functionToStopCalling)
  548. {
  549. sourceMap[SteamVR_Input_Sources.Any].onChange -= functionToStopCalling;
  550. }
  551. /// <summary>Executes a function when the state of this action is updated.</summary>
  552. /// <param name="functionToCall">A local function that receives the boolean action who's state has changed, the corresponding input source, and the new value</param>
  553. public void AddOnUpdateListener(UpdateHandler functionToCall)
  554. {
  555. sourceMap[SteamVR_Input_Sources.Any].onUpdate += functionToCall;
  556. }
  557. /// <summary>Stops executing the function setup by the corresponding AddListener</summary>
  558. /// <param name="functionToStopCalling">The local function that you've setup to receive update events</param>
  559. public void RemoveOnUpdateListener(UpdateHandler functionToStopCalling)
  560. {
  561. sourceMap[SteamVR_Input_Sources.Any].onUpdate -= functionToStopCalling;
  562. }
  563. void ISerializationCallbackReceiver.OnBeforeSerialize()
  564. {
  565. }
  566. void ISerializationCallbackReceiver.OnAfterDeserialize()
  567. {
  568. InitAfterDeserialize();
  569. }
  570. public static Quaternion steamVRFixUpRotation = Quaternion.AngleAxis(Mathf.PI * Mathf.Rad2Deg, Vector3.up);
  571. }
  572. public class SteamVR_Action_Skeleton_Source_Map : SteamVR_Action_Pose_Source_Map<SteamVR_Action_Skeleton_Source>
  573. {
  574. protected override SteamVR_Action_Skeleton_Source GetSourceElementForIndexer(SteamVR_Input_Sources inputSource)
  575. {
  576. return sources[0]; //just in case somebody tries to access a different element, redirect them to the correct one.
  577. }
  578. }
  579. /// <summary>
  580. /// Skeleton Actions are our best approximation of where your hands are while holding vr controllers and pressing buttons. We give you 31 bones to help you animate hand models.
  581. /// For more information check out this blog post: https://steamcommunity.com/games/250820/announcements/detail/1690421280625220068
  582. /// </summary>
  583. public class SteamVR_Action_Skeleton_Source : SteamVR_Action_Pose_Source, ISteamVR_Action_Skeleton_Source
  584. {
  585. protected static uint skeletonActionData_size = 0;
  586. /// <summary>Event fires when the active state (ActionSet active and binding active) changes</summary>
  587. public new event SteamVR_Action_Skeleton.ActiveChangeHandler onActiveChange;
  588. /// <summary>Event fires when the active state of the binding changes</summary>
  589. public new event SteamVR_Action_Skeleton.ActiveChangeHandler onActiveBindingChange;
  590. /// <summary>Event fires when the orientation of the pose or bones changes more than the changeTolerance</summary>
  591. public new event SteamVR_Action_Skeleton.ChangeHandler onChange;
  592. /// <summary>Event fires when the action is updated</summary>
  593. public new event SteamVR_Action_Skeleton.UpdateHandler onUpdate;
  594. /// <summary>Event fires when the state of the tracking system that is used to create pose data (position, rotation, etc) changes</summary>
  595. public new event SteamVR_Action_Skeleton.TrackingChangeHandler onTrackingChanged;
  596. /// <summary>Event fires when the state of the pose data retrieved for this action changes validity (good/bad data from the tracking source)</summary>
  597. public new event SteamVR_Action_Skeleton.ValidPoseChangeHandler onValidPoseChanged;
  598. /// <summary>Event fires when the device bound to this action is connected or disconnected</summary>
  599. public new event SteamVR_Action_Skeleton.DeviceConnectedChangeHandler onDeviceConnectedChanged;
  600. /// <summary>True if the action is bound</summary>
  601. public override bool activeBinding { get { return skeletonActionData.bActive; } }
  602. /// <summary>True if the action's binding was active during the previous update</summary>
  603. public override bool lastActiveBinding { get { return lastSkeletonActionData.bActive; } }
  604. /// <summary>An array of the positions of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.</summary>
  605. public Vector3[] bonePositions { get; protected set; }
  606. /// <summary>An array of the rotations of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.</summary>
  607. public Quaternion[] boneRotations { get; protected set; }
  608. /// <summary>From the previous update: An array of the positions of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.</summary>
  609. public Vector3[] lastBonePositions { get; protected set; }
  610. /// <summary>From the previous update: An array of the rotations of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.</summary>
  611. public Quaternion[] lastBoneRotations { get; protected set; }
  612. /// <summary>The range of motion the we're using to get bone data from. With Controller being your hand while holding the controller.</summary>
  613. public EVRSkeletalMotionRange rangeOfMotion { get; set; }
  614. /// <summary>The space to get bone data in. Parent space by default</summary>
  615. public EVRSkeletalTransformSpace skeletalTransformSpace { get; set; }
  616. /// <summary>The type of summary data that will be retrieved by default. FromAnimation is smoothed data to based on the skeletal animation system. FromDevice is as recent from the device as we can get - may be different data from smoothed. </summary>
  617. public EVRSummaryType summaryDataType { get; set; }
  618. /// <summary>A 0-1 value representing how curled the thumb is. 0 being straight, 1 being fully curled.</summary>
  619. public float thumbCurl { get { return fingerCurls[SteamVR_Skeleton_FingerIndexes.thumb]; } }
  620. /// <summary>A 0-1 value representing how curled the index finger is. 0 being straight, 1 being fully curled.</summary>
  621. public float indexCurl { get { return fingerCurls[SteamVR_Skeleton_FingerIndexes.index]; } }
  622. /// <summary>A 0-1 value representing how curled the middle finger is. 0 being straight, 1 being fully curled.</summary>
  623. public float middleCurl { get { return fingerCurls[SteamVR_Skeleton_FingerIndexes.middle]; } }
  624. /// <summary>A 0-1 value representing how curled the ring finger is. 0 being straight, 1 being fully curled.</summary>
  625. public float ringCurl { get { return fingerCurls[SteamVR_Skeleton_FingerIndexes.ring]; } }
  626. /// <summary>A 0-1 value representing how curled the pinky finger is. 0 being straight, 1 being fully curled.</summary>
  627. public float pinkyCurl { get { return fingerCurls[SteamVR_Skeleton_FingerIndexes.pinky]; } }
  628. /// <summary>A 0-1 value representing the size of the gap between the thumb and index fingers</summary>
  629. public float thumbIndexSplay { get { return fingerSplays[SteamVR_Skeleton_FingerSplayIndexes.thumbIndex]; } }
  630. /// <summary>A 0-1 value representing the size of the gap between the index and middle fingers</summary>
  631. public float indexMiddleSplay { get { return fingerSplays[SteamVR_Skeleton_FingerSplayIndexes.indexMiddle]; } }
  632. /// <summary>A 0-1 value representing the size of the gap between the middle and ring fingers</summary>
  633. public float middleRingSplay { get { return fingerSplays[SteamVR_Skeleton_FingerSplayIndexes.middleRing]; } }
  634. /// <summary>A 0-1 value representing the size of the gap between the ring and pinky fingers</summary>
  635. public float ringPinkySplay { get { return fingerSplays[SteamVR_Skeleton_FingerSplayIndexes.ringPinky]; } }
  636. /// <summary>[Previous Update] A 0-1 value representing how curled the thumb is. 0 being straight, 1 being fully curled.</summary>
  637. public float lastThumbCurl { get { return lastFingerCurls[SteamVR_Skeleton_FingerIndexes.thumb]; } }
  638. /// <summary>[Previous Update] A 0-1 value representing how curled the index finger is. 0 being straight, 1 being fully curled.</summary>
  639. public float lastIndexCurl { get { return lastFingerCurls[SteamVR_Skeleton_FingerIndexes.index]; } }
  640. /// <summary>[Previous Update] A 0-1 value representing how curled the middle finger is. 0 being straight, 1 being fully curled.</summary>
  641. public float lastMiddleCurl { get { return lastFingerCurls[SteamVR_Skeleton_FingerIndexes.middle]; } }
  642. /// <summary>[Previous Update] A 0-1 value representing how curled the ring finger is. 0 being straight, 1 being fully curled.</summary>
  643. public float lastRingCurl { get { return lastFingerCurls[SteamVR_Skeleton_FingerIndexes.ring]; } }
  644. /// <summary>[Previous Update] A 0-1 value representing how curled the pinky finger is. 0 being straight, 1 being fully curled.</summary>
  645. public float lastPinkyCurl { get { return lastFingerCurls[SteamVR_Skeleton_FingerIndexes.pinky]; } }
  646. /// <summary>[Previous Update] A 0-1 value representing the size of the gap between the thumb and index fingers</summary>
  647. public float lastThumbIndexSplay { get { return lastFingerSplays[SteamVR_Skeleton_FingerSplayIndexes.thumbIndex]; } }
  648. /// <summary>[Previous Update] A 0-1 value representing the size of the gap between the index and middle fingers</summary>
  649. public float lastIndexMiddleSplay { get { return lastFingerSplays[SteamVR_Skeleton_FingerSplayIndexes.indexMiddle]; } }
  650. /// <summary>[Previous Update] A 0-1 value representing the size of the gap between the middle and ring fingers</summary>
  651. public float lastMiddleRingSplay { get { return lastFingerSplays[SteamVR_Skeleton_FingerSplayIndexes.middleRing]; } }
  652. /// <summary>[Previous Update] A 0-1 value representing the size of the gap between the ring and pinky fingers</summary>
  653. public float lastRingPinkySplay { get { return lastFingerSplays[SteamVR_Skeleton_FingerSplayIndexes.ringPinky]; } }
  654. /// <summary>0-1 values representing how curled the specified finger is. 0 being straight, 1 being fully curled. For indexes see: SteamVR_Skeleton_FingerIndexes</summary>
  655. public float[] fingerCurls { get; protected set; }
  656. /// <summary>0-1 values representing how splayed the specified finger and it's next index'd finger is. For indexes see: SteamVR_Skeleton_FingerIndexes</summary>
  657. public float[] fingerSplays { get; protected set; }
  658. /// <summary>[Previous Update] 0-1 values representing how curled the specified finger is. 0 being straight, 1 being fully curled. For indexes see: SteamVR_Skeleton_FingerIndexes</summary>
  659. public float[] lastFingerCurls { get; protected set; }
  660. /// <summary>[Previous Update] 0-1 values representing how splayed the specified finger and it's next index'd finger is. For indexes see: SteamVR_Skeleton_FingerIndexes</summary>
  661. public float[] lastFingerSplays { get; protected set; }
  662. /// <summary>Separate from "changed". If the pose for this skeleton action has changed (root position/rotation)</summary>
  663. public bool poseChanged { get; protected set; }
  664. /// <summary>Skips processing the full per bone data and only does the summary data</summary>
  665. public bool onlyUpdateSummaryData { get; set; }
  666. protected VRSkeletalSummaryData_t skeletalSummaryData = new VRSkeletalSummaryData_t();
  667. protected VRSkeletalSummaryData_t lastSkeletalSummaryData = new VRSkeletalSummaryData_t();
  668. protected SteamVR_Action_Skeleton skeletonAction;
  669. protected VRBoneTransform_t[] tempBoneTransforms = new VRBoneTransform_t[SteamVR_Action_Skeleton.numBones];
  670. protected InputSkeletalActionData_t skeletonActionData = new InputSkeletalActionData_t();
  671. protected InputSkeletalActionData_t lastSkeletonActionData = new InputSkeletalActionData_t();
  672. protected InputSkeletalActionData_t tempSkeletonActionData = new InputSkeletalActionData_t();
  673. public override void Preinitialize(SteamVR_Action wrappingAction, SteamVR_Input_Sources forInputSource)
  674. {
  675. base.Preinitialize(wrappingAction, forInputSource);
  676. skeletonAction = (SteamVR_Action_Skeleton)wrappingAction;
  677. bonePositions = new Vector3[SteamVR_Action_Skeleton.numBones];
  678. lastBonePositions = new Vector3[SteamVR_Action_Skeleton.numBones];
  679. boneRotations = new Quaternion[SteamVR_Action_Skeleton.numBones];
  680. lastBoneRotations = new Quaternion[SteamVR_Action_Skeleton.numBones];
  681. rangeOfMotion = EVRSkeletalMotionRange.WithController;
  682. skeletalTransformSpace = EVRSkeletalTransformSpace.Parent;
  683. fingerCurls = new float[SteamVR_Skeleton_FingerIndexes.enumArray.Length];
  684. fingerSplays = new float[SteamVR_Skeleton_FingerSplayIndexes.enumArray.Length];
  685. lastFingerCurls = new float[SteamVR_Skeleton_FingerIndexes.enumArray.Length];
  686. lastFingerSplays = new float[SteamVR_Skeleton_FingerSplayIndexes.enumArray.Length];
  687. }
  688. /// <summary>
  689. /// <strong>[Should not be called by user code]</strong>
  690. /// Initializes the handle for the inputSource, the skeletal action data size, and any other related SteamVR data.
  691. /// </summary>
  692. public override void Initialize()
  693. {
  694. base.Initialize();
  695. if (skeletonActionData_size == 0)
  696. skeletonActionData_size = (uint)Marshal.SizeOf(typeof(InputSkeletalActionData_t));
  697. }
  698. /// <summary><strong>[Should not be called by user code]</strong>
  699. /// Updates the data for this action and this input source. Sends related events.
  700. /// </summary>
  701. public override void UpdateValue()
  702. {
  703. UpdateValue(false);
  704. }
  705. /// <summary><strong>[Should not be called by user code]</strong>
  706. /// Updates the data for this action and this input source. Sends related events.
  707. /// </summary>
  708. public override void UpdateValue(bool skipStateAndEventUpdates)
  709. {
  710. lastActive = active;
  711. lastSkeletonActionData = skeletonActionData;
  712. lastSkeletalSummaryData = skeletalSummaryData;
  713. if (onlyUpdateSummaryData == false)
  714. {
  715. for (int boneIndex = 0; boneIndex < SteamVR_Action_Skeleton.numBones; boneIndex++)
  716. {
  717. lastBonePositions[boneIndex] = bonePositions[boneIndex];
  718. lastBoneRotations[boneIndex] = boneRotations[boneIndex];
  719. }
  720. }
  721. for (int fingerIndex = 0; fingerIndex < SteamVR_Skeleton_FingerIndexes.enumArray.Length; fingerIndex++)
  722. {
  723. lastFingerCurls[fingerIndex] = fingerCurls[fingerIndex];
  724. }
  725. for (int fingerIndex = 0; fingerIndex < SteamVR_Skeleton_FingerSplayIndexes.enumArray.Length; fingerIndex++)
  726. {
  727. lastFingerSplays[fingerIndex] = fingerSplays[fingerIndex];
  728. }
  729. base.UpdateValue(true);
  730. poseChanged = changed;
  731. EVRInputError error = OpenVR.Input.GetSkeletalActionData(handle, ref skeletonActionData, skeletonActionData_size);
  732. if (error != EVRInputError.None)
  733. {
  734. Debug.LogError("<b>[SteamVR]</b> GetSkeletalActionData error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
  735. return;
  736. }
  737. if (active)
  738. {
  739. if (onlyUpdateSummaryData == false)
  740. {
  741. error = OpenVR.Input.GetSkeletalBoneData(handle, skeletalTransformSpace, rangeOfMotion, tempBoneTransforms);
  742. if (error != EVRInputError.None)
  743. Debug.LogError("<b>[SteamVR]</b> GetSkeletalBoneData error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
  744. for (int boneIndex = 0; boneIndex < tempBoneTransforms.Length; boneIndex++)
  745. {
  746. // SteamVR's coordinate system is right handed, and Unity's is left handed. The FBX data has its
  747. // X axis flipped when Unity imports it, so here we need to flip the X axis as well
  748. bonePositions[boneIndex].x = -tempBoneTransforms[boneIndex].position.v0;
  749. bonePositions[boneIndex].y = tempBoneTransforms[boneIndex].position.v1;
  750. bonePositions[boneIndex].z = tempBoneTransforms[boneIndex].position.v2;
  751. boneRotations[boneIndex].x = tempBoneTransforms[boneIndex].orientation.x;
  752. boneRotations[boneIndex].y = -tempBoneTransforms[boneIndex].orientation.y;
  753. boneRotations[boneIndex].z = -tempBoneTransforms[boneIndex].orientation.z;
  754. boneRotations[boneIndex].w = tempBoneTransforms[boneIndex].orientation.w;
  755. }
  756. // Now that we're in the same handedness as Unity, rotate the root bone around the Y axis
  757. // so that forward is facing down +Z
  758. boneRotations[0] = SteamVR_Action_Skeleton.steamVRFixUpRotation * boneRotations[0];
  759. }
  760. UpdateSkeletalSummaryData(summaryDataType, true);
  761. }
  762. if (changed == false)
  763. {
  764. for (int boneIndex = 0; boneIndex < tempBoneTransforms.Length; boneIndex++)
  765. {
  766. if (Vector3.Distance(lastBonePositions[boneIndex], bonePositions[boneIndex]) > changeTolerance)
  767. {
  768. changed = true;
  769. break;
  770. }
  771. if (Mathf.Abs(Quaternion.Angle(lastBoneRotations[boneIndex], boneRotations[boneIndex])) > changeTolerance)
  772. {
  773. changed = true;
  774. break;
  775. }
  776. }
  777. }
  778. if (changed)
  779. changedTime = Time.realtimeSinceStartup;
  780. if (skipStateAndEventUpdates == false)
  781. CheckAndSendEvents();
  782. }
  783. /// <summary>
  784. /// The number of bones in the skeleton for this action
  785. /// </summary>
  786. public int boneCount { get { return (int)GetBoneCount(); } }
  787. /// <summary>
  788. /// Gets the number of bones in the skeleton for this action
  789. /// </summary>
  790. public uint GetBoneCount()
  791. {
  792. uint boneCount = 0;
  793. EVRInputError error = OpenVR.Input.GetBoneCount(handle, ref boneCount);
  794. if (error != EVRInputError.None)
  795. Debug.LogError("<b>[SteamVR]</b> GetBoneCount error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
  796. return boneCount;
  797. }
  798. /// <summary>
  799. /// Gets the ordering of the bone hierarchy
  800. /// </summary>
  801. public int[] boneHierarchy { get { return GetBoneHierarchy(); } }
  802. /// <summary>
  803. /// Gets the ordering of the bone hierarchy
  804. /// </summary>
  805. public int[] GetBoneHierarchy()
  806. {
  807. int boneCount = (int)GetBoneCount();
  808. int[] parentIndicies = new int[boneCount];
  809. EVRInputError error = OpenVR.Input.GetBoneHierarchy(handle, parentIndicies);
  810. if (error != EVRInputError.None)
  811. Debug.LogError("<b>[SteamVR]</b> GetBoneHierarchy error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
  812. return parentIndicies;
  813. }
  814. /// <summary>
  815. /// Gets the name for a bone at the specified index
  816. /// </summary>
  817. public string GetBoneName(int boneIndex)
  818. {
  819. StringBuilder stringBuilder = new StringBuilder(255);
  820. EVRInputError error = OpenVR.Input.GetBoneName(handle, boneIndex, stringBuilder, 255);
  821. if (error != EVRInputError.None)
  822. Debug.LogError("<b>[SteamVR]</b> GetBoneName error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
  823. return stringBuilder.ToString();
  824. }
  825. /// <summary>
  826. /// Returns an array of positions/rotations that represent the state of each bone in a reference pose.
  827. /// </summary>
  828. /// <param name="transformSpace">What to get the position/rotation data relative to, the model, or the bone's parent</param>
  829. /// <param name="referencePose">Which reference pose to return</param>
  830. /// <returns></returns>
  831. public SteamVR_Utils.RigidTransform[] GetReferenceTransforms(EVRSkeletalTransformSpace transformSpace, EVRSkeletalReferencePose referencePose)
  832. {
  833. SteamVR_Utils.RigidTransform[] transforms = new SteamVR_Utils.RigidTransform[GetBoneCount()];
  834. VRBoneTransform_t[] boneTransforms = new VRBoneTransform_t[transforms.Length];
  835. EVRInputError error = OpenVR.Input.GetSkeletalReferenceTransforms(handle, transformSpace, referencePose, boneTransforms);
  836. if (error != EVRInputError.None)
  837. Debug.LogError("<b>[SteamVR]</b> GetSkeletalReferenceTransforms error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
  838. for (int transformIndex = 0; transformIndex < boneTransforms.Length; transformIndex++)
  839. {
  840. Vector3 position = new Vector3(-boneTransforms[transformIndex].position.v0, boneTransforms[transformIndex].position.v1, boneTransforms[transformIndex].position.v2);
  841. Quaternion rotation = new Quaternion(boneTransforms[transformIndex].orientation.x, -boneTransforms[transformIndex].orientation.y, -boneTransforms[transformIndex].orientation.z, boneTransforms[transformIndex].orientation.w);
  842. transforms[transformIndex] = new SteamVR_Utils.RigidTransform(position, rotation);
  843. }
  844. if (transforms.Length > 0)
  845. {
  846. // Now that we're in the same handedness as Unity, rotate the root bone around the Y axis
  847. // so that forward is facing down +Z
  848. Quaternion qFixUpRot = Quaternion.AngleAxis(Mathf.PI * Mathf.Rad2Deg, Vector3.up);
  849. transforms[0].rot = qFixUpRot * transforms[0].rot;
  850. }
  851. return transforms;
  852. }
  853. /// <summary>
  854. /// Get the accuracy level of the skeletal tracking data.
  855. /// <para/>* Estimated: Body part location can’t be directly determined by the device. Any skeletal pose provided by the device is estimated based on the active buttons, triggers, joysticks, or other input sensors. Examples include the Vive Controller and gamepads.
  856. /// <para/>* Partial: Body part location can be measured directly but with fewer degrees of freedom than the actual body part.Certain body part positions may be unmeasured by the device and estimated from other input data.Examples include Knuckles or gloves that only measure finger curl
  857. /// <para/>* Full: Body part location can be measured directly throughout the entire range of motion of the body part.Examples include hi-end mocap systems, or gloves that measure the rotation of each finger segment.
  858. /// </summary>
  859. public EVRSkeletalTrackingLevel skeletalTrackingLevel { get { return GetSkeletalTrackingLevel(); } }
  860. /// <summary>
  861. /// Get the accuracy level of the skeletal tracking data.
  862. /// <para/>* Estimated: Body part location can’t be directly determined by the device. Any skeletal pose provided by the device is estimated based on the active buttons, triggers, joysticks, or other input sensors. Examples include the Vive Controller and gamepads.
  863. /// <para/>* Partial: Body part location can be measured directly but with fewer degrees of freedom than the actual body part.Certain body part positions may be unmeasured by the device and estimated from other input data.Examples include Knuckles or gloves that only measure finger curl
  864. /// <para/>* Full: Body part location can be measured directly throughout the entire range of motion of the body part.Examples include hi-end mocap systems, or gloves that measure the rotation of each finger segment.
  865. /// </summary>
  866. public EVRSkeletalTrackingLevel GetSkeletalTrackingLevel()
  867. {
  868. EVRSkeletalTrackingLevel skeletalTrackingLevel = EVRSkeletalTrackingLevel.VRSkeletalTracking_Estimated;
  869. EVRInputError error = OpenVR.Input.GetSkeletalTrackingLevel(handle, ref skeletalTrackingLevel);
  870. if (error != EVRInputError.None)
  871. Debug.LogError("<b>[SteamVR]</b> GetSkeletalTrackingLevel error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
  872. return skeletalTrackingLevel;
  873. }
  874. /// <summary>
  875. /// Get the skeletal summary data structure from OpenVR.
  876. /// Contains curl and splay data in finger order: thumb, index, middlg, ring, pinky.
  877. /// Easier access at named members: indexCurl, ringSplay, etc.
  878. /// </summary>
  879. protected VRSkeletalSummaryData_t GetSkeletalSummaryData(EVRSummaryType summaryType = EVRSummaryType.FromAnimation, bool force = false)
  880. {
  881. UpdateSkeletalSummaryData(summaryType, force);
  882. return skeletalSummaryData;
  883. }
  884. /// <summary>
  885. /// Updates the skeletal summary data structure from OpenVR.
  886. /// Contains curl and splay data in finger order: thumb, index, middlg, ring, pinky.
  887. /// Easier access at named members: indexCurl, ringSplay, etc.
  888. /// </summary>
  889. protected void UpdateSkeletalSummaryData(EVRSummaryType summaryType = EVRSummaryType.FromAnimation, bool force = false)
  890. {
  891. if (force || this.summaryDataType != summaryDataType && active)
  892. {
  893. EVRInputError error = OpenVR.Input.GetSkeletalSummaryData(handle, summaryType, ref skeletalSummaryData);
  894. if (error != EVRInputError.None)
  895. Debug.LogError("<b>[SteamVR]</b> GetSkeletalSummaryData error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
  896. fingerCurls[0] = skeletalSummaryData.flFingerCurl0;
  897. fingerCurls[1] = skeletalSummaryData.flFingerCurl1;
  898. fingerCurls[2] = skeletalSummaryData.flFingerCurl2;
  899. fingerCurls[3] = skeletalSummaryData.flFingerCurl3;
  900. fingerCurls[4] = skeletalSummaryData.flFingerCurl4;
  901. //no splay data for thumb
  902. fingerSplays[0] = skeletalSummaryData.flFingerSplay0;
  903. fingerSplays[1] = skeletalSummaryData.flFingerSplay1;
  904. fingerSplays[2] = skeletalSummaryData.flFingerSplay2;
  905. fingerSplays[3] = skeletalSummaryData.flFingerSplay3;
  906. }
  907. }
  908. protected override void CheckAndSendEvents()
  909. {
  910. if (trackingState != lastTrackingState && onTrackingChanged != null)
  911. onTrackingChanged.Invoke(skeletonAction, trackingState);
  912. if (poseIsValid != lastPoseIsValid && onValidPoseChanged != null)
  913. onValidPoseChanged.Invoke(skeletonAction, poseIsValid);
  914. if (deviceIsConnected != lastDeviceIsConnected && onDeviceConnectedChanged != null)
  915. onDeviceConnectedChanged.Invoke(skeletonAction, deviceIsConnected);
  916. if (changed && onChange != null)
  917. onChange.Invoke(skeletonAction);
  918. if (active != lastActive && onActiveChange != null)
  919. onActiveChange.Invoke(skeletonAction, active);
  920. if (activeBinding != lastActiveBinding && onActiveBindingChange != null)
  921. onActiveBindingChange.Invoke(skeletonAction, activeBinding);
  922. if (onUpdate != null)
  923. onUpdate.Invoke(skeletonAction);
  924. }
  925. }
  926. public interface ISteamVR_Action_Skeleton_Source
  927. {
  928. /// <summary>
  929. /// Get the accuracy level of the skeletal tracking data.
  930. /// <para/>* Estimated: Body part location can’t be directly determined by the device. Any skeletal pose provided by the device is estimated based on the active buttons, triggers, joysticks, or other input sensors. Examples include the Vive Controller and gamepads.
  931. /// <para/>* Partial: Body part location can be measured directly but with fewer degrees of freedom than the actual body part.Certain body part positions may be unmeasured by the device and estimated from other input data.Examples include Knuckles or gloves that only measure finger curl
  932. /// <para/>* Full: Body part location can be measured directly throughout the entire range of motion of the body part.Examples include hi-end mocap systems, or gloves that measure the rotation of each finger segment.
  933. /// </summary>
  934. EVRSkeletalTrackingLevel skeletalTrackingLevel { get; }
  935. /// <summary>An array of the positions of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.</summary>
  936. Vector3[] bonePositions { get; }
  937. /// <summary>An array of the rotations of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.</summary>
  938. Quaternion[] boneRotations { get; }
  939. /// <summary>From the previous update: An array of the positions of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.</summary>
  940. Vector3[] lastBonePositions { get; }
  941. /// <summary>From the previous update: An array of the rotations of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.</summary>
  942. Quaternion[] lastBoneRotations { get; }
  943. /// <summary>The range of motion the we're using to get bone data from. With Controller being your hand while holding the controller.</summary>
  944. EVRSkeletalMotionRange rangeOfMotion { get; set; }
  945. /// <summary>The space to get bone data in. Parent space by default</summary>
  946. EVRSkeletalTransformSpace skeletalTransformSpace { get; set; }
  947. /// <summary>Skips processing the full per bone data and only does the summary data</summary>
  948. bool onlyUpdateSummaryData { get; set; }
  949. /// <summary>A 0-1 value representing how curled the thumb is. 0 being straight, 1 being fully curled.</summary>
  950. float thumbCurl { get; }
  951. /// <summary>A 0-1 value representing how curled the index finger is. 0 being straight, 1 being fully curled.</summary>
  952. float indexCurl { get; }
  953. /// <summary>A 0-1 value representing how curled the middle finger is. 0 being straight, 1 being fully curled.</summary>
  954. float middleCurl { get; }
  955. /// <summary>A 0-1 value representing how curled the ring finger is. 0 being straight, 1 being fully curled.</summary>
  956. float ringCurl { get; }
  957. /// <summary>A 0-1 value representing how curled the pinky finger is. 0 being straight, 1 being fully curled.</summary>
  958. float pinkyCurl { get; }
  959. /// <summary>A 0-1 value representing the size of the gap between the thumb and index fingers</summary>
  960. float thumbIndexSplay { get; }
  961. /// <summary>A 0-1 value representing the size of the gap between the index and middle fingers</summary>
  962. float indexMiddleSplay { get; }
  963. /// <summary>A 0-1 value representing the size of the gap between the middle and ring fingers</summary>
  964. float middleRingSplay { get; }
  965. /// <summary>A 0-1 value representing the size of the gap between the ring and pinky fingers</summary>
  966. float ringPinkySplay { get; }
  967. /// <summary>[Previous Update] A 0-1 value representing how curled the thumb is. 0 being straight, 1 being fully curled.</summary>
  968. float lastThumbCurl { get; }
  969. /// <summary>[Previous Update] A 0-1 value representing how curled the index finger is. 0 being straight, 1 being fully curled.</summary>
  970. float lastIndexCurl { get; }
  971. /// <summary>[Previous Update] A 0-1 value representing how curled the middle finger is. 0 being straight, 1 being fully curled.</summary>
  972. float lastMiddleCurl { get; }
  973. /// <summary>[Previous Update] A 0-1 value representing how curled the ring finger is. 0 being straight, 1 being fully curled.</summary>
  974. float lastRingCurl { get; }
  975. /// <summary>[Previous Update] A 0-1 value representing how curled the pinky finger is. 0 being straight, 1 being fully curled.</summary>
  976. float lastPinkyCurl { get; }
  977. /// <summary>[Previous Update] A 0-1 value representing the size of the gap between the thumb and index fingers</summary>
  978. float lastThumbIndexSplay { get; }
  979. /// <summary>[Previous Update] A 0-1 value representing the size of the gap between the index and middle fingers</summary>
  980. float lastIndexMiddleSplay { get; }
  981. /// <summary>[Previous Update] A 0-1 value representing the size of the gap between the middle and ring fingers</summary>
  982. float lastMiddleRingSplay { get; }
  983. /// <summary>[Previous Update] A 0-1 value representing the size of the gap between the ring and pinky fingers</summary>
  984. float lastRingPinkySplay { get; }
  985. /// <summary>0-1 values representing how curled the specified finger is. 0 being straight, 1 being fully curled. For indexes see: SteamVR_Skeleton_FingerIndexes</summary>
  986. float[] fingerCurls { get; }
  987. /// <summary>0-1 values representing how splayed the specified finger and it's next index'd finger is. For indexes see: SteamVR_Skeleton_FingerIndexes</summary>
  988. float[] fingerSplays { get; }
  989. /// <summary>[Previous Update] 0-1 values representing how curled the specified finger is. 0 being straight, 1 being fully curled. For indexes see: SteamVR_Skeleton_FingerIndexes</summary>
  990. float[] lastFingerCurls { get; }
  991. /// <summary>[Previous Update] 0-1 values representing how splayed the specified finger and it's next index'd finger is. For indexes see: SteamVR_Skeleton_FingerIndexes</summary>
  992. float[] lastFingerSplays { get; }
  993. }
  994. /// <summary>
  995. /// The change in range of the motion of the bones in the skeleton. Options are "With Controller" as if your hand is holding your VR controller.
  996. /// Or "Without Controller" as if your hand is empty.
  997. /// </summary>
  998. public enum SkeletalMotionRangeChange
  999. {
  1000. None = -1,
  1001. /// <summary>Estimation of bones in hand while holding a controller</summary>
  1002. WithController = 0,
  1003. /// <summary>Estimation of bones in hand while hand is empty (allowing full fist)</summary>
  1004. WithoutController = 1,
  1005. }
  1006. /// <summary>The order of the joints that SteamVR Skeleton Input is expecting.</summary>
  1007. public static class SteamVR_Skeleton_JointIndexes
  1008. {
  1009. public const int root = 0;
  1010. public const int wrist = 1;
  1011. public const int thumbMetacarpal = 2;
  1012. public const int thumbProximal = 2;
  1013. public const int thumbMiddle = 3;
  1014. public const int thumbDistal = 4;
  1015. public const int thumbTip = 5;
  1016. public const int indexMetacarpal = 6;
  1017. public const int indexProximal = 7;
  1018. public const int indexMiddle = 8;
  1019. public const int indexDistal = 9;
  1020. public const int indexTip = 10;
  1021. public const int middleMetacarpal = 11;
  1022. public const int middleProximal = 12;
  1023. public const int middleMiddle = 13;
  1024. public const int middleDistal = 14;
  1025. public const int middleTip = 15;
  1026. public const int ringMetacarpal = 16;
  1027. public const int ringProximal = 17;
  1028. public const int ringMiddle = 18;
  1029. public const int ringDistal = 19;
  1030. public const int ringTip = 20;
  1031. public const int pinkyMetacarpal = 21;
  1032. public const int pinkyProximal = 22;
  1033. public const int pinkyMiddle = 23;
  1034. public const int pinkyDistal = 24;
  1035. public const int pinkyTip = 25;
  1036. public const int thumbAux = 26;
  1037. public const int indexAux = 27;
  1038. public const int middleAux = 28;
  1039. public const int ringAux = 29;
  1040. public const int pinkyAux = 30;
  1041. public static int GetFingerForBone(int boneIndex)
  1042. {
  1043. switch (boneIndex)
  1044. {
  1045. case root:
  1046. case wrist:
  1047. return -1;
  1048. case thumbMetacarpal:
  1049. case thumbMiddle:
  1050. case thumbDistal:
  1051. case thumbTip:
  1052. case thumbAux:
  1053. return 0;
  1054. case indexMetacarpal:
  1055. case indexProximal:
  1056. case indexMiddle:
  1057. case indexDistal:
  1058. case indexTip:
  1059. case indexAux:
  1060. return 1;
  1061. case middleMetacarpal:
  1062. case middleProximal:
  1063. case middleMiddle:
  1064. case middleDistal:
  1065. case middleTip:
  1066. case middleAux:
  1067. return 2;
  1068. case ringMetacarpal:
  1069. case ringProximal:
  1070. case ringMiddle:
  1071. case ringDistal:
  1072. case ringTip:
  1073. case ringAux:
  1074. return 3;
  1075. case pinkyMetacarpal:
  1076. case pinkyProximal:
  1077. case pinkyMiddle:
  1078. case pinkyDistal:
  1079. case pinkyTip:
  1080. case pinkyAux:
  1081. return 4;
  1082. default:
  1083. return -1;
  1084. }
  1085. }
  1086. public static int GetBoneForFingerTip(int fingerIndex)
  1087. {
  1088. switch (fingerIndex)
  1089. {
  1090. case SteamVR_Skeleton_FingerIndexes.thumb:
  1091. return thumbTip;
  1092. case SteamVR_Skeleton_FingerIndexes.index:
  1093. return indexTip;
  1094. case SteamVR_Skeleton_FingerIndexes.middle:
  1095. return middleTip;
  1096. case SteamVR_Skeleton_FingerIndexes.ring:
  1097. return ringTip;
  1098. case SteamVR_Skeleton_FingerIndexes.pinky:
  1099. return pinkyTip;
  1100. default:
  1101. return indexTip;
  1102. }
  1103. }
  1104. }
  1105. public enum SteamVR_Skeleton_JointIndexEnum
  1106. {
  1107. root = SteamVR_Skeleton_JointIndexes.root,
  1108. wrist = SteamVR_Skeleton_JointIndexes.wrist,
  1109. thumbMetacarpal = SteamVR_Skeleton_JointIndexes.thumbMetacarpal,
  1110. thumbProximal = SteamVR_Skeleton_JointIndexes.thumbProximal,
  1111. thumbMiddle = SteamVR_Skeleton_JointIndexes.thumbMiddle,
  1112. thumbDistal = SteamVR_Skeleton_JointIndexes.thumbDistal,
  1113. thumbTip = SteamVR_Skeleton_JointIndexes.thumbTip,
  1114. indexMetacarpal = SteamVR_Skeleton_JointIndexes.indexMetacarpal,
  1115. indexProximal = SteamVR_Skeleton_JointIndexes.indexProximal,
  1116. indexMiddle = SteamVR_Skeleton_JointIndexes.indexMiddle,
  1117. indexDistal = SteamVR_Skeleton_JointIndexes.indexDistal,
  1118. indexTip = SteamVR_Skeleton_JointIndexes.indexTip,
  1119. middleMetacarpal = SteamVR_Skeleton_JointIndexes.middleMetacarpal,
  1120. middleProximal = SteamVR_Skeleton_JointIndexes.middleProximal,
  1121. middleMiddle = SteamVR_Skeleton_JointIndexes.middleMiddle,
  1122. middleDistal = SteamVR_Skeleton_JointIndexes.middleDistal,
  1123. middleTip = SteamVR_Skeleton_JointIndexes.middleTip,
  1124. ringMetacarpal = SteamVR_Skeleton_JointIndexes.ringMetacarpal,
  1125. ringProximal = SteamVR_Skeleton_JointIndexes.ringProximal,
  1126. ringMiddle = SteamVR_Skeleton_JointIndexes.ringMiddle,
  1127. ringDistal = SteamVR_Skeleton_JointIndexes.ringDistal,
  1128. ringTip = SteamVR_Skeleton_JointIndexes.ringTip,
  1129. pinkyMetacarpal = SteamVR_Skeleton_JointIndexes.pinkyMetacarpal,
  1130. pinkyProximal = SteamVR_Skeleton_JointIndexes.pinkyProximal,
  1131. pinkyMiddle = SteamVR_Skeleton_JointIndexes.pinkyMiddle,
  1132. pinkyDistal = SteamVR_Skeleton_JointIndexes.pinkyDistal,
  1133. pinkyTip = SteamVR_Skeleton_JointIndexes.pinkyTip,
  1134. thumbAux = SteamVR_Skeleton_JointIndexes.thumbAux,
  1135. indexAux = SteamVR_Skeleton_JointIndexes.indexAux,
  1136. middleAux = SteamVR_Skeleton_JointIndexes.middleAux,
  1137. ringAux = SteamVR_Skeleton_JointIndexes.ringAux,
  1138. pinkyAux = SteamVR_Skeleton_JointIndexes.pinkyAux,
  1139. }
  1140. /// <summary>The order of the fingers that SteamVR Skeleton Input outputs</summary>
  1141. public class SteamVR_Skeleton_FingerIndexes
  1142. {
  1143. public const int thumb = 0;
  1144. public const int index = 1;
  1145. public const int middle = 2;
  1146. public const int ring = 3;
  1147. public const int pinky = 4;
  1148. public static SteamVR_Skeleton_FingerIndexEnum[] enumArray = (SteamVR_Skeleton_FingerIndexEnum[])System.Enum.GetValues(typeof(SteamVR_Skeleton_FingerIndexEnum));
  1149. }
  1150. /// <summary>The order of the fingerSplays that SteamVR Skeleton Input outputs</summary>
  1151. public class SteamVR_Skeleton_FingerSplayIndexes
  1152. {
  1153. public const int thumbIndex = 0;
  1154. public const int indexMiddle = 1;
  1155. public const int middleRing = 2;
  1156. public const int ringPinky = 3;
  1157. public static SteamVR_Skeleton_FingerSplayIndexEnum[] enumArray = (SteamVR_Skeleton_FingerSplayIndexEnum[])System.Enum.GetValues(typeof(SteamVR_Skeleton_FingerSplayIndexEnum));
  1158. }
  1159. public enum SteamVR_Skeleton_FingerSplayIndexEnum
  1160. {
  1161. thumbIndex = SteamVR_Skeleton_FingerSplayIndexes.thumbIndex,
  1162. indexMiddle = SteamVR_Skeleton_FingerSplayIndexes.indexMiddle,
  1163. middleRing = SteamVR_Skeleton_FingerSplayIndexes.middleRing,
  1164. ringPinky = SteamVR_Skeleton_FingerSplayIndexes.ringPinky,
  1165. }
  1166. public enum SteamVR_Skeleton_FingerIndexEnum
  1167. {
  1168. thumb = SteamVR_Skeleton_FingerIndexes.thumb,
  1169. index = SteamVR_Skeleton_FingerIndexes.index,
  1170. middle = SteamVR_Skeleton_FingerIndexes.middle,
  1171. ring = SteamVR_Skeleton_FingerIndexes.ring,
  1172. pinky = SteamVR_Skeleton_FingerIndexes.pinky,
  1173. }
  1174. }