PXR_MotionTracking.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. /*******************************************************************************
  2. Copyright © 2015-2022 PICO Technology Co., Ltd.All rights reserved.
  3. NOTICE:All information contained herein is, and remains the property of
  4. PICO Technology Co., Ltd. The intellectual and technical concepts
  5. contained herein are proprietary to PICO Technology Co., Ltd. and may be
  6. covered by patents, patents in process, and are protected by trade secret or
  7. copyright law. Dissemination of this information or reproduction of this
  8. material is strictly forbidden unless prior written permission is obtained from
  9. PICO Technology Co., Ltd.
  10. *******************************************************************************/
  11. using System.Runtime.InteropServices;
  12. namespace Unity.XR.PXR
  13. {
  14. /// <summary>
  15. /// The codes that indicates the state of motion tracking features.
  16. /// </summary>
  17. public enum TrackingStateCode
  18. {
  19. /// <summary>
  20. /// Request succeeded.
  21. /// </summary>
  22. PXR_MT_SUCCESS = 0,
  23. /// <summary>
  24. /// Request failed.
  25. /// </summary>
  26. PXR_MT_FAILURE = -1,
  27. /// <summary>
  28. /// Invalid mode.
  29. /// </summary>
  30. PXR_MT_MODE_NONE = -2,
  31. /// <summary>
  32. /// The current device does not support this feature.
  33. /// </summary>
  34. PXR_MT_DEVICE_NOT_SUPPORT = -3,
  35. /// <summary>
  36. /// This feature is not started.
  37. /// </summary>
  38. PXR_MT_SERVICE_NEED_START = -4,
  39. /// <summary>
  40. /// Eye tracking permission denied.
  41. /// </summary>
  42. PXR_MT_ET_PERMISSION_DENIED = -5,
  43. /// <summary>
  44. /// Face tracking permission denied.
  45. /// </summary>
  46. PXR_MT_FT_PERMISSION_DENIED = -6,
  47. /// <summary>
  48. /// Microphone permission denied.
  49. /// </summary>
  50. PXR_MT_MIC_PERMISSION_DENIED = -7,
  51. /// <summary>
  52. /// (Reserved)
  53. /// </summary>
  54. PXR_MT_SYSTEM_DENIED = -8,
  55. /// <summary>
  56. /// Unknown error.
  57. /// </summary>
  58. PXR_MT_UNKNOW_ERROR = -9
  59. }
  60. #region Eye Tracking
  61. /// <summary>
  62. /// Eye tracking modes.
  63. /// </summary>
  64. public enum EyeTrackingMode
  65. {
  66. /// <summary>
  67. /// To disable eye tracking.
  68. /// </summary>
  69. PXR_ETM_NONE = -1,
  70. /// <summary>
  71. /// To enable eye tracking.
  72. /// </summary>
  73. PXR_ETM_BOTH = 0,
  74. /// <summary>
  75. /// (Reserved)
  76. /// </summary>
  77. PXR_ETM_COUNT = 1
  78. }
  79. public enum PerEyeUsage
  80. {
  81. LeftEye = 0,
  82. RightEye = 1,
  83. Combined = 2,
  84. EyeCount = 3
  85. }
  86. /// <summary>
  87. /// Eye tracking data flags.
  88. /// </summary>
  89. public enum EyeTrackingDataGetFlags : long
  90. {
  91. /// <summary>
  92. /// Do not return any data.
  93. /// </summary>
  94. PXR_EYE_DEFAULT = 0,
  95. /// <summary>
  96. /// To return the positions of both eyes.
  97. /// </summary>
  98. PXR_EYE_POSITION = 1 << 0,
  99. /// <summary>
  100. /// To return the orientations of both eyes.
  101. /// </summary>
  102. PXR_EYE_ORIENTATION = 1 << 1
  103. }
  104. /// <summary>
  105. /// The information to pass for starting eye tracking. This information remains effective during the period when eye tracking is enabled.
  106. /// </summary>
  107. public struct EyeTrackingStartInfo
  108. {
  109. private int apiVersion;
  110. /// <summary>
  111. /// Whether the app needs eye tracking calibration.
  112. /// * `0`: needs
  113. /// * `1`: does not need
  114. /// </summary>
  115. public byte needCalibration;
  116. /// <summary>
  117. /// Select an eye tracking mode for the app. Refer to the `EyeTrackingMode` enum for details.
  118. /// </summary>
  119. public EyeTrackingMode mode;
  120. public void SetVersion(int version)
  121. {
  122. apiVersion = version;
  123. }
  124. public override string ToString()
  125. {
  126. return string.Format("apiVersion :{0}, needCalibration:{1}, mode:{2}", apiVersion, needCalibration, mode);
  127. }
  128. }
  129. public struct EyeTrackingStopInfo
  130. {
  131. private int apiVersion;
  132. public void SetVersion(int version)
  133. {
  134. apiVersion = version;
  135. }
  136. public override string ToString()
  137. {
  138. return string.Format("apiVersion :{0}", apiVersion);
  139. }
  140. }
  141. /// <summary>
  142. /// Information about the state of eye tracking.
  143. /// </summary>
  144. public struct EyeTrackingState
  145. {
  146. private int apiVersion;
  147. /// <summary>
  148. /// Eye tracking mode. Refer to the `EyeTrackingMode` enum for details.
  149. /// </summary>
  150. public EyeTrackingMode currentTrackingMode;
  151. /// <summary>
  152. /// The state code of eye tracking. Refer to the `TrackingStateCode` enum for details.
  153. /// </summary>
  154. public TrackingStateCode code;
  155. public void SetVersion(int version)
  156. {
  157. apiVersion = version;
  158. }
  159. public override string ToString()
  160. {
  161. return string.Format("apiVersion :{0}, currentTrackingMode:{1}, code:{2}", apiVersion, currentTrackingMode, code);
  162. }
  163. }
  164. /// <summary>
  165. /// The information to pass for getting eye tracking data. Should be called at every frame when you need to update eye tracking data.
  166. /// </summary>
  167. public struct EyeTrackingDataGetInfo
  168. {
  169. private int apiVersion;
  170. /// <summary>
  171. /// Reserved. Pass `0`.
  172. /// </summary>
  173. public long displayTime;
  174. /// <summary>
  175. /// Specifies what eye tracking data to return. Refer to the `EyeTrackingDataGetFlags` enum for details.
  176. /// </summary>
  177. public EyeTrackingDataGetFlags flags;
  178. public void SetVersion(int version)
  179. {
  180. apiVersion = version;
  181. }
  182. public override string ToString()
  183. {
  184. return string.Format("apiVersion :{0}, displayTime:{1}, flags:{2}", apiVersion, displayTime, flags);
  185. }
  186. }
  187. /// <summary>
  188. /// The data of the eye.
  189. /// </summary>
  190. public struct PerEyeData
  191. {
  192. private int apiVersion;
  193. /// <summary>
  194. /// The pose (postion and orientation) of the eye.
  195. /// </summary>
  196. public Posef pose;
  197. /// <summary>
  198. /// Whether the pose data is valid.
  199. /// </summary>
  200. public byte isPoseValid;
  201. /// <summary>
  202. /// The openness of the eye, which is a float value ranges from `0.0` to `1.0`. `0.0` indicates completely closed, `1.0` indicates completely open.
  203. /// </summary>
  204. public float openness;
  205. /// <summary>
  206. /// Whether the openness value is valid.
  207. /// </summary>
  208. public byte isOpennessValid;
  209. public void SetVersion(int version)
  210. {
  211. apiVersion = version;
  212. }
  213. public override string ToString()
  214. {
  215. return string.Format("apiVersion :{0}, pose:{1}, isPoseValid:{2}, openness:{3}, isOpennessValid:{4}", apiVersion, pose, isPoseValid, openness, isOpennessValid);
  216. }
  217. }
  218. /// <summary>
  219. /// Eye tracking data.
  220. /// </summary>
  221. public struct EyeTrackingData
  222. {
  223. private int apiVersion;
  224. [MarshalAs(UnmanagedType.ByValArray, SizeConst = (int)PerEyeUsage.EyeCount)]
  225. /// <summary>
  226. /// Eye data. Index `0`: left eye. Index `1`: right eye. Index `2`: combined eyes (left and right eyes).
  227. /// @note Currently, only index `2` returns data.
  228. /// </summary>
  229. public PerEyeData[] eyeDatas;
  230. public void SetVersion(int version)
  231. {
  232. apiVersion = version;
  233. }
  234. public override string ToString()
  235. {
  236. return string.Format("apiVersion :{0},\n eyeDatas[0]:{1},\n eyeDatas[1]:{2},\n eyeDatas[2]:{3}", apiVersion, eyeDatas[0], eyeDatas[1], eyeDatas[2]);
  237. }
  238. }
  239. /// <summary>
  240. /// The information about the pupils of both eyes.
  241. /// </summary>
  242. [StructLayout(LayoutKind.Sequential)]
  243. public unsafe struct EyePupilInfo
  244. {
  245. /// <summary>
  246. /// The diameter (unit: pixels) of the left eye's pupil.
  247. /// </summary>
  248. public float leftEyePupilDiameter;
  249. /// <summary>
  250. /// The diameter (unit: pixels) of the right eye's pupil.
  251. /// </summary>
  252. public float rightEyePupilDiameter;
  253. /// <summary>
  254. /// The position of the left eye's pupil.
  255. /// </summary>
  256. public fixed float leftEyePupilPosition[2];
  257. /// <summary>
  258. /// The position of the right eye's pupil.
  259. /// </summary>
  260. public fixed float rightEyePupilPosition[2];
  261. public override string ToString()
  262. {
  263. string str = string.Format("leftEyePupilDiameter :{0}, rightEyePupilDiameter:{1}", leftEyePupilDiameter.ToString("F6"), rightEyePupilDiameter.ToString("F6"));
  264. for (int i = 0; i < 2; i++)
  265. {
  266. str += string.Format("\nleftEyePupilPosition[{0}] :{1}", i, leftEyePupilPosition[i].ToString("F6"));
  267. str += string.Format(" rightEyePupilPosition[{0}] :{1}", i, rightEyePupilPosition[i].ToString("F6"));
  268. }
  269. return str;
  270. }
  271. }
  272. #endregion
  273. #region Face Tracking
  274. /// <summary>
  275. /// Face tracking modes.
  276. /// </summary>
  277. public enum FaceTrackingSupportedMode
  278. {
  279. /// <summary>
  280. /// No face tracking.
  281. /// </summary>
  282. PXR_FTM_NONE = -1,
  283. /// <summary>
  284. /// Face tracking only (without lipsync).
  285. /// </summary>
  286. PXR_FTM_FACE = 0,
  287. /// <summary>
  288. /// Lipsync only.
  289. /// </summary>
  290. PXR_FTM_LIPS = 1,
  291. /// <summary>
  292. /// Hybrid mode. Enable both face tracking and lipsync. The lip data's output format is viseme.
  293. /// </summary>
  294. PXR_FTM_FACE_LIPS_VIS = 2,
  295. /// <summary>
  296. /// Hybrid mode. Enable both face tracking and lipsync. The lip data's output format is blendshape.
  297. /// </summary>
  298. PXR_FTM_FACE_LIPS_BS = 3,
  299. /// <summary>
  300. /// (Reserved)
  301. /// </summary>
  302. PXR_FTM_COUNT = 4
  303. }
  304. /// <summary>
  305. /// Specifies the face tracking data to return.
  306. /// </summary>
  307. public enum FaceTrackingDataGetFlags : long
  308. {
  309. /// <summary>
  310. /// To return all types of face tracking data.
  311. /// </summary>
  312. PXR_FACE_DEFAULT = 0,
  313. }
  314. /// <summary>
  315. /// The information to pass for starting eye tracking.
  316. /// </summary>
  317. public struct FaceTrackingStartInfo
  318. {
  319. private int apiVersion;
  320. /// <summary>
  321. /// The face tracking mode to enable. Refer to the `FaceTrackingSupportedMode` enum for details.
  322. /// </summary>
  323. public FaceTrackingSupportedMode mode;
  324. public void SetVersion(int version)
  325. {
  326. apiVersion = version;
  327. }
  328. public override string ToString()
  329. {
  330. return string.Format("apiVersion :{0}, mode:{1}", apiVersion, mode);
  331. }
  332. }
  333. /// <summary>
  334. /// The information to pass for stopping face tracking.
  335. /// </summary>
  336. public struct FaceTrackingStopInfo
  337. {
  338. private int apiVersion;
  339. /// <summary>
  340. /// Determines whether to pause face tracking.
  341. /// * `0`: pause
  342. /// * `1`: do not pause, directly stop face tracking
  343. /// </summary>
  344. public byte pause;
  345. public void SetVersion(int version)
  346. {
  347. apiVersion = version;
  348. }
  349. public override string ToString()
  350. {
  351. return string.Format("apiVersion :{0}, pause:{1}", apiVersion, pause);
  352. }
  353. }
  354. /// <summary>
  355. /// Information about the state of face tracking.
  356. /// </summary>
  357. public struct FaceTrackingState
  358. {
  359. private int apiVersion;
  360. /// <summary>
  361. /// The face tracking mode of the app. Refer to the `FaceTrackingSupportedMode` enum for details.
  362. /// </summary>
  363. public FaceTrackingSupportedMode currentTrackingMode;
  364. /// <summary>
  365. /// Face tracking state code. Refer to the `TrackingStateCode` enum for details.
  366. /// </summary>
  367. public TrackingStateCode code;
  368. public void SetVersion(int version)
  369. {
  370. apiVersion = version;
  371. }
  372. public override string ToString()
  373. {
  374. return string.Format("apiVersion :{0}, currentTrackingMode:{1}, code:{2}", apiVersion, currentTrackingMode, code);
  375. }
  376. }
  377. /// <summary>
  378. /// The information to pass for getting face tracking data.
  379. /// </summary>
  380. public struct FaceTrackingDataGetInfo
  381. {
  382. private int apiVersion;
  383. /// <summary>
  384. /// Reserved. Pass `0`.
  385. /// </summary>
  386. public long displayTime;
  387. public void SetVersion(int version)
  388. {
  389. apiVersion = version;
  390. }
  391. public FaceTrackingDataGetFlags flags;
  392. public override string ToString()
  393. {
  394. return string.Format("apiVersion :{0}, displayTime:{1}, flags:{2}", apiVersion, displayTime, flags);
  395. }
  396. }
  397. /// <summary>
  398. /// Face tracking data.
  399. /// </summary>
  400. public unsafe struct FaceTrackingData
  401. {
  402. private int apiVersion;
  403. /// <summary>
  404. /// A float* value, the length must be 72. Refer to `BlendShapeIndex` for the definition of each value.
  405. /// </summary>
  406. public float* blendShapeWeight;
  407. /// <summary>
  408. /// The timestamp for the current data.
  409. /// </summary>
  410. public long timestamp;
  411. /// <summary>
  412. /// The laughing prob is a float ranging from `0` to `1`.
  413. /// </summary>
  414. public float laughingProb;
  415. /// <summary>
  416. /// Whether the data of the eye area is valid.
  417. /// </summary>
  418. public byte eyeValid;
  419. /// <summary>
  420. /// Whether the data of the face area is valid.
  421. /// </summary>
  422. public byte faceValid;
  423. public void SetVersion(int version)
  424. {
  425. apiVersion = version;
  426. }
  427. public override string ToString()
  428. {
  429. string str = string.Format("apiVersion :{0}, timestamp:{1}, laughingProb:{2}, eyeValid:{3}, faceValid:{4}\n", apiVersion, timestamp, laughingProb, eyeValid, faceValid);
  430. for (int i = 0; i < 72; i++)
  431. {
  432. str += string.Format(" blendShapeWeight[{0}]:{1}", i, blendShapeWeight[i].ToString("F6"));
  433. }
  434. return str;
  435. }
  436. }
  437. #endregion
  438. public class PXR_MotionTracking
  439. {
  440. //Eye Tracking
  441. public const int PXR_EYE_TRACKING_API_VERSION = 1;
  442. /// <summary>
  443. /// Wants eye tracking service for the current app.
  444. /// </summary>
  445. /// <returns>Returns `0` for success and other values for failure.</returns>
  446. public static int WantEyeTrackingService()
  447. {
  448. return PXR_Plugin.MotionTracking.UPxr_WantEyeTrackingService();
  449. }
  450. /// <summary>
  451. /// Gets whether the current device supports eye tracking.
  452. /// </summary>
  453. /// <param name="supported">
  454. /// Returns a bool indicating whether eye tracking is supported:
  455. /// * `true`: supported
  456. /// * `false`: not supported
  457. /// </param>
  458. /// <param name="supportedModesCount">
  459. /// Returns the number of eye tracking modes supported by the current device.
  460. /// </param>
  461. /// <param name="supportedModes">
  462. /// Returns the eye tracking modes supported by the current device.
  463. /// </param>
  464. /// <returns>Returns `0` for success and other values for failure.</returns>
  465. public static int GetEyeTrackingSupported(ref bool supported, ref int supportedModesCount, ref EyeTrackingMode supportedModes)
  466. {
  467. return PXR_Plugin.MotionTracking.UPxr_GetEyeTrackingSupported(ref supported, ref supportedModesCount, ref supportedModes);
  468. }
  469. /// <summary>
  470. /// Starts eye tracking.
  471. /// @note Supported by PICO Neo3 Pro Eye, PICO 4 Pro, and PICO 4 Enterprise.
  472. /// </summary>
  473. /// <param name="startInfo">Passes the information for starting eye tracking.
  474. /// </param>
  475. /// <returns>Returns `0` for success and other values for failure.</returns>
  476. public static int StartEyeTracking(ref EyeTrackingStartInfo startInfo)
  477. {
  478. startInfo.SetVersion(PXR_EYE_TRACKING_API_VERSION);
  479. return PXR_Plugin.MotionTracking.UPxr_StartEyeTracking1(ref startInfo);
  480. }
  481. /// <summary>
  482. /// Stops eye tracking.
  483. /// @note Supported by PICO Neo3 Pro Eye, PICO 4 Pro, and PICO 4 Enterprise.
  484. /// </summary>
  485. /// <param name="stopInfo">Passes the information for stopping eye tracking. Currently, you do not need to pass anything.</param>
  486. /// <returns>Returns `0` for success and other values for failure.</returns>
  487. public static int StopEyeTracking(ref EyeTrackingStopInfo stopInfo)
  488. {
  489. stopInfo.SetVersion(PXR_EYE_TRACKING_API_VERSION);
  490. return PXR_Plugin.MotionTracking.UPxr_StopEyeTracking1(ref stopInfo);
  491. }
  492. /// <summary>
  493. /// Gets the state of eye tracking.
  494. /// @note Supported by PICO Neo3 Pro Eye, PICO 4 Pro, and PICO 4 Enterprise.
  495. /// </summary>
  496. /// <param name="isTracking">Returns a bool that indicates whether eye tracking is working:
  497. /// * `true`: eye tracking is working
  498. /// * `false`: eye tracking has been stopped
  499. /// </param>
  500. /// <param name="state">Returns the eye tracking state information, including the eye tracking mode and eye tracking state code.</param>
  501. /// <returns>Returns `0` for success and other values for failure.</returns>
  502. public static int GetEyeTrackingState(ref bool isTracking, ref EyeTrackingState state)
  503. {
  504. state.SetVersion(PXR_EYE_TRACKING_API_VERSION);
  505. return PXR_Plugin.MotionTracking.UPxr_GetEyeTrackingState(ref isTracking, ref state);
  506. }
  507. /// <summary>
  508. /// Gets eye tracking data.
  509. /// @note Supported by PICO Neo3 Pro Eye, PICO 4 Pro, and PICO 4 Enterprise.
  510. /// </summary>
  511. /// <param name="getInfo">Specifies the eye tracking data you want.</param>
  512. /// <param name="data">Returns the desired eye tracking data.</param>
  513. /// <returns>Returns `0` for success and other values for failure.</returns>
  514. public static int GetEyeTrackingData(ref EyeTrackingDataGetInfo getInfo, ref EyeTrackingData data)
  515. {
  516. getInfo.SetVersion(PXR_EYE_TRACKING_API_VERSION);
  517. data.SetVersion(PXR_EYE_TRACKING_API_VERSION);
  518. return PXR_Plugin.MotionTracking.UPxr_GetEyeTrackingData1(ref getInfo, ref data);
  519. }
  520. //PICO4E
  521. /// <summary>
  522. /// Gets the opennesses of the left and right eyes.
  523. /// @note
  524. /// - Supported by PICO 4 Enterprise.
  525. /// - To use this API, you need to add '<meta-data android:name="pvr.app.et_tob_advance" android:value="true"/>' to the app's AndroidManifest file.
  526. /// </summary>
  527. /// <param name="leftEyeOpenness">The openness of the left eye, which is a float value ranges from `0.0` to `1.0`. `0.0` indicates completely closed, `1.0` indicates completely open.</param>
  528. /// <param name="rightEyeOpenness">The openness of the right eye, which is a float value ranges from `0.0` to `1.0`. `0.0` indicates completely closed, `1.0` indicates completely open.</param>
  529. /// <returns>Returns `0` for success and other values for failure.</returns>
  530. public static int GetEyeOpenness(ref float leftEyeOpenness, ref float rightEyeOpenness)
  531. {
  532. return PXR_Plugin.MotionTracking.UPxr_GetEyeOpenness(ref leftEyeOpenness, ref rightEyeOpenness);
  533. }
  534. /// <summary>
  535. /// Gets the information about the pupils of both eyes.
  536. /// @note
  537. /// - Supported by PICO 4 Enterprise.
  538. /// - To use this API, you need to add '<meta-data android:name="pvr.app.et_tob_advance" android:value="true"/>' to the app's AndroidManifest file.
  539. /// </summary>
  540. /// <param name="eyePupilPosition">Returns the diameters and positions of both pupils.</param>
  541. /// <returns>Returns `0` for success and other values for failure.</returns>
  542. public static int GetEyePupilInfo(ref EyePupilInfo eyePupilPosition)
  543. {
  544. return PXR_Plugin.MotionTracking.UPxr_GetEyePupilInfo(ref eyePupilPosition);
  545. }
  546. /// <summary>
  547. /// Gets the poses of the left and right eyes.
  548. /// @note
  549. /// - Supported by PICO 4 Enterprise.
  550. /// - To use this API, you need to add '<meta-data android:name="pvr.app.et_tob_advance" android:value="true"/>' to the app's AndroidManifest file.
  551. /// </summary>
  552. /// <param name="timestamp">Returns the timestamp (unit: nanosecond) of the eye pose information.</param>
  553. /// <param name="leftEyePose">Returns the position and rotation of the left eye.</param>
  554. /// <param name="rightPose">Returns the position and rotation of the right eye.</param>
  555. /// <returns>Returns `0` for success and other values for failure.</returns>
  556. public static int GetPerEyePose(ref long timestamp, ref Posef leftEyePose, ref Posef rightPose)
  557. {
  558. return PXR_Plugin.MotionTracking.UPxr_GetPerEyePose(ref timestamp, ref leftEyePose, ref rightPose);
  559. }
  560. /// <summary>
  561. /// Gets whether the left and right eyes blinked.
  562. /// @note
  563. /// - Supported by PICO 4 Enterprise.
  564. /// - To use this API, you need to add '<meta-data android:name="pvr.app.et_tob_advance" android:value="true"/>' to the app's AndroidManifest file.
  565. /// </summary>
  566. /// <param name="timestamp">Returns the timestamp (unit: nanosecond) of the eye blink information.</param>
  567. /// <param name="isLeftBlink">Returns whether the left eye blinked:
  568. /// * `true`: blinked (the user's left eye is closed, which will usually open again immediately to generate a blink event)
  569. /// * `false`: didn't blink (the user's left eye is open)
  570. /// </param>
  571. /// <param name="isRightBlink">Returns whether the right eye blined:
  572. /// * `true`: blinked (the user's right eye is closed, which will usually open again immediately to generate a blink event)
  573. /// * `false`: didn't blink (the user's right eye is open)
  574. /// </param>
  575. /// <returns>Returns `0` for success and other values for failure.</returns>
  576. public static int GetEyeBlink(ref long timestamp, ref bool isLeftBlink, ref bool isRightBlink)
  577. {
  578. return PXR_Plugin.MotionTracking.UPxr_GetEyeBlink(ref timestamp, ref isLeftBlink, ref isRightBlink);
  579. }
  580. //Face Tracking
  581. public const int PXR_FACE_TRACKING_API_VERSION = 1;
  582. /// <summary>
  583. /// Wants face tracking service for the current app.
  584. /// </summary>
  585. /// <returns>Returns `0` for success and other values for failure.</returns>
  586. public static int WantFaceTrackingService()
  587. {
  588. return PXR_Plugin.MotionTracking.UPxr_WantFaceTrackingService();
  589. }
  590. /// <summary>
  591. /// Gets whether the current device supports face tracking.
  592. /// </summary>
  593. /// <param name="supported">Indicates whether the device supports face tracking:
  594. /// * `true`: support
  595. /// * `false`: not support
  596. /// </param>
  597. /// <param name="supportedModesCount">Returns the total number of face tracking modes supported by the device.</param>
  598. /// <param name="supportedModes">Returns the specific face tracking modes supported by the device.</param>
  599. /// <returns>Returns `0` for success and other values for failure.</returns>
  600. public static int GetFaceTrackingSupported(ref bool supported, ref int supportedModesCount, ref FaceTrackingSupportedMode supportedModes)
  601. {
  602. return PXR_Plugin.MotionTracking.UPxr_GetFaceTrackingSupported(ref supported, ref supportedModesCount, ref supportedModes);
  603. }
  604. /// <summary>
  605. /// Starts face tracking.
  606. /// @note Supported by PICO 4 Pro and PICO 4 Enterprise.
  607. /// </summary>
  608. /// <param name="startInfo">Passes the information for starting face tracking.</param>
  609. /// <returns>Returns `0` for success and other values for failure.</returns>
  610. public static int StartFaceTracking(ref FaceTrackingStartInfo startInfo)
  611. {
  612. startInfo.SetVersion(PXR_FACE_TRACKING_API_VERSION);
  613. return PXR_Plugin.MotionTracking.UPxr_StartFaceTracking(ref startInfo);
  614. }
  615. /// <summary>
  616. /// Stops face tracking.
  617. /// @note Supported by PICO 4 Pro and PICO 4 Enterprise.
  618. /// </summary>
  619. /// <param name="stopInfo">Passes the information for stopping face tracking.</param>
  620. /// <returns>Returns `0` for success and other values for failure.</returns>
  621. public static int StopFaceTracking(ref FaceTrackingStopInfo stopInfo)
  622. {
  623. stopInfo.SetVersion(PXR_FACE_TRACKING_API_VERSION);
  624. return PXR_Plugin.MotionTracking.UPxr_StopFaceTracking(ref stopInfo);
  625. }
  626. /// <summary>
  627. /// Gets the state of face tracking.
  628. /// @note Supported by PICO 4 Pro and PICO 4 Enterprise.
  629. /// </summary>
  630. /// <param name="isTracking">Returns a bool indicating whether face tracking is working:
  631. /// * `true`: face tracking is working
  632. /// * `false`: face tracking has been stopped
  633. /// </param>
  634. /// <param name="state">Returns the state of face tracking, including the face tracking mode and face tracking state code.
  635. /// </param>
  636. /// <returns>Returns `0` for success and other values for failure.</returns>
  637. public static int GetFaceTrackingState(ref bool isTracking, ref FaceTrackingState state)
  638. {
  639. state.SetVersion(PXR_FACE_TRACKING_API_VERSION);
  640. return PXR_Plugin.MotionTracking.UPxr_GetFaceTrackingState(ref isTracking, ref state);
  641. }
  642. /// <summary>
  643. /// Gets face tracking data.
  644. /// @note Supported by PICO 4 Pro and PICO 4 Enterprise.
  645. /// </summary>
  646. /// <param name="getInfo">Specifies the face tracking data you want.</param>
  647. /// <param name="data">Returns the desired face tracking data.</param>
  648. /// <returns>Returns `0` for success and other values for failure.</returns>
  649. public static int GetFaceTrackingData(ref FaceTrackingDataGetInfo getInfo, ref FaceTrackingData data)
  650. {
  651. getInfo.SetVersion(PXR_FACE_TRACKING_API_VERSION);
  652. data.SetVersion(PXR_FACE_TRACKING_API_VERSION);
  653. return PXR_Plugin.MotionTracking.UPxr_GetFaceTrackingData1(ref getInfo, ref data);
  654. }
  655. }
  656. }
粤ICP备19079148号