getSkeleton.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. return {
  2. tag = 'input',
  3. summary = 'Get skeletal joint transforms tracked by a device.',
  4. description = [[
  5. Returns a list of joint transforms tracked by a device. Currently, only hand devices are able
  6. to track joints.
  7. ]],
  8. arguments = {
  9. device = {
  10. type = 'Device',
  11. description = 'The Device to query.'
  12. },
  13. t = {
  14. type = 'table',
  15. description = 'A table to fill with the joint transforms, instead of allocating a new one.'
  16. }
  17. },
  18. returns = {
  19. transforms = {
  20. type = 'table',
  21. description = [[
  22. A list of joint transforms for the device. Each transform is a table with 3 numbers for the
  23. position of the joint, 1 number for the joint radius (in meters), and 4 numbers for the
  24. angle/axis orientation of the joint. There is also a `radius` key with the radius of the
  25. joint as well.
  26. ]]
  27. }
  28. },
  29. variants = {
  30. {
  31. arguments = { 'device' },
  32. returns = { 'transforms' }
  33. },
  34. {
  35. arguments = { 'device', 't' },
  36. returns = { 'transforms' }
  37. }
  38. },
  39. notes = [[
  40. If the Device does not support tracking joints or the transforms are unavailable, `nil` is
  41. returned.
  42. The joint orientation is similar to the graphics coordinate system: -Z is the forwards
  43. direction, pointing towards the fingertips. The +Y direction is "up", pointing out of the back
  44. of the hand. The +X direction is to the right, perpendicular to X and Z.
  45. Here's a picture, courtesy of Khronos Group:
  46. ![Hand Skeleton Joints](https://lovr.org/img/hand-skeleton.png)
  47. Hand joints are returned in the following order:
  48. <table>
  49. <thead>
  50. <tr>
  51. <td colspan="2">Joint</td>
  52. <td>Index</td>
  53. </tr>
  54. </thead>
  55. <tbody>
  56. <tr>
  57. <td colspan="2">Palm</td>
  58. <td>1</td>
  59. </tr>
  60. <tr>
  61. <td colspan="2">Wrist</td>
  62. <td>2</td>
  63. </tr>
  64. <tr>
  65. <td rowspan="4">Thumb</td>
  66. <td>Metacarpal</td>
  67. <td>3</td>
  68. </tr>
  69. <tr>
  70. <td>Proximal</td>
  71. <td>4</td>
  72. </tr>
  73. <tr>
  74. <td>Distal</td>
  75. <td>5</td>
  76. </tr>
  77. <tr>
  78. <td>Tip</td>
  79. <td>6</td>
  80. </tr>
  81. <tr>
  82. <td rowspan="5">Index</td>
  83. <td>Metacarpal</td>
  84. <td>7</td>
  85. </tr>
  86. <tr>
  87. <td>Proximal</td>
  88. <td>8</td>
  89. </tr>
  90. <tr>
  91. <td>Intermediate</td>
  92. <td>9</td>
  93. </tr>
  94. <tr>
  95. <td>Distal</td>
  96. <td>10</td>
  97. </tr>
  98. <tr>
  99. <td>Tip</td>
  100. <td>11</td>
  101. </tr>
  102. <tr>
  103. <td rowspan="5">Middle</td>
  104. <td>Metacarpal</td>
  105. <td>12</td>
  106. </tr>
  107. <tr>
  108. <td>Proximal</td>
  109. <td>13</td>
  110. </tr>
  111. <tr>
  112. <td>Intermediate</td>
  113. <td>14</td>
  114. </tr>
  115. <tr>
  116. <td>Distal</td>
  117. <td>15</td>
  118. </tr>
  119. <tr>
  120. <td>Tip</td>
  121. <td>16</td>
  122. </tr>
  123. <tr>
  124. <td rowspan="5">Ring</td>
  125. <td>Metacarpal</td>
  126. <td>17</td>
  127. </tr>
  128. <tr>
  129. <td>Proximal</td>
  130. <td>18</td>
  131. </tr>
  132. <tr>
  133. <td>Intermediate</td>
  134. <td>19</td>
  135. </tr>
  136. <tr>
  137. <td>Distal</td>
  138. <td>20</td>
  139. </tr>
  140. <tr>
  141. <td>Tip</td>
  142. <td>21</td>
  143. </tr>
  144. <tr>
  145. <td rowspan="5">Pinky</td>
  146. <td>Metacarpal</td>
  147. <td>22</td>
  148. </tr>
  149. <tr>
  150. <td>Proximal</td>
  151. <td>23</td>
  152. </tr>
  153. <tr>
  154. <td>Intermediate</td>
  155. <td>24</td>
  156. </tr>
  157. <tr>
  158. <td>Distal</td>
  159. <td>25</td>
  160. </tr>
  161. <tr>
  162. <td>Tip</td>
  163. <td>26</td>
  164. </tr>
  165. </tbody>
  166. </table>
  167. ]],
  168. example = [[
  169. function lovr.draw(pass)
  170. for _, hand in ipairs({ 'left', 'right' }) do
  171. for _, joint in ipairs(lovr.headset.getSkeleton(hand) or {}) do
  172. pass:points(unpack(joint, 1, 3))
  173. end
  174. end
  175. end
  176. ]],
  177. related = {
  178. 'lovr.headset.getPose',
  179. 'lovr.headset.animate'
  180. }
  181. }