2
0

SteamVR_Action_Skeleton.cs 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526
  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>
  493. /// Removes all listeners, useful for dispose pattern
  494. /// </summary>
  495. public void RemoveAllListeners(SteamVR_Input_Sources input_Sources)
  496. {
  497. sourceMap[input_Sources].RemoveAllListeners();
  498. }
  499. /// <summary>Fires an event when a device is connected or disconnected.</summary>
  500. /// <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>
  501. public void AddOnDeviceConnectedChanged(DeviceConnectedChangeHandler functionToCall)
  502. {
  503. sourceMap[SteamVR_Input_Sources.Any].onDeviceConnectedChanged += functionToCall;
  504. }
  505. /// <summary>Stops executing the function setup by the corresponding AddListener</summary>
  506. /// <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>
  507. public void RemoveOnDeviceConnectedChanged(DeviceConnectedChangeHandler functionToStopCalling)
  508. {
  509. sourceMap[SteamVR_Input_Sources.Any].onDeviceConnectedChanged -= functionToStopCalling;
  510. }
  511. /// <summary>Fires an event when the tracking of the device has changed</summary>
  512. /// <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>
  513. public void AddOnTrackingChanged(TrackingChangeHandler functionToCall)
  514. {
  515. sourceMap[SteamVR_Input_Sources.Any].onTrackingChanged += functionToCall;
  516. }
  517. /// <summary>Stops executing the function setup by the corresponding AddListener</summary>
  518. /// <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>
  519. public void RemoveOnTrackingChanged(TrackingChangeHandler functionToStopCalling)
  520. {
  521. sourceMap[SteamVR_Input_Sources.Any].onTrackingChanged -= functionToStopCalling;
  522. }
  523. /// <summary>Fires an event when the device now has a valid pose or no longer has a valid pose</summary>
  524. /// <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>
  525. public void AddOnValidPoseChanged(ValidPoseChangeHandler functionToCall)
  526. {
  527. sourceMap[SteamVR_Input_Sources.Any].onValidPoseChanged += functionToCall;
  528. }
  529. /// <summary>Stops executing the function setup by the corresponding AddListener</summary>
  530. /// <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>
  531. public void RemoveOnValidPoseChanged(ValidPoseChangeHandler functionToStopCalling)
  532. {
  533. sourceMap[SteamVR_Input_Sources.Any].onValidPoseChanged -= functionToStopCalling;
  534. }
  535. /// <summary>Executes a function when this action's bound state changes</summary>
  536. public void AddOnActiveChangeListener(ActiveChangeHandler functionToCall)
  537. {
  538. sourceMap[SteamVR_Input_Sources.Any].onActiveChange += functionToCall;
  539. }
  540. /// <summary>Stops executing the function setup by the corresponding AddListener</summary>
  541. /// <param name="functionToStopCalling">The local function that you've setup to receive update events</param>
  542. public void RemoveOnActiveChangeListener(ActiveChangeHandler functionToStopCalling)
  543. {
  544. sourceMap[SteamVR_Input_Sources.Any].onActiveChange -= functionToStopCalling;
  545. }
  546. /// <summary>Executes a function when the state of this action changes</summary>
  547. /// <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>
  548. public void AddOnChangeListener(ChangeHandler functionToCall)
  549. {
  550. sourceMap[SteamVR_Input_Sources.Any].onChange += functionToCall;
  551. }
  552. /// <summary>Stops executing the function setup by the corresponding AddListener</summary>
  553. /// <param name="functionToStopCalling">The local function that you've setup to receive on change events</param>
  554. public void RemoveOnChangeListener(ChangeHandler functionToStopCalling)
  555. {
  556. sourceMap[SteamVR_Input_Sources.Any].onChange -= functionToStopCalling;
  557. }
  558. /// <summary>Executes a function when the state of this action is updated.</summary>
  559. /// <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>
  560. public void AddOnUpdateListener(UpdateHandler functionToCall)
  561. {
  562. sourceMap[SteamVR_Input_Sources.Any].onUpdate += functionToCall;
  563. }
  564. /// <summary>Stops executing the function setup by the corresponding AddListener</summary>
  565. /// <param name="functionToStopCalling">The local function that you've setup to receive update events</param>
  566. public void RemoveOnUpdateListener(UpdateHandler functionToStopCalling)
  567. {
  568. sourceMap[SteamVR_Input_Sources.Any].onUpdate -= functionToStopCalling;
  569. }
  570. void ISerializationCallbackReceiver.OnBeforeSerialize()
  571. {
  572. }
  573. void ISerializationCallbackReceiver.OnAfterDeserialize()
  574. {
  575. InitAfterDeserialize();
  576. }
  577. public static Quaternion steamVRFixUpRotation = Quaternion.AngleAxis(Mathf.PI * Mathf.Rad2Deg, Vector3.up);
  578. }
  579. public class SteamVR_Action_Skeleton_Source_Map : SteamVR_Action_Pose_Source_Map<SteamVR_Action_Skeleton_Source>
  580. {
  581. protected override SteamVR_Action_Skeleton_Source GetSourceElementForIndexer(SteamVR_Input_Sources inputSource)
  582. {
  583. return sources[0]; //just in case somebody tries to access a different element, redirect them to the correct one.
  584. }
  585. }
  586. /// <summary>
  587. /// 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.
  588. /// For more information check out this blog post: https://steamcommunity.com/games/250820/announcements/detail/1690421280625220068
  589. /// </summary>
  590. public class SteamVR_Action_Skeleton_Source : SteamVR_Action_Pose_Source, ISteamVR_Action_Skeleton_Source
  591. {
  592. protected static uint skeletonActionData_size = 0;
  593. /// <summary>Event fires when the active state (ActionSet active and binding active) changes</summary>
  594. public new event SteamVR_Action_Skeleton.ActiveChangeHandler onActiveChange;
  595. /// <summary>Event fires when the active state of the binding changes</summary>
  596. public new event SteamVR_Action_Skeleton.ActiveChangeHandler onActiveBindingChange;
  597. /// <summary>Event fires when the orientation of the pose or bones changes more than the changeTolerance</summary>
  598. public new event SteamVR_Action_Skeleton.ChangeHandler onChange;
  599. /// <summary>Event fires when the action is updated</summary>
  600. public new event SteamVR_Action_Skeleton.UpdateHandler onUpdate;
  601. /// <summary>Event fires when the state of the tracking system that is used to create pose data (position, rotation, etc) changes</summary>
  602. public new event SteamVR_Action_Skeleton.TrackingChangeHandler onTrackingChanged;
  603. /// <summary>Event fires when the state of the pose data retrieved for this action changes validity (good/bad data from the tracking source)</summary>
  604. public new event SteamVR_Action_Skeleton.ValidPoseChangeHandler onValidPoseChanged;
  605. /// <summary>Event fires when the device bound to this action is connected or disconnected</summary>
  606. public new event SteamVR_Action_Skeleton.DeviceConnectedChangeHandler onDeviceConnectedChanged;
  607. /// <summary>True if the action is bound</summary>
  608. public override bool activeBinding { get { return skeletonActionData.bActive; } }
  609. /// <summary>True if the action's binding was active during the previous update</summary>
  610. public override bool lastActiveBinding { get { return lastSkeletonActionData.bActive; } }
  611. /// <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>
  612. public Vector3[] bonePositions { get; protected set; }
  613. /// <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>
  614. public Quaternion[] boneRotations { get; protected set; }
  615. /// <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>
  616. public Vector3[] lastBonePositions { get; protected set; }
  617. /// <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>
  618. public Quaternion[] lastBoneRotations { get; protected set; }
  619. /// <summary>The range of motion the we're using to get bone data from. With Controller being your hand while holding the controller.</summary>
  620. public EVRSkeletalMotionRange rangeOfMotion { get; set; }
  621. /// <summary>The space to get bone data in. Parent space by default</summary>
  622. public EVRSkeletalTransformSpace skeletalTransformSpace { get; set; }
  623. /// <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>
  624. public EVRSummaryType summaryDataType { get; set; }
  625. /// <summary>A 0-1 value representing how curled the thumb is. 0 being straight, 1 being fully curled.</summary>
  626. public float thumbCurl { get { return fingerCurls[SteamVR_Skeleton_FingerIndexes.thumb]; } }
  627. /// <summary>A 0-1 value representing how curled the index finger is. 0 being straight, 1 being fully curled.</summary>
  628. public float indexCurl { get { return fingerCurls[SteamVR_Skeleton_FingerIndexes.index]; } }
  629. /// <summary>A 0-1 value representing how curled the middle finger is. 0 being straight, 1 being fully curled.</summary>
  630. public float middleCurl { get { return fingerCurls[SteamVR_Skeleton_FingerIndexes.middle]; } }
  631. /// <summary>A 0-1 value representing how curled the ring finger is. 0 being straight, 1 being fully curled.</summary>
  632. public float ringCurl { get { return fingerCurls[SteamVR_Skeleton_FingerIndexes.ring]; } }
  633. /// <summary>A 0-1 value representing how curled the pinky finger is. 0 being straight, 1 being fully curled.</summary>
  634. public float pinkyCurl { get { return fingerCurls[SteamVR_Skeleton_FingerIndexes.pinky]; } }
  635. /// <summary>A 0-1 value representing the size of the gap between the thumb and index fingers</summary>
  636. public float thumbIndexSplay { get { return fingerSplays[SteamVR_Skeleton_FingerSplayIndexes.thumbIndex]; } }
  637. /// <summary>A 0-1 value representing the size of the gap between the index and middle fingers</summary>
  638. public float indexMiddleSplay { get { return fingerSplays[SteamVR_Skeleton_FingerSplayIndexes.indexMiddle]; } }
  639. /// <summary>A 0-1 value representing the size of the gap between the middle and ring fingers</summary>
  640. public float middleRingSplay { get { return fingerSplays[SteamVR_Skeleton_FingerSplayIndexes.middleRing]; } }
  641. /// <summary>A 0-1 value representing the size of the gap between the ring and pinky fingers</summary>
  642. public float ringPinkySplay { get { return fingerSplays[SteamVR_Skeleton_FingerSplayIndexes.ringPinky]; } }
  643. /// <summary>[Previous Update] A 0-1 value representing how curled the thumb is. 0 being straight, 1 being fully curled.</summary>
  644. public float lastThumbCurl { get { return lastFingerCurls[SteamVR_Skeleton_FingerIndexes.thumb]; } }
  645. /// <summary>[Previous Update] A 0-1 value representing how curled the index finger is. 0 being straight, 1 being fully curled.</summary>
  646. public float lastIndexCurl { get { return lastFingerCurls[SteamVR_Skeleton_FingerIndexes.index]; } }
  647. /// <summary>[Previous Update] A 0-1 value representing how curled the middle finger is. 0 being straight, 1 being fully curled.</summary>
  648. public float lastMiddleCurl { get { return lastFingerCurls[SteamVR_Skeleton_FingerIndexes.middle]; } }
  649. /// <summary>[Previous Update] A 0-1 value representing how curled the ring finger is. 0 being straight, 1 being fully curled.</summary>
  650. public float lastRingCurl { get { return lastFingerCurls[SteamVR_Skeleton_FingerIndexes.ring]; } }
  651. /// <summary>[Previous Update] A 0-1 value representing how curled the pinky finger is. 0 being straight, 1 being fully curled.</summary>
  652. public float lastPinkyCurl { get { return lastFingerCurls[SteamVR_Skeleton_FingerIndexes.pinky]; } }
  653. /// <summary>[Previous Update] A 0-1 value representing the size of the gap between the thumb and index fingers</summary>
  654. public float lastThumbIndexSplay { get { return lastFingerSplays[SteamVR_Skeleton_FingerSplayIndexes.thumbIndex]; } }
  655. /// <summary>[Previous Update] A 0-1 value representing the size of the gap between the index and middle fingers</summary>
  656. public float lastIndexMiddleSplay { get { return lastFingerSplays[SteamVR_Skeleton_FingerSplayIndexes.indexMiddle]; } }
  657. /// <summary>[Previous Update] A 0-1 value representing the size of the gap between the middle and ring fingers</summary>
  658. public float lastMiddleRingSplay { get { return lastFingerSplays[SteamVR_Skeleton_FingerSplayIndexes.middleRing]; } }
  659. /// <summary>[Previous Update] A 0-1 value representing the size of the gap between the ring and pinky fingers</summary>
  660. public float lastRingPinkySplay { get { return lastFingerSplays[SteamVR_Skeleton_FingerSplayIndexes.ringPinky]; } }
  661. /// <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>
  662. public float[] fingerCurls { get; protected set; }
  663. /// <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>
  664. public float[] fingerSplays { get; protected set; }
  665. /// <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>
  666. public float[] lastFingerCurls { get; protected set; }
  667. /// <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>
  668. public float[] lastFingerSplays { get; protected set; }
  669. /// <summary>Separate from "changed". If the pose for this skeleton action has changed (root position/rotation)</summary>
  670. public bool poseChanged { get; protected set; }
  671. /// <summary>Skips processing the full per bone data and only does the summary data</summary>
  672. public bool onlyUpdateSummaryData { get; set; }
  673. protected VRSkeletalSummaryData_t skeletalSummaryData = new VRSkeletalSummaryData_t();
  674. protected VRSkeletalSummaryData_t lastSkeletalSummaryData = new VRSkeletalSummaryData_t();
  675. protected SteamVR_Action_Skeleton skeletonAction;
  676. protected VRBoneTransform_t[] tempBoneTransforms = new VRBoneTransform_t[SteamVR_Action_Skeleton.numBones];
  677. protected InputSkeletalActionData_t skeletonActionData = new InputSkeletalActionData_t();
  678. protected InputSkeletalActionData_t lastSkeletonActionData = new InputSkeletalActionData_t();
  679. protected InputSkeletalActionData_t tempSkeletonActionData = new InputSkeletalActionData_t();
  680. public override void Preinitialize(SteamVR_Action wrappingAction, SteamVR_Input_Sources forInputSource)
  681. {
  682. base.Preinitialize(wrappingAction, forInputSource);
  683. skeletonAction = (SteamVR_Action_Skeleton)wrappingAction;
  684. bonePositions = new Vector3[SteamVR_Action_Skeleton.numBones];
  685. lastBonePositions = new Vector3[SteamVR_Action_Skeleton.numBones];
  686. boneRotations = new Quaternion[SteamVR_Action_Skeleton.numBones];
  687. lastBoneRotations = new Quaternion[SteamVR_Action_Skeleton.numBones];
  688. rangeOfMotion = EVRSkeletalMotionRange.WithController;
  689. skeletalTransformSpace = EVRSkeletalTransformSpace.Parent;
  690. fingerCurls = new float[SteamVR_Skeleton_FingerIndexes.enumArray.Length];
  691. fingerSplays = new float[SteamVR_Skeleton_FingerSplayIndexes.enumArray.Length];
  692. lastFingerCurls = new float[SteamVR_Skeleton_FingerIndexes.enumArray.Length];
  693. lastFingerSplays = new float[SteamVR_Skeleton_FingerSplayIndexes.enumArray.Length];
  694. }
  695. /// <summary>
  696. /// <strong>[Should not be called by user code]</strong>
  697. /// Initializes the handle for the inputSource, the skeletal action data size, and any other related SteamVR data.
  698. /// </summary>
  699. public override void Initialize()
  700. {
  701. base.Initialize();
  702. if (skeletonActionData_size == 0)
  703. skeletonActionData_size = (uint)Marshal.SizeOf(typeof(InputSkeletalActionData_t));
  704. }
  705. /// <summary>
  706. /// Removes all listeners, useful for dispose pattern
  707. /// </summary>
  708. public override void RemoveAllListeners()
  709. {
  710. base.RemoveAllListeners();
  711. Delegate[] delegates;
  712. if (onActiveChange != null)
  713. {
  714. delegates = onActiveChange.GetInvocationList();
  715. if (delegates != null)
  716. foreach (Delegate existingDelegate in delegates)
  717. onActiveChange -= (SteamVR_Action_Skeleton.ActiveChangeHandler)existingDelegate;
  718. }
  719. if (onChange != null)
  720. {
  721. delegates = onChange.GetInvocationList();
  722. if (delegates != null)
  723. foreach (Delegate existingDelegate in delegates)
  724. onChange -= (SteamVR_Action_Skeleton.ChangeHandler)existingDelegate;
  725. }
  726. if (onUpdate != null)
  727. {
  728. delegates = onUpdate.GetInvocationList();
  729. if (delegates != null)
  730. foreach (Delegate existingDelegate in delegates)
  731. onUpdate -= (SteamVR_Action_Skeleton.UpdateHandler)existingDelegate;
  732. }
  733. if (onTrackingChanged != null)
  734. {
  735. delegates = onTrackingChanged.GetInvocationList();
  736. if (delegates != null)
  737. foreach (Delegate existingDelegate in delegates)
  738. onTrackingChanged -= (SteamVR_Action_Skeleton.TrackingChangeHandler)existingDelegate;
  739. }
  740. if (onValidPoseChanged != null)
  741. {
  742. delegates = onValidPoseChanged.GetInvocationList();
  743. if (delegates != null)
  744. foreach (Delegate existingDelegate in delegates)
  745. onValidPoseChanged -= (SteamVR_Action_Skeleton.ValidPoseChangeHandler)existingDelegate;
  746. }
  747. if (onDeviceConnectedChanged != null)
  748. {
  749. delegates = onDeviceConnectedChanged.GetInvocationList();
  750. if (delegates != null)
  751. foreach (Delegate existingDelegate in delegates)
  752. onDeviceConnectedChanged -= (SteamVR_Action_Skeleton.DeviceConnectedChangeHandler)existingDelegate;
  753. }
  754. }
  755. /// <summary><strong>[Should not be called by user code]</strong>
  756. /// Updates the data for this action and this input source. Sends related events.
  757. /// </summary>
  758. public override void UpdateValue()
  759. {
  760. UpdateValue(false);
  761. }
  762. /// <summary><strong>[Should not be called by user code]</strong>
  763. /// Updates the data for this action and this input source. Sends related events.
  764. /// </summary>
  765. public override void UpdateValue(bool skipStateAndEventUpdates)
  766. {
  767. lastActive = active;
  768. lastSkeletonActionData = skeletonActionData;
  769. lastSkeletalSummaryData = skeletalSummaryData;
  770. if (onlyUpdateSummaryData == false)
  771. {
  772. for (int boneIndex = 0; boneIndex < SteamVR_Action_Skeleton.numBones; boneIndex++)
  773. {
  774. lastBonePositions[boneIndex] = bonePositions[boneIndex];
  775. lastBoneRotations[boneIndex] = boneRotations[boneIndex];
  776. }
  777. }
  778. for (int fingerIndex = 0; fingerIndex < SteamVR_Skeleton_FingerIndexes.enumArray.Length; fingerIndex++)
  779. {
  780. lastFingerCurls[fingerIndex] = fingerCurls[fingerIndex];
  781. }
  782. for (int fingerIndex = 0; fingerIndex < SteamVR_Skeleton_FingerSplayIndexes.enumArray.Length; fingerIndex++)
  783. {
  784. lastFingerSplays[fingerIndex] = fingerSplays[fingerIndex];
  785. }
  786. base.UpdateValue(true);
  787. poseChanged = changed;
  788. EVRInputError error = OpenVR.Input.GetSkeletalActionData(handle, ref skeletonActionData, skeletonActionData_size);
  789. if (error != EVRInputError.None)
  790. {
  791. Debug.LogError("<b>[SteamVR]</b> GetSkeletalActionData error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
  792. return;
  793. }
  794. if (active)
  795. {
  796. if (onlyUpdateSummaryData == false)
  797. {
  798. error = OpenVR.Input.GetSkeletalBoneData(handle, skeletalTransformSpace, rangeOfMotion, tempBoneTransforms);
  799. if (error != EVRInputError.None)
  800. Debug.LogError("<b>[SteamVR]</b> GetSkeletalBoneData error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
  801. for (int boneIndex = 0; boneIndex < tempBoneTransforms.Length; boneIndex++)
  802. {
  803. // SteamVR's coordinate system is right handed, and Unity's is left handed. The FBX data has its
  804. // X axis flipped when Unity imports it, so here we need to flip the X axis as well
  805. bonePositions[boneIndex].x = -tempBoneTransforms[boneIndex].position.v0;
  806. bonePositions[boneIndex].y = tempBoneTransforms[boneIndex].position.v1;
  807. bonePositions[boneIndex].z = tempBoneTransforms[boneIndex].position.v2;
  808. boneRotations[boneIndex].x = tempBoneTransforms[boneIndex].orientation.x;
  809. boneRotations[boneIndex].y = -tempBoneTransforms[boneIndex].orientation.y;
  810. boneRotations[boneIndex].z = -tempBoneTransforms[boneIndex].orientation.z;
  811. boneRotations[boneIndex].w = tempBoneTransforms[boneIndex].orientation.w;
  812. }
  813. // Now that we're in the same handedness as Unity, rotate the root bone around the Y axis
  814. // so that forward is facing down +Z
  815. boneRotations[0] = SteamVR_Action_Skeleton.steamVRFixUpRotation * boneRotations[0];
  816. }
  817. UpdateSkeletalSummaryData(summaryDataType, true);
  818. }
  819. if (changed == false)
  820. {
  821. for (int boneIndex = 0; boneIndex < tempBoneTransforms.Length; boneIndex++)
  822. {
  823. if (Vector3.Distance(lastBonePositions[boneIndex], bonePositions[boneIndex]) > changeTolerance)
  824. {
  825. changed = true;
  826. break;
  827. }
  828. if (Mathf.Abs(Quaternion.Angle(lastBoneRotations[boneIndex], boneRotations[boneIndex])) > changeTolerance)
  829. {
  830. changed = true;
  831. break;
  832. }
  833. }
  834. }
  835. if (changed)
  836. changedTime = Time.realtimeSinceStartup;
  837. if (skipStateAndEventUpdates == false)
  838. CheckAndSendEvents();
  839. }
  840. /// <summary>
  841. /// The number of bones in the skeleton for this action
  842. /// </summary>
  843. public int boneCount { get { return (int)GetBoneCount(); } }
  844. /// <summary>
  845. /// Gets the number of bones in the skeleton for this action
  846. /// </summary>
  847. public uint GetBoneCount()
  848. {
  849. uint boneCount = 0;
  850. EVRInputError error = OpenVR.Input.GetBoneCount(handle, ref boneCount);
  851. if (error != EVRInputError.None)
  852. Debug.LogError("<b>[SteamVR]</b> GetBoneCount error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
  853. return boneCount;
  854. }
  855. /// <summary>
  856. /// Gets the ordering of the bone hierarchy
  857. /// </summary>
  858. public int[] boneHierarchy { get { return GetBoneHierarchy(); } }
  859. /// <summary>
  860. /// Gets the ordering of the bone hierarchy
  861. /// </summary>
  862. public int[] GetBoneHierarchy()
  863. {
  864. int boneCount = (int)GetBoneCount();
  865. int[] parentIndicies = new int[boneCount];
  866. EVRInputError error = OpenVR.Input.GetBoneHierarchy(handle, parentIndicies);
  867. if (error != EVRInputError.None)
  868. Debug.LogError("<b>[SteamVR]</b> GetBoneHierarchy error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
  869. return parentIndicies;
  870. }
  871. /// <summary>
  872. /// Gets the name for a bone at the specified index
  873. /// </summary>
  874. public string GetBoneName(int boneIndex)
  875. {
  876. StringBuilder stringBuilder = new StringBuilder(255);
  877. EVRInputError error = OpenVR.Input.GetBoneName(handle, boneIndex, stringBuilder, 255);
  878. if (error != EVRInputError.None)
  879. Debug.LogError("<b>[SteamVR]</b> GetBoneName error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
  880. return stringBuilder.ToString();
  881. }
  882. /// <summary>
  883. /// Returns an array of positions/rotations that represent the state of each bone in a reference pose.
  884. /// </summary>
  885. /// <param name="transformSpace">What to get the position/rotation data relative to, the model, or the bone's parent</param>
  886. /// <param name="referencePose">Which reference pose to return</param>
  887. /// <returns></returns>
  888. public SteamVR_Utils.RigidTransform[] GetReferenceTransforms(EVRSkeletalTransformSpace transformSpace, EVRSkeletalReferencePose referencePose)
  889. {
  890. SteamVR_Utils.RigidTransform[] transforms = new SteamVR_Utils.RigidTransform[GetBoneCount()];
  891. VRBoneTransform_t[] boneTransforms = new VRBoneTransform_t[transforms.Length];
  892. EVRInputError error = OpenVR.Input.GetSkeletalReferenceTransforms(handle, transformSpace, referencePose, boneTransforms);
  893. if (error != EVRInputError.None)
  894. Debug.LogError("<b>[SteamVR]</b> GetSkeletalReferenceTransforms error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
  895. for (int transformIndex = 0; transformIndex < boneTransforms.Length; transformIndex++)
  896. {
  897. Vector3 position = new Vector3(-boneTransforms[transformIndex].position.v0, boneTransforms[transformIndex].position.v1, boneTransforms[transformIndex].position.v2);
  898. Quaternion rotation = new Quaternion(boneTransforms[transformIndex].orientation.x, -boneTransforms[transformIndex].orientation.y, -boneTransforms[transformIndex].orientation.z, boneTransforms[transformIndex].orientation.w);
  899. transforms[transformIndex] = new SteamVR_Utils.RigidTransform(position, rotation);
  900. }
  901. if (transforms.Length > 0)
  902. {
  903. // Now that we're in the same handedness as Unity, rotate the root bone around the Y axis
  904. // so that forward is facing down +Z
  905. Quaternion qFixUpRot = Quaternion.AngleAxis(Mathf.PI * Mathf.Rad2Deg, Vector3.up);
  906. transforms[0].rot = qFixUpRot * transforms[0].rot;
  907. }
  908. return transforms;
  909. }
  910. /// <summary>
  911. /// Get the accuracy level of the skeletal tracking data.
  912. /// <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.
  913. /// <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
  914. /// <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.
  915. /// </summary>
  916. public EVRSkeletalTrackingLevel skeletalTrackingLevel { get { return GetSkeletalTrackingLevel(); } }
  917. /// <summary>
  918. /// Get the accuracy level of the skeletal tracking data.
  919. /// <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.
  920. /// <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
  921. /// <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.
  922. /// </summary>
  923. public EVRSkeletalTrackingLevel GetSkeletalTrackingLevel()
  924. {
  925. EVRSkeletalTrackingLevel skeletalTrackingLevel = EVRSkeletalTrackingLevel.VRSkeletalTracking_Estimated;
  926. EVRInputError error = OpenVR.Input.GetSkeletalTrackingLevel(handle, ref skeletalTrackingLevel);
  927. if (error != EVRInputError.None)
  928. Debug.LogError("<b>[SteamVR]</b> GetSkeletalTrackingLevel error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
  929. return skeletalTrackingLevel;
  930. }
  931. /// <summary>
  932. /// Get the skeletal summary data structure from OpenVR.
  933. /// Contains curl and splay data in finger order: thumb, index, middlg, ring, pinky.
  934. /// Easier access at named members: indexCurl, ringSplay, etc.
  935. /// </summary>
  936. protected VRSkeletalSummaryData_t GetSkeletalSummaryData(EVRSummaryType summaryType = EVRSummaryType.FromAnimation, bool force = false)
  937. {
  938. UpdateSkeletalSummaryData(summaryType, force);
  939. return skeletalSummaryData;
  940. }
  941. /// <summary>
  942. /// Updates the skeletal summary data structure from OpenVR.
  943. /// Contains curl and splay data in finger order: thumb, index, middlg, ring, pinky.
  944. /// Easier access at named members: indexCurl, ringSplay, etc.
  945. /// </summary>
  946. protected void UpdateSkeletalSummaryData(EVRSummaryType summaryType = EVRSummaryType.FromAnimation, bool force = false)
  947. {
  948. if (force || this.summaryDataType != summaryDataType && active)
  949. {
  950. EVRInputError error = OpenVR.Input.GetSkeletalSummaryData(handle, summaryType, ref skeletalSummaryData);
  951. if (error != EVRInputError.None)
  952. Debug.LogError("<b>[SteamVR]</b> GetSkeletalSummaryData error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
  953. fingerCurls[0] = skeletalSummaryData.flFingerCurl0;
  954. fingerCurls[1] = skeletalSummaryData.flFingerCurl1;
  955. fingerCurls[2] = skeletalSummaryData.flFingerCurl2;
  956. fingerCurls[3] = skeletalSummaryData.flFingerCurl3;
  957. fingerCurls[4] = skeletalSummaryData.flFingerCurl4;
  958. //no splay data for thumb
  959. fingerSplays[0] = skeletalSummaryData.flFingerSplay0;
  960. fingerSplays[1] = skeletalSummaryData.flFingerSplay1;
  961. fingerSplays[2] = skeletalSummaryData.flFingerSplay2;
  962. fingerSplays[3] = skeletalSummaryData.flFingerSplay3;
  963. }
  964. }
  965. protected override void CheckAndSendEvents()
  966. {
  967. if (trackingState != lastTrackingState && onTrackingChanged != null)
  968. onTrackingChanged.Invoke(skeletonAction, trackingState);
  969. if (poseIsValid != lastPoseIsValid && onValidPoseChanged != null)
  970. onValidPoseChanged.Invoke(skeletonAction, poseIsValid);
  971. if (deviceIsConnected != lastDeviceIsConnected && onDeviceConnectedChanged != null)
  972. onDeviceConnectedChanged.Invoke(skeletonAction, deviceIsConnected);
  973. if (changed && onChange != null)
  974. onChange.Invoke(skeletonAction);
  975. if (active != lastActive && onActiveChange != null)
  976. onActiveChange.Invoke(skeletonAction, active);
  977. if (activeBinding != lastActiveBinding && onActiveBindingChange != null)
  978. onActiveBindingChange.Invoke(skeletonAction, activeBinding);
  979. if (onUpdate != null)
  980. onUpdate.Invoke(skeletonAction);
  981. }
  982. }
  983. public interface ISteamVR_Action_Skeleton_Source
  984. {
  985. /// <summary>
  986. /// Get the accuracy level of the skeletal tracking data.
  987. /// <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.
  988. /// <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
  989. /// <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.
  990. /// </summary>
  991. EVRSkeletalTrackingLevel skeletalTrackingLevel { get; }
  992. /// <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>
  993. Vector3[] bonePositions { get; }
  994. /// <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>
  995. Quaternion[] boneRotations { get; }
  996. /// <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>
  997. Vector3[] lastBonePositions { get; }
  998. /// <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>
  999. Quaternion[] lastBoneRotations { get; }
  1000. /// <summary>The range of motion the we're using to get bone data from. With Controller being your hand while holding the controller.</summary>
  1001. EVRSkeletalMotionRange rangeOfMotion { get; set; }
  1002. /// <summary>The space to get bone data in. Parent space by default</summary>
  1003. EVRSkeletalTransformSpace skeletalTransformSpace { get; set; }
  1004. /// <summary>Skips processing the full per bone data and only does the summary data</summary>
  1005. bool onlyUpdateSummaryData { get; set; }
  1006. /// <summary>A 0-1 value representing how curled the thumb is. 0 being straight, 1 being fully curled.</summary>
  1007. float thumbCurl { get; }
  1008. /// <summary>A 0-1 value representing how curled the index finger is. 0 being straight, 1 being fully curled.</summary>
  1009. float indexCurl { get; }
  1010. /// <summary>A 0-1 value representing how curled the middle finger is. 0 being straight, 1 being fully curled.</summary>
  1011. float middleCurl { get; }
  1012. /// <summary>A 0-1 value representing how curled the ring finger is. 0 being straight, 1 being fully curled.</summary>
  1013. float ringCurl { get; }
  1014. /// <summary>A 0-1 value representing how curled the pinky finger is. 0 being straight, 1 being fully curled.</summary>
  1015. float pinkyCurl { get; }
  1016. /// <summary>A 0-1 value representing the size of the gap between the thumb and index fingers</summary>
  1017. float thumbIndexSplay { get; }
  1018. /// <summary>A 0-1 value representing the size of the gap between the index and middle fingers</summary>
  1019. float indexMiddleSplay { get; }
  1020. /// <summary>A 0-1 value representing the size of the gap between the middle and ring fingers</summary>
  1021. float middleRingSplay { get; }
  1022. /// <summary>A 0-1 value representing the size of the gap between the ring and pinky fingers</summary>
  1023. float ringPinkySplay { get; }
  1024. /// <summary>[Previous Update] A 0-1 value representing how curled the thumb is. 0 being straight, 1 being fully curled.</summary>
  1025. float lastThumbCurl { get; }
  1026. /// <summary>[Previous Update] A 0-1 value representing how curled the index finger is. 0 being straight, 1 being fully curled.</summary>
  1027. float lastIndexCurl { get; }
  1028. /// <summary>[Previous Update] A 0-1 value representing how curled the middle finger is. 0 being straight, 1 being fully curled.</summary>
  1029. float lastMiddleCurl { get; }
  1030. /// <summary>[Previous Update] A 0-1 value representing how curled the ring finger is. 0 being straight, 1 being fully curled.</summary>
  1031. float lastRingCurl { get; }
  1032. /// <summary>[Previous Update] A 0-1 value representing how curled the pinky finger is. 0 being straight, 1 being fully curled.</summary>
  1033. float lastPinkyCurl { get; }
  1034. /// <summary>[Previous Update] A 0-1 value representing the size of the gap between the thumb and index fingers</summary>
  1035. float lastThumbIndexSplay { get; }
  1036. /// <summary>[Previous Update] A 0-1 value representing the size of the gap between the index and middle fingers</summary>
  1037. float lastIndexMiddleSplay { get; }
  1038. /// <summary>[Previous Update] A 0-1 value representing the size of the gap between the middle and ring fingers</summary>
  1039. float lastMiddleRingSplay { get; }
  1040. /// <summary>[Previous Update] A 0-1 value representing the size of the gap between the ring and pinky fingers</summary>
  1041. float lastRingPinkySplay { get; }
  1042. /// <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>
  1043. float[] fingerCurls { get; }
  1044. /// <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>
  1045. float[] fingerSplays { get; }
  1046. /// <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>
  1047. float[] lastFingerCurls { get; }
  1048. /// <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>
  1049. float[] lastFingerSplays { get; }
  1050. }
  1051. /// <summary>
  1052. /// 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.
  1053. /// Or "Without Controller" as if your hand is empty.
  1054. /// </summary>
  1055. public enum SkeletalMotionRangeChange
  1056. {
  1057. None = -1,
  1058. /// <summary>Estimation of bones in hand while holding a controller</summary>
  1059. WithController = 0,
  1060. /// <summary>Estimation of bones in hand while hand is empty (allowing full fist)</summary>
  1061. WithoutController = 1,
  1062. }
  1063. /// <summary>The order of the joints that SteamVR Skeleton Input is expecting.</summary>
  1064. public static class SteamVR_Skeleton_JointIndexes
  1065. {
  1066. public const int root = 0;
  1067. public const int wrist = 1;
  1068. public const int thumbMetacarpal = 2;
  1069. public const int thumbProximal = 2;
  1070. public const int thumbMiddle = 3;
  1071. public const int thumbDistal = 4;
  1072. public const int thumbTip = 5;
  1073. public const int indexMetacarpal = 6;
  1074. public const int indexProximal = 7;
  1075. public const int indexMiddle = 8;
  1076. public const int indexDistal = 9;
  1077. public const int indexTip = 10;
  1078. public const int middleMetacarpal = 11;
  1079. public const int middleProximal = 12;
  1080. public const int middleMiddle = 13;
  1081. public const int middleDistal = 14;
  1082. public const int middleTip = 15;
  1083. public const int ringMetacarpal = 16;
  1084. public const int ringProximal = 17;
  1085. public const int ringMiddle = 18;
  1086. public const int ringDistal = 19;
  1087. public const int ringTip = 20;
  1088. public const int pinkyMetacarpal = 21;
  1089. public const int pinkyProximal = 22;
  1090. public const int pinkyMiddle = 23;
  1091. public const int pinkyDistal = 24;
  1092. public const int pinkyTip = 25;
  1093. public const int thumbAux = 26;
  1094. public const int indexAux = 27;
  1095. public const int middleAux = 28;
  1096. public const int ringAux = 29;
  1097. public const int pinkyAux = 30;
  1098. public static int GetFingerForBone(int boneIndex)
  1099. {
  1100. switch (boneIndex)
  1101. {
  1102. case root:
  1103. case wrist:
  1104. return -1;
  1105. case thumbMetacarpal:
  1106. case thumbMiddle:
  1107. case thumbDistal:
  1108. case thumbTip:
  1109. case thumbAux:
  1110. return 0;
  1111. case indexMetacarpal:
  1112. case indexProximal:
  1113. case indexMiddle:
  1114. case indexDistal:
  1115. case indexTip:
  1116. case indexAux:
  1117. return 1;
  1118. case middleMetacarpal:
  1119. case middleProximal:
  1120. case middleMiddle:
  1121. case middleDistal:
  1122. case middleTip:
  1123. case middleAux:
  1124. return 2;
  1125. case ringMetacarpal:
  1126. case ringProximal:
  1127. case ringMiddle:
  1128. case ringDistal:
  1129. case ringTip:
  1130. case ringAux:
  1131. return 3;
  1132. case pinkyMetacarpal:
  1133. case pinkyProximal:
  1134. case pinkyMiddle:
  1135. case pinkyDistal:
  1136. case pinkyTip:
  1137. case pinkyAux:
  1138. return 4;
  1139. default:
  1140. return -1;
  1141. }
  1142. }
  1143. public static int GetBoneForFingerTip(int fingerIndex)
  1144. {
  1145. switch (fingerIndex)
  1146. {
  1147. case SteamVR_Skeleton_FingerIndexes.thumb:
  1148. return thumbTip;
  1149. case SteamVR_Skeleton_FingerIndexes.index:
  1150. return indexTip;
  1151. case SteamVR_Skeleton_FingerIndexes.middle:
  1152. return middleTip;
  1153. case SteamVR_Skeleton_FingerIndexes.ring:
  1154. return ringTip;
  1155. case SteamVR_Skeleton_FingerIndexes.pinky:
  1156. return pinkyTip;
  1157. default:
  1158. return indexTip;
  1159. }
  1160. }
  1161. }
  1162. public enum SteamVR_Skeleton_JointIndexEnum
  1163. {
  1164. root = SteamVR_Skeleton_JointIndexes.root,
  1165. wrist = SteamVR_Skeleton_JointIndexes.wrist,
  1166. thumbMetacarpal = SteamVR_Skeleton_JointIndexes.thumbMetacarpal,
  1167. thumbProximal = SteamVR_Skeleton_JointIndexes.thumbProximal,
  1168. thumbMiddle = SteamVR_Skeleton_JointIndexes.thumbMiddle,
  1169. thumbDistal = SteamVR_Skeleton_JointIndexes.thumbDistal,
  1170. thumbTip = SteamVR_Skeleton_JointIndexes.thumbTip,
  1171. indexMetacarpal = SteamVR_Skeleton_JointIndexes.indexMetacarpal,
  1172. indexProximal = SteamVR_Skeleton_JointIndexes.indexProximal,
  1173. indexMiddle = SteamVR_Skeleton_JointIndexes.indexMiddle,
  1174. indexDistal = SteamVR_Skeleton_JointIndexes.indexDistal,
  1175. indexTip = SteamVR_Skeleton_JointIndexes.indexTip,
  1176. middleMetacarpal = SteamVR_Skeleton_JointIndexes.middleMetacarpal,
  1177. middleProximal = SteamVR_Skeleton_JointIndexes.middleProximal,
  1178. middleMiddle = SteamVR_Skeleton_JointIndexes.middleMiddle,
  1179. middleDistal = SteamVR_Skeleton_JointIndexes.middleDistal,
  1180. middleTip = SteamVR_Skeleton_JointIndexes.middleTip,
  1181. ringMetacarpal = SteamVR_Skeleton_JointIndexes.ringMetacarpal,
  1182. ringProximal = SteamVR_Skeleton_JointIndexes.ringProximal,
  1183. ringMiddle = SteamVR_Skeleton_JointIndexes.ringMiddle,
  1184. ringDistal = SteamVR_Skeleton_JointIndexes.ringDistal,
  1185. ringTip = SteamVR_Skeleton_JointIndexes.ringTip,
  1186. pinkyMetacarpal = SteamVR_Skeleton_JointIndexes.pinkyMetacarpal,
  1187. pinkyProximal = SteamVR_Skeleton_JointIndexes.pinkyProximal,
  1188. pinkyMiddle = SteamVR_Skeleton_JointIndexes.pinkyMiddle,
  1189. pinkyDistal = SteamVR_Skeleton_JointIndexes.pinkyDistal,
  1190. pinkyTip = SteamVR_Skeleton_JointIndexes.pinkyTip,
  1191. thumbAux = SteamVR_Skeleton_JointIndexes.thumbAux,
  1192. indexAux = SteamVR_Skeleton_JointIndexes.indexAux,
  1193. middleAux = SteamVR_Skeleton_JointIndexes.middleAux,
  1194. ringAux = SteamVR_Skeleton_JointIndexes.ringAux,
  1195. pinkyAux = SteamVR_Skeleton_JointIndexes.pinkyAux,
  1196. }
  1197. /// <summary>The order of the fingers that SteamVR Skeleton Input outputs</summary>
  1198. public class SteamVR_Skeleton_FingerIndexes
  1199. {
  1200. public const int thumb = 0;
  1201. public const int index = 1;
  1202. public const int middle = 2;
  1203. public const int ring = 3;
  1204. public const int pinky = 4;
  1205. public static SteamVR_Skeleton_FingerIndexEnum[] enumArray = (SteamVR_Skeleton_FingerIndexEnum[])System.Enum.GetValues(typeof(SteamVR_Skeleton_FingerIndexEnum));
  1206. }
  1207. /// <summary>The order of the fingerSplays that SteamVR Skeleton Input outputs</summary>
  1208. public class SteamVR_Skeleton_FingerSplayIndexes
  1209. {
  1210. public const int thumbIndex = 0;
  1211. public const int indexMiddle = 1;
  1212. public const int middleRing = 2;
  1213. public const int ringPinky = 3;
  1214. public static SteamVR_Skeleton_FingerSplayIndexEnum[] enumArray = (SteamVR_Skeleton_FingerSplayIndexEnum[])System.Enum.GetValues(typeof(SteamVR_Skeleton_FingerSplayIndexEnum));
  1215. }
  1216. public enum SteamVR_Skeleton_FingerSplayIndexEnum
  1217. {
  1218. thumbIndex = SteamVR_Skeleton_FingerSplayIndexes.thumbIndex,
  1219. indexMiddle = SteamVR_Skeleton_FingerSplayIndexes.indexMiddle,
  1220. middleRing = SteamVR_Skeleton_FingerSplayIndexes.middleRing,
  1221. ringPinky = SteamVR_Skeleton_FingerSplayIndexes.ringPinky,
  1222. }
  1223. public enum SteamVR_Skeleton_FingerIndexEnum
  1224. {
  1225. thumb = SteamVR_Skeleton_FingerIndexes.thumb,
  1226. index = SteamVR_Skeleton_FingerIndexes.index,
  1227. middle = SteamVR_Skeleton_FingerIndexes.middle,
  1228. ring = SteamVR_Skeleton_FingerIndexes.ring,
  1229. pinky = SteamVR_Skeleton_FingerIndexes.pinky,
  1230. }
  1231. }