NativeInterface_Gesture.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using Rokid.UXR.Utility;
  4. using UnityEngine;
  5. namespace Rokid.UXR.Native
  6. {
  7. public partial class NativeInterface
  8. {
  9. public partial class NativeAPI
  10. {
  11. /// <summary>
  12. /// Init gesture
  13. /// </summary>
  14. public static void InitGesture()
  15. {
  16. if (Utils.IsAndroidPlatfrom())
  17. NativeInterface.NativeAPI.openGestureTracker();
  18. }
  19. /// <summary>
  20. /// Relese gesture
  21. /// </summary>
  22. public static void ReleaseGesure()
  23. {
  24. if (Utils.IsAndroidPlatfrom())
  25. NativeInterface.NativeAPI.closeGestureTracker();
  26. }
  27. /// <summary>
  28. /// Retrieve the number of tracked hand vertices.
  29. /// </summary>
  30. /// <returns></returns>
  31. public static int GetTrackingHandVertsNum()
  32. {
  33. if (Utils.IsAndroidPlatfrom())
  34. return getTrackingHandVertsNum();
  35. return 0;
  36. }
  37. /// <summary>
  38. /// Retrieve the number of tracked skeletons.
  39. /// </summary>
  40. /// <returns></returns>
  41. public static int GetTrackingHandSkeletonNum()
  42. {
  43. if (Utils.IsAndroidPlatfrom())
  44. return getTrackingHandSkeletonNum();
  45. return 0;
  46. }
  47. /// <summary>
  48. /// Retrieve the number of tracked hands.
  49. /// </summary>
  50. /// <returns></returns>
  51. public static int GetTrackingHandNum()
  52. {
  53. if (Utils.IsAndroidPlatfrom())
  54. return getTrackingHandNum();
  55. return 0;
  56. }
  57. /// <summary>
  58. /// Retrieve the type of tracked hands
  59. /// </summary>
  60. /// <param name="index">hand index</param>
  61. /// <returns> 0:lefthand 1:righthand</returns>
  62. public static int GetTrackingHandLrHand(int index)
  63. {
  64. if (Utils.IsAndroidPlatfrom())
  65. return getTrackingHandLrHand(index);
  66. return 0;
  67. }
  68. /// <summary>
  69. /// Retrieve the type of tracked gestures.
  70. /// </summary>
  71. /// <param name="index"></param>
  72. /// <returns></returns>
  73. public static int GetTrackingGestureType(int index)
  74. {
  75. if (Utils.IsAndroidPlatfrom())
  76. return getTrackingGestureType(index);
  77. return 0;
  78. }
  79. /// <summary>
  80. /// Retrieve the type of tracked gestures.
  81. /// When there is a conflict between "grip" and "pinch" in the combine type, prioritize selecting "grip."
  82. /// </summary>
  83. /// <param name="index"></param>
  84. /// <returns></returns>
  85. public static int GetTrackingHandCombineGestureType(int index)
  86. {
  87. if (Utils.IsAndroidPlatfrom())
  88. return getTrackingHandCombineGestureType(index);
  89. return 0;
  90. }
  91. /// <summary>
  92. /// Retrieve the skeleton information in camera space.
  93. /// </summary>
  94. /// <param name="skeletonCAM"></param>
  95. /// <param name="index"></param>
  96. public static void GetTrackingHandSkeletonCAM(float[] skeletonCAM, int index)
  97. {
  98. if (Utils.IsAndroidPlatfrom())
  99. getTrackingHandSkeletonCAM(skeletonCAM, index);
  100. }
  101. /// <summary>
  102. /// Retrieve the skeleton information in NDC (Normalized Device Coordinates) space.
  103. /// </summary>
  104. /// <param name="skeletonNDC"></param>
  105. /// <param name="index"></param>
  106. public static void GetTrackingHandSkeletonNDC(float[] skeletonNDC, int index)
  107. {
  108. if (Utils.IsAndroidPlatfrom())
  109. getTrackingHandSkeletonNDC(skeletonNDC, index);
  110. }
  111. /// <summary>
  112. /// Retrieve the mesh points of the hand in NDC (Normalized Device Coordinates) space.
  113. /// </summary>
  114. /// <param name="vertsNDC"></param>
  115. /// <param name="index"></param>
  116. public static void GetTrackingHandVertsNDC(float[] vertsNDC, int index)
  117. {
  118. if (Utils.IsAndroidPlatfrom())
  119. getTrackingHandVertsNDC(vertsNDC, index);
  120. }
  121. /// <summary>
  122. /// Retrieve the mesh points of the hand in camera space.
  123. /// </summary>
  124. /// <param name="vertsCAM"></param>
  125. /// <param name="index"></param>
  126. public static void GetTrackingHandVertsCAM(float[] vertsCAM, int index)
  127. {
  128. if (Utils.IsAndroidPlatfrom())
  129. getTrackingHandVertsCAM(vertsCAM, index);
  130. }
  131. /// <summary>
  132. /// Retrieve the rotation of the hand as a quaternion.
  133. /// </summary>
  134. /// <param name="rotation">quaternion</param>
  135. /// <param name="index">hand index</param>
  136. public static void GetTrackingHandRootRotation(float[] rotation, int index)
  137. {
  138. if (Utils.IsAndroidPlatfrom())
  139. getTrackingHandRootRotation(rotation, index);
  140. }
  141. /// <summary>
  142. /// Retrieve the type of palm and back of the hand.
  143. /// </summary>
  144. /// <param name="index">hand index</param>
  145. /// <returns></returns>
  146. public static int GetTrackingHandOrientation(int index)
  147. {
  148. if (Utils.IsAndroidPlatfrom())
  149. return getTrackingHandOrientation(index);
  150. return 0;
  151. }
  152. /// <summary>
  153. /// Retrieve the coordinate axes of the hand in camera space.
  154. /// </summary>
  155. /// <param name="axis"></param>
  156. /// <param name="index"></param>
  157. public static void GetTrackingHandRootRotationAxisCAM(float[] axis, int index)
  158. {
  159. if (Utils.IsAndroidPlatfrom())
  160. getTrackingHandRootRotationAxisCAM(axis, index);
  161. }
  162. /// <summary>
  163. /// Retrieve the hand velocity tracking.
  164. /// </summary>
  165. /// <param name="data"></param>
  166. /// <param name="index"></param>
  167. // public static void GetTrackingHandVelocity(float[] data, int index)
  168. // {
  169. // if (Utils.IsAndroidPlatfrom())
  170. // getTrackingHandVelocity(data, index);
  171. // }
  172. /// <summary>
  173. /// Retrieve the timestamp of the gesture image moment.
  174. /// </summary>
  175. /// <returns></returns>
  176. public static long GetCurrentFrameTimeStamp()
  177. {
  178. if (Utils.IsAndroidPlatfrom())
  179. return getCurrentFrameTimeStamp();
  180. return 0;
  181. }
  182. /// <summary>
  183. /// Retrieve the timestamp of the completed gesture image processing.
  184. /// </summary>
  185. /// <returns></returns>
  186. public static long GetFinishProcessTimeStamp()
  187. {
  188. if (Utils.IsAndroidPlatfrom())
  189. return GetFinishProcessTimeStamp();
  190. return 0;
  191. }
  192. /// <summary>
  193. /// Set the tracking count for hands.
  194. /// </summary>
  195. /// <param name="maxHandNum"></param>
  196. public static void SetMaxHandNum(int maxHandNum)
  197. {
  198. if (Utils.IsAndroidPlatfrom())
  199. setMaxHandNum(maxHandNum);
  200. }
  201. /// <summary>
  202. /// Enable DSP
  203. /// <param name = "useDsp" >
  204. /// 0 means neither detection nor tracking DSP is enabled
  205. /// 1 means detection is enabled, but tracking is disabled.
  206. /// 2 means detection is disabled, but tracking is enabled.
  207. /// 3 means both detection and tracking are enabled.
  208. /// </ param >
  209. /// </summary>
  210. public static void SetUseDsp(int useDsp)
  211. {
  212. if (Utils.IsAndroidPlatfrom())
  213. setUseDsp(useDsp);
  214. }
  215. /// <summary>
  216. /// Enable fisheye distortion correction
  217. /// </summary>
  218. /// <param name="useFishEyeDistort">,0-false,1-true</param>
  219. public static void SetUseFishEyeDistort(int useFishEyeDistort)
  220. {
  221. if (Utils.IsAndroidPlatfrom())
  222. setUseFishEyeDistort(useFishEyeDistort);
  223. }
  224. /// <summary>
  225. /// Retrieve skeleton rotation data
  226. /// </summary>
  227. /// <param name="data"></param>
  228. /// <param name="index">hand index</param>
  229. /// <param name="type">0-matrix(21*9),1-quaternion(21*4),2-euler(21*3</param>
  230. public static void GetTrackingHandSkeletonRotationAll(float[] data, int index, int type)
  231. {
  232. if (Utils.IsAndroidPlatfrom())
  233. getTrackingHandSkeletonRotationAll(data, index, type);
  234. }
  235. /// <summary>
  236. /// Set gesture loglevel
  237. /// </summary>
  238. /// <param name="logLevel"> "debug", "info", "warn", "err", "fatal", "none"</param>
  239. public static void SetGestureLogLevel(string logLevel)
  240. {
  241. if (Utils.IsAndroidPlatfrom())
  242. {
  243. setGestureLogLevel(logLevel);
  244. }
  245. }
  246. /// <summary>
  247. /// It is physical camera pose
  248. /// </summary>
  249. /// <param name="timestamp"></param>
  250. /// <returns></returns>
  251. [Obsolete("Only gesture use")]
  252. public static Pose GetHeadPoseForGes(long timestamp)
  253. {
  254. Pose pose = Pose.identity;
  255. if (Utils.IsAndroidPlatfrom())
  256. {
  257. getHistoryHeadPosePysRHS(timestamp, position, rotation);
  258. pose.position = new Vector3(position[0], position[1], -position[2]);
  259. pose.rotation = new Quaternion(-rotation[0], -rotation[1], rotation[2], rotation[3]);
  260. }
  261. return pose;
  262. }
  263. /// <summary>
  264. /// Get upforward influencePow
  265. /// </summary>
  266. /// <returns></returns>
  267. public static float GetUpForwardInfluencePow()
  268. {
  269. if (Utils.IsAndroidPlatfrom())
  270. return getUpForwardInfluencePow();
  271. return 0;
  272. }
  273. #region NativeInterface
  274. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  275. static extern void openGestureTracker();
  276. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  277. static extern void closeGestureTracker();
  278. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  279. static extern int getTrackingHandVertsNum();
  280. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  281. static extern int getTrackingHandSkeletonNum();
  282. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  283. static extern int getTrackingHandNum();
  284. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  285. static extern int getTrackingHandLrHand(int index);
  286. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  287. static extern int getTrackingGestureType(int index);
  288. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  289. static extern int getTrackingHandCombineGestureType(int index);
  290. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  291. static extern void getTrackingHandSkeletonCAM(float[] skeletonCAM, int index);
  292. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  293. static extern void getTrackingHandVertsNDC(float[] vertsNDC, int index);
  294. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  295. static extern void getTrackingHandVertsCAM(float[] vertsCAM, int index);
  296. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  297. static extern void getTrackingHandSkeletonNDC(float[] skeletonNDC, int index);
  298. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  299. static extern void getTrackingHandRootRotation(float[] rotation, int index);
  300. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  301. static extern int getTrackingHandOrientation(int index);
  302. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  303. static extern void getTrackingHandRootRotationAxisCAM(float[] axis, int index);
  304. [DllImport(ApiConstants.UXR_GFX_PLUGIN), Obsolete]
  305. static extern void getTrackingHandStableAnchorPoint(float[] stableAnchorPoint, int index);
  306. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  307. static extern void getTrackingHandSkeletonRotationAll(float[] data, int index, int type);
  308. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  309. static extern void getTrackingHandVelocity(float[] data, int index);
  310. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  311. static extern long getCurrentFrameTimeStamp();
  312. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  313. static extern long getFinishProcessTimeStamp();
  314. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  315. static extern void setMaxHandNum(int maxHandNum);
  316. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  317. static extern void setUseDsp(int useDsp);
  318. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  319. static extern void setUseFishEyeDistort(int useFishEyeDistort);
  320. [DllImport(ApiConstants.UXR_GFX_PLUGIN, CharSet = CharSet.Ansi)]
  321. static extern void setGestureLogLevel(string logLevel);
  322. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  323. static extern void getHistoryHeadPosePysRHS(long timestamp, float[] position, float[] orientation);
  324. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  325. static extern float getUpForwardInfluencePow();
  326. #region OPEN_GL_INTERFACE
  327. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  328. static extern void getTrackingHandVertsCAM_GLAxis(float[] data, int index);
  329. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  330. static extern void getTrackingHandSkeletonCAM_GLAxis(float[] data, int index);
  331. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  332. static extern void getTrackingHandRootRotation_GLAxis(float[] data, int index);
  333. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  334. static extern void getTrackingHandRootRotationEuler_GLAxis(float[] data, int index);
  335. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  336. static extern void getTrackingHandRootRotationAxisCAM_GLAxis(float[] data, int index);
  337. [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
  338. static extern void getTrackingHandSkeletonRotationAll_GLAxis(float[] data, int index, int type);
  339. #endregion
  340. #endregion
  341. }
  342. }
  343. }