NativeHandTracking.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal
  10. {
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Runtime.InteropServices;
  14. using UnityEngine;
  15. /// <summary>
  16. /// Hand Tracking's Native API.
  17. /// </summary>
  18. internal partial class NativeHandTracking
  19. {
  20. public enum NRHandType
  21. {
  22. NR_HAND_TYPE_UNKNOWN = -1,
  23. NR_HAND_TYPE_LEFT = 0,
  24. NR_HAND_TYPE_RIGHT = 1
  25. }
  26. public enum NRHandJointType
  27. {
  28. NR_HAND_JOINT_TYPE_INVALID = -1,
  29. NR_HAND_JOINT_TYPE_THUMB_0 = 0,
  30. NR_HAND_JOINT_TYPE_THUMB_1 = 1,
  31. NR_HAND_JOINT_TYPE_THUMB_2 = 2,
  32. NR_HAND_JOINT_TYPE_THUMB_3 = 3,
  33. NR_HAND_JOINT_TYPE_INDEX_1 = 4,
  34. NR_HAND_JOINT_TYPE_INDEX_2 = 5,
  35. NR_HAND_JOINT_TYPE_INDEX_3 = 6,
  36. NR_HAND_JOINT_TYPE_INDEX_4 = 7,
  37. NR_HAND_JOINT_TYPE_MIDDLE_1 = 8,
  38. NR_HAND_JOINT_TYPE_MIDDLE_2 = 9,
  39. NR_HAND_JOINT_TYPE_MIDDLE_3 = 10,
  40. NR_HAND_JOINT_TYPE_MIDDLE_4 = 11,
  41. NR_HAND_JOINT_TYPE_RING_1 = 12,
  42. NR_HAND_JOINT_TYPE_RING_2 = 13,
  43. NR_HAND_JOINT_TYPE_RING_3 = 14,
  44. NR_HAND_JOINT_TYPE_RING_4 = 15,
  45. NR_HAND_JOINT_TYPE_PINKY_0 = 16,
  46. NR_HAND_JOINT_TYPE_PINKY_1 = 17,
  47. NR_HAND_JOINT_TYPE_PINKY_2 = 18,
  48. NR_HAND_JOINT_TYPE_PINKY_3 = 19,
  49. NR_HAND_JOINT_TYPE_PINKY_4 = 20,
  50. NR_HAND_JOINT_TYPE_PALM_CENTER = 21,
  51. NR_HAND_JOINT_TYPE_WRIST_BEGIN = 22,
  52. NR_HAND_JOINT_TYPE_WRIST_END = 23,
  53. NR_HAND_JOINT_TYPE_WRIST_CENTER = 24
  54. }
  55. public enum NRHandJointMask : UInt64
  56. {
  57. NR_HAND_JOINT_TYPE_MASK_THUMB_0 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_THUMB_0),
  58. NR_HAND_JOINT_TYPE_MASK_THUMB_1 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_THUMB_1),
  59. NR_HAND_JOINT_TYPE_MASK_THUMB_2 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_THUMB_2),
  60. NR_HAND_JOINT_TYPE_MASK_THUMB_3 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_THUMB_3),
  61. NR_HAND_JOINT_TYPE_MASK_INDEX_1 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_INDEX_1),
  62. NR_HAND_JOINT_TYPE_MASK_INDEX_2 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_INDEX_2),
  63. NR_HAND_JOINT_TYPE_MASK_INDEX_3 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_INDEX_3),
  64. NR_HAND_JOINT_TYPE_MASK_INDEX_4 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_INDEX_4),
  65. NR_HAND_JOINT_TYPE_MASK_MIDDLE_1 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_MIDDLE_1),
  66. NR_HAND_JOINT_TYPE_MASK_MIDDLE_2 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_MIDDLE_2),
  67. NR_HAND_JOINT_TYPE_MASK_MIDDLE_3 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_MIDDLE_3),
  68. NR_HAND_JOINT_TYPE_MASK_MIDDLE_4 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_MIDDLE_4),
  69. NR_HAND_JOINT_TYPE_MASK_RING_1 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_RING_1),
  70. NR_HAND_JOINT_TYPE_MASK_RING_2 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_RING_2),
  71. NR_HAND_JOINT_TYPE_MASK_RING_3 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_RING_3),
  72. NR_HAND_JOINT_TYPE_MASK_RING_4 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_RING_4),
  73. NR_HAND_JOINT_TYPE_MASK_PINKY_0 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_PINKY_0),
  74. NR_HAND_JOINT_TYPE_MASK_PINKY_1 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_PINKY_1),
  75. NR_HAND_JOINT_TYPE_MASK_PINKY_2 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_PINKY_2),
  76. NR_HAND_JOINT_TYPE_MASK_PINKY_3 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_PINKY_3),
  77. NR_HAND_JOINT_TYPE_MASK_PINKY_4 = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_PINKY_4),
  78. NR_HAND_JOINT_TYPE_MASK_PALM_CENTER = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_PALM_CENTER),
  79. NR_HAND_JOINT_TYPE_MASK_WRIST_BEGIN = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_WRIST_BEGIN),
  80. NR_HAND_JOINT_TYPE_MASK_WRIST_END = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_WRIST_END),
  81. NR_HAND_JOINT_TYPE_MASK_WRIST_CENTER = (1L << NRHandJointType.NR_HAND_JOINT_TYPE_WRIST_CENTER),
  82. NR_HAND_JOINT_TYPE_MASK_ALL = 0x7FFFFFFFFFFFFFFF
  83. }
  84. public enum NRGestureType
  85. {
  86. NR_GESTURE_TYPE_UNKNOWN = -1,
  87. NR_GESTURE_TYPE_OPEN_HAND = 0,
  88. NR_GESTURE_TYPE_GRAB = 1,
  89. NR_GESTURE_TYPE_PINCH = 2,
  90. NR_GESTURE_TYPE_POINT = 3,
  91. NR_GESTURE_TYPE_VICTORY = 4,
  92. NR_GESTURE_TYPE_CALL = 5,
  93. NR_GESTURE_TYPE_SYSTEM = 6,
  94. }
  95. public enum NRGestureTypeMask : UInt64
  96. {
  97. NR_GESTURE_TYPE_MASK_OPEN_HAND = (1L << NRGestureType.NR_GESTURE_TYPE_OPEN_HAND),
  98. NR_GESTURE_TYPE_MASK_GRAB = (1L << NRGestureType.NR_GESTURE_TYPE_GRAB),
  99. NR_GESTURE_TYPE_MASK_PINCH = (1L << NRGestureType.NR_GESTURE_TYPE_PINCH),
  100. NR_GESTURE_TYPE_MASK_POINT = (1L << NRGestureType.NR_GESTURE_TYPE_POINT),
  101. NR_GESTURE_TYPE_MASK_VICTORY = (1L << NRGestureType.NR_GESTURE_TYPE_VICTORY),
  102. NR_GESTURE_TYPE_MASK_CALL = (1L << NRGestureType.NR_GESTURE_TYPE_CALL),
  103. NR_GESTURE_TYPE_MASK_SYSTEM = (1L << NRGestureType.NR_GESTURE_TYPE_SYSTEM),
  104. NR_GESTURE_TYPE_MASK_ALL = 0x7FFFFFFFFFFFFFFF
  105. }
  106. public enum NRHandTrackingSupportFunction
  107. {
  108. NR_HANDTRACKING_SUPPORT_TIMESTAMP = 0,
  109. NR_HANDTRACKING_SUPPORT_HAND_JOINT_POSITION = 1,
  110. NR_HANDTRACKING_SUPPORT_HAND_JOINT_ROTATION = 2
  111. }
  112. public enum NRHandTrackingSupportFunctionMask : UInt64
  113. {
  114. NR_HANDTRACKING_SUPPORT_MASK_TIMESTAMP = (1L << NRHandTrackingSupportFunction.NR_HANDTRACKING_SUPPORT_TIMESTAMP),
  115. NR_HANDTRACKING_SUPPORT_MASK_HAND_JOINT_POSITION = (1L << NRHandTrackingSupportFunction.NR_HANDTRACKING_SUPPORT_HAND_JOINT_POSITION),
  116. NR_HANDTRACKING_SUPPORT_MASK_HAND_JOINT_ROTATION = (1L << NRHandTrackingSupportFunction.NR_HANDTRACKING_SUPPORT_HAND_JOINT_ROTATION)
  117. }
  118. private UInt64 m_HandTrackingHandle = 0;
  119. private UInt64 m_TrackingDataHandle = 0;
  120. private UInt64 m_CurrentHMDTimeNanos = 0;
  121. private UInt64 m_AvailableHandJointTypeMask = 0;
  122. private UInt64 m_AvailableGestureTypeMask = 0;
  123. private UInt64 m_SupportedFunctionMask = 0;
  124. private Dictionary<NRHandJointType, HandJointID> m_JointMapping = new Dictionary<NRHandJointType, HandJointID>
  125. {
  126. {NRHandJointType.NR_HAND_JOINT_TYPE_WRIST_CENTER, HandJointID.Wrist},
  127. {NRHandJointType.NR_HAND_JOINT_TYPE_PALM_CENTER, HandJointID.Palm},
  128. {NRHandJointType.NR_HAND_JOINT_TYPE_THUMB_0, HandJointID.ThumbMetacarpal},
  129. {NRHandJointType.NR_HAND_JOINT_TYPE_THUMB_1, HandJointID.ThumbProximal},
  130. {NRHandJointType.NR_HAND_JOINT_TYPE_THUMB_2, HandJointID.ThumbDistal},
  131. {NRHandJointType.NR_HAND_JOINT_TYPE_THUMB_3, HandJointID.ThumbTip},
  132. {NRHandJointType.NR_HAND_JOINT_TYPE_INDEX_1, HandJointID.IndexProximal},
  133. {NRHandJointType.NR_HAND_JOINT_TYPE_INDEX_2, HandJointID.IndexMiddle},
  134. {NRHandJointType.NR_HAND_JOINT_TYPE_INDEX_3, HandJointID.IndexDistal},
  135. {NRHandJointType.NR_HAND_JOINT_TYPE_INDEX_4, HandJointID.IndexTip},
  136. {NRHandJointType.NR_HAND_JOINT_TYPE_MIDDLE_1, HandJointID.MiddleProximal},
  137. {NRHandJointType.NR_HAND_JOINT_TYPE_MIDDLE_2, HandJointID.MiddleMiddle},
  138. {NRHandJointType.NR_HAND_JOINT_TYPE_MIDDLE_3, HandJointID.MiddleDistal},
  139. {NRHandJointType.NR_HAND_JOINT_TYPE_MIDDLE_4, HandJointID.MiddleTip},
  140. {NRHandJointType.NR_HAND_JOINT_TYPE_RING_1, HandJointID.RingProximal},
  141. {NRHandJointType.NR_HAND_JOINT_TYPE_RING_2, HandJointID.RingMiddle},
  142. {NRHandJointType.NR_HAND_JOINT_TYPE_RING_3, HandJointID.RingDistal},
  143. {NRHandJointType.NR_HAND_JOINT_TYPE_RING_4, HandJointID.RingTip},
  144. {NRHandJointType.NR_HAND_JOINT_TYPE_PINKY_0, HandJointID.PinkyMetacarpal},
  145. {NRHandJointType.NR_HAND_JOINT_TYPE_PINKY_1, HandJointID.PinkyProximal},
  146. {NRHandJointType.NR_HAND_JOINT_TYPE_PINKY_2, HandJointID.PinkyMiddle},
  147. {NRHandJointType.NR_HAND_JOINT_TYPE_PINKY_3, HandJointID.PinkyDistal},
  148. {NRHandJointType.NR_HAND_JOINT_TYPE_PINKY_4, HandJointID.PinkyTip}
  149. };
  150. private Transform m_CachedCameraRigTransform; //instead of using this, should use CameraRigTransform
  151. private Transform CameraRigTransform
  152. {
  153. get
  154. {
  155. if (m_CachedCameraRigTransform == null)
  156. {
  157. if (NRSessionManager.Instance != null)
  158. {
  159. m_CachedCameraRigTransform = NRSessionManager.Instance.NRSessionBehaviour.transform;
  160. }
  161. }
  162. return m_CachedCameraRigTransform;
  163. }
  164. }
  165. public NativeHandTracking()
  166. {
  167. var result = NativeApi.NRHandTrackingCreate(ref m_HandTrackingHandle);
  168. NativeErrorListener.Check(result, this, "Create");
  169. }
  170. public bool Start()
  171. {
  172. if (m_HandTrackingHandle == 0)
  173. return false;
  174. var result = NativeApi.NRHandTrackingStart(m_HandTrackingHandle);
  175. NativeErrorListener.Check(result, this, "Start", true);
  176. NativeApi.NRHandTrackingGetAvailableHandJoint(m_HandTrackingHandle, ref m_AvailableHandJointTypeMask);
  177. NativeApi.NRHandTrackingGetAvailableGestureType(m_HandTrackingHandle, ref m_AvailableGestureTypeMask);
  178. NativeApi.NRHandTrackingGetSupportedFunctions(m_HandTrackingHandle, ref m_SupportedFunctionMask);
  179. return result == NativeResult.Success;
  180. }
  181. public void Update(HandState[] handStates)
  182. {
  183. if (m_HandTrackingHandle == 0)
  184. return;
  185. ulong timeStamp = NRFrame.CurrentPoseTimeStamp;
  186. if (timeStamp == 0)
  187. {
  188. NRSessionManager.Instance.NativeAPI.NativeRenderring.GetFramePresentTime(ref timeStamp);
  189. }
  190. if (!TryAcquireHandTrackingDataHandle(timeStamp))
  191. return;
  192. UInt64 hmd_time_nanos = 0;
  193. var timeResult = NativeApi.NRHandTrackingDataGetHMDTimeNanos(m_TrackingDataHandle, ref hmd_time_nanos);
  194. if (timeResult != NativeResult.Success)
  195. {
  196. NativeErrorListener.Check(timeResult, this, "hmd_time_nanos");
  197. }
  198. UInt32 hand_count = 0;
  199. var countResult = NativeApi.NRHandTrackingDataGetHandsCount(m_TrackingDataHandle, ref hand_count);
  200. if (countResult != NativeResult.Success)
  201. {
  202. NativeErrorListener.Check(countResult, this, "hand_count");
  203. }
  204. for (int i = 0; i < handStates.Length; i++)
  205. {
  206. handStates[i].isTracked = false;
  207. handStates[i].pointerPoseValid = false;
  208. handStates[i].currentGesture = HandGesture.None;
  209. }
  210. bool rightHandUpdated = false;
  211. bool leftHandUpdated = false;
  212. for (int i = 0; i < hand_count; i++)
  213. {
  214. UInt64 hand_state_handle = 0;
  215. var handStateCreateResult = NativeApi.NRHandStateCreate(m_TrackingDataHandle, (UInt32)i, ref hand_state_handle);
  216. if (handStateCreateResult != NativeResult.Success)
  217. {
  218. NativeErrorListener.Check(handStateCreateResult, this, "hand_state_handle");
  219. continue;
  220. }
  221. bool isTracked = false;
  222. NativeApi.NRHandStateIsTracked(hand_state_handle, ref isTracked);
  223. NRHandType handType = NRHandType.NR_HAND_TYPE_UNKNOWN;
  224. NativeApi.NRHandStateGetHandType(hand_state_handle, ref handType);
  225. if (!isTracked)
  226. continue;
  227. if (rightHandUpdated && leftHandUpdated)
  228. continue;
  229. HandState handState = null;
  230. if (handType == NRHandType.NR_HAND_TYPE_RIGHT && !rightHandUpdated)
  231. {
  232. handState = handStates[0];
  233. rightHandUpdated = true;
  234. }
  235. else if(handType == NRHandType.NR_HAND_TYPE_LEFT && !leftHandUpdated)
  236. {
  237. handState = handStates[1];
  238. leftHandUpdated = true;
  239. }
  240. if (handState == null)
  241. continue;
  242. NRGestureType gestureType = NRGestureType.NR_GESTURE_TYPE_UNKNOWN;
  243. NativeApi.NRHandStateGetGestureType(hand_state_handle, ref gestureType);
  244. UInt32 handJointCount = 0;
  245. NativeApi.NRHandStateGetHandJointCount(hand_state_handle, ref handJointCount);
  246. //NativeApi.NRHandStateGetConfidence(hand_state_handle, ref handState.confidence);
  247. handState.isTracked = true;
  248. handState.pointerPoseValid = true;
  249. handState.currentGesture = GetMappedGesture(gestureType);
  250. for (UInt32 j = 0; j < handJointCount; j++)
  251. {
  252. UInt64 hand_joint_state_handle = 0;
  253. if (NativeApi.NRHandJointStateCreate(hand_state_handle, j, ref hand_joint_state_handle) == NativeResult.Success)
  254. {
  255. NRHandJointType handJointType = NRHandJointType.NR_HAND_JOINT_TYPE_INVALID;
  256. NativeApi.NRHandJointGetHandJointType(hand_joint_state_handle, ref handJointType);
  257. NativeMat4f handJointPose = new NativeMat4f(Matrix4x4.identity);
  258. NativeApi.NRHandJointGetHandJointPose(hand_joint_state_handle, ref handJointPose);
  259. HandJointID handJointID;
  260. if (m_JointMapping.TryGetValue(handJointType, out handJointID))
  261. {
  262. var pose = GetWorldPose(handJointPose);
  263. SetHandJointPose(handState, handJointID, pose);
  264. }
  265. }
  266. }
  267. }
  268. }
  269. public bool Pause()
  270. {
  271. if (m_HandTrackingHandle == 0)
  272. return false;
  273. var result = NativeApi.NRHandTrackingPause(m_HandTrackingHandle);
  274. NativeErrorListener.Check(result, this, "Pause");
  275. return result == NativeResult.Success;
  276. }
  277. public bool Resume()
  278. {
  279. if (m_HandTrackingHandle == 0)
  280. return false;
  281. var result = NativeApi.NRHandTrackingResume(m_HandTrackingHandle);
  282. NativeErrorListener.Check(result, this, "Resume");
  283. return result == NativeResult.Success;
  284. }
  285. public bool Stop()
  286. {
  287. if (m_HandTrackingHandle == 0)
  288. return false;
  289. var result = NativeApi.NRHandTrackingStop(m_HandTrackingHandle);
  290. NativeErrorListener.Check(result, this, "Stop");
  291. return result == NativeResult.Success;
  292. }
  293. public bool Destroy()
  294. {
  295. if (m_HandTrackingHandle == 0)
  296. return false;
  297. var result = NativeApi.NRHandTrackingDestroy(m_HandTrackingHandle);
  298. NativeErrorListener.Check(result, this, "Destroy");
  299. return result == NativeResult.Success;
  300. }
  301. private bool TryUpdateHandTracking()
  302. {
  303. var result = NativeApi.NRHandTrackingUpdate(m_HandTrackingHandle);
  304. return result == NativeResult.Success;
  305. }
  306. private bool TryCreateTrackingDataHandle()
  307. {
  308. var result = NativeApi.NRHandTrackingDataCreate(m_HandTrackingHandle, ref m_TrackingDataHandle);
  309. return result == NativeResult.Success;
  310. }
  311. private bool TryAcquireHandTrackingDataHandle(UInt64 timestamp)
  312. {
  313. var result = NativeApi.NRAcquireHandTrackingData(m_HandTrackingHandle, timestamp, ref m_TrackingDataHandle);
  314. return result == NativeResult.Success;
  315. }
  316. private HandEnum GetMappedHandEnum(NRHandType handType)
  317. {
  318. switch (handType)
  319. {
  320. case NRHandType.NR_HAND_TYPE_LEFT:
  321. return HandEnum.LeftHand;
  322. case NRHandType.NR_HAND_TYPE_RIGHT:
  323. return HandEnum.RightHand;
  324. default:
  325. break;
  326. }
  327. return HandEnum.None;
  328. }
  329. private HandGesture GetMappedGesture(NRGestureType gestureType)
  330. {
  331. switch (gestureType)
  332. {
  333. case NRGestureType.NR_GESTURE_TYPE_OPEN_HAND:
  334. return HandGesture.OpenHand;
  335. case NRGestureType.NR_GESTURE_TYPE_GRAB:
  336. return HandGesture.Grab;
  337. case NRGestureType.NR_GESTURE_TYPE_PINCH:
  338. return HandGesture.Pinch;
  339. case NRGestureType.NR_GESTURE_TYPE_POINT:
  340. return HandGesture.Point;
  341. case NRGestureType.NR_GESTURE_TYPE_VICTORY:
  342. return HandGesture.Victory;
  343. case NRGestureType.NR_GESTURE_TYPE_CALL:
  344. return HandGesture.Call;
  345. case NRGestureType.NR_GESTURE_TYPE_SYSTEM:
  346. return HandGesture.System;
  347. default:
  348. break;
  349. }
  350. return HandGesture.None;
  351. }
  352. private void SetHandJointPose(HandState handState, HandJointID jointID, Pose pose)
  353. {
  354. if (handState.jointsPoseDict.ContainsKey(jointID))
  355. {
  356. handState.jointsPoseDict[jointID] = pose;
  357. }
  358. else
  359. {
  360. handState.jointsPoseDict.Add(jointID, pose);
  361. }
  362. }
  363. private Pose GetWorldPose(NativeMat4f jointPose)
  364. {
  365. if (CameraRigTransform == null)
  366. {
  367. return Pose.identity;
  368. }
  369. Pose unitypose;
  370. ConversionUtility.ApiPoseToUnityPose(jointPose, out unitypose);
  371. return ConversionUtility.ApiWorldToUnityWorld(unitypose);
  372. }
  373. private partial struct NativeApi
  374. {
  375. [DllImport(NativeConstants.NRNativeLibrary)]
  376. public static extern NativeResult NRHandTrackingCreate(ref UInt64 hand_tracking_handle);
  377. [DllImport(NativeConstants.NRNativeLibrary)]
  378. public static extern NativeResult NRHandTrackingStart(UInt64 hand_tracking_handle);
  379. [DllImport(NativeConstants.NRNativeLibrary)]
  380. public static extern NativeResult NRHandTrackingPause(UInt64 hand_tracking_handle);
  381. [DllImport(NativeConstants.NRNativeLibrary)]
  382. public static extern NativeResult NRHandTrackingResume(UInt64 hand_tracking_handle);
  383. [DllImport(NativeConstants.NRNativeLibrary)]
  384. public static extern NativeResult NRHandTrackingStop(UInt64 hand_tracking_handle);
  385. [DllImport(NativeConstants.NRNativeLibrary)]
  386. public static extern NativeResult NRHandTrackingDestroy(UInt64 hand_tracking_handle);
  387. [DllImport(NativeConstants.NRNativeLibrary)]
  388. public static extern NativeResult NRHandTrackingGetAvailableHandJoint(UInt64 hand_tracking_handle, ref UInt64 out_available_hand_joint_type_mask);
  389. [DllImport(NativeConstants.NRNativeLibrary)]
  390. public static extern NativeResult NRHandTrackingGetAvailableGestureType(UInt64 hand_tracking_handle, ref UInt64 out_available_gesture_type_mask);
  391. [DllImport(NativeConstants.NRNativeLibrary)]
  392. public static extern NativeResult NRHandTrackingGetSupportedFunctions(UInt64 hand_tracking_handle, ref UInt64 out_supported_function_mask);
  393. [DllImport(NativeConstants.NRNativeLibrary)]
  394. public static extern NativeResult NRHandTrackingUpdate(UInt64 hand_tracking_handle);
  395. [DllImport(NativeConstants.NRNativeLibrary)]
  396. public static extern NativeResult NRHandTrackingDataCreate(UInt64 hand_tracking_handle, ref UInt64 out_hand_tracking_data_handle);
  397. [DllImport(NativeConstants.NRNativeLibrary)]
  398. public static extern NativeResult NRAcquireHandTrackingData(UInt64 hand_tracking_handle, UInt64 timestamp, ref UInt64 out_hand_tracking_data_handle);
  399. [DllImport(NativeConstants.NRNativeLibrary)]
  400. public static extern NativeResult NRHandTrackingDataDestroy(UInt64 hand_tracking_data_handle);
  401. [DllImport(NativeConstants.NRNativeLibrary)]
  402. public static extern NativeResult NRHandTrackingDataGetHMDTimeNanos(UInt64 hand_tracking_data_handle, ref UInt64 out_hmd_time_nanos);
  403. [DllImport(NativeConstants.NRNativeLibrary)]
  404. public static extern NativeResult NRHandTrackingDataGetHandsCount(UInt64 hand_tracking_data_handle, ref UInt32 out_hand_count);
  405. [DllImport(NativeConstants.NRNativeLibrary)]
  406. public static extern NativeResult NRHandStateCreate(UInt64 hand_tracking_data_handle, UInt32 hand_index, ref UInt64 out_hand_state_handle);
  407. [DllImport(NativeConstants.NRNativeLibrary)]
  408. public static extern NativeResult NRHandStateDestroy(UInt64 hand_state_handle);
  409. [DllImport(NativeConstants.NRNativeLibrary)]
  410. public static extern NativeResult NRHandStateGetHandType(UInt64 hand_state_handle, ref NRHandType out_hand_type);
  411. [DllImport(NativeConstants.NRNativeLibrary)]
  412. public static extern NativeResult NRHandStateGetGestureType(UInt64 hand_state_handle, ref NRGestureType out_gesture_type);
  413. [DllImport(NativeConstants.NRNativeLibrary)]
  414. public static extern NativeResult NRHandStateIsTracked(UInt64 hand_state_handle, ref bool out_is_tracked);
  415. [DllImport(NativeConstants.NRNativeLibrary)]
  416. public static extern NativeResult NRHandStateGetHandJointCount(UInt64 hand_state_handle, ref UInt32 out_hand_joint_count);
  417. [DllImport(NativeConstants.NRNativeLibrary)]
  418. public static extern NativeResult NRHandJointStateCreate(UInt64 hand_state_handle, UInt32 hand_joint_index, ref UInt64 out_hand_joint_state_handle);
  419. [DllImport(NativeConstants.NRNativeLibrary)]
  420. public static extern NativeResult NRHandJointStateDestroy(UInt64 hand_joint_state_handle);
  421. [DllImport(NativeConstants.NRNativeLibrary)]
  422. public static extern NativeResult NRHandJointGetHandJointType(UInt64 hand_joint_state_handle, ref NRHandJointType out_hand_joint_type);
  423. [DllImport(NativeConstants.NRNativeLibrary)]
  424. public static extern NativeResult NRHandJointGetHandJointPose(UInt64 hand_joint_state_handle, ref NativeMat4f out_hand_joint_pose);
  425. //[DllImport(NativeConstants.NRNativeLibrary)]
  426. //public static extern NativeResult NRHandStateGetConfidence(UInt64 hand_state_handle, ref float out_confidence);
  427. }
  428. }
  429. }