PXR_System.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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;
  12. using System.Collections;
  13. using System.Collections.Generic;
  14. using UnityEngine;
  15. namespace Unity.XR.PXR
  16. {
  17. /// <summary>
  18. /// A callback function that notifies the change of input source. Returns one of the following values indicating the current input source:
  19. /// * `0`: HMD
  20. /// * `1`: controllers
  21. /// * `2`: hands (i.e., hand tracking)
  22. /// </summary>
  23. public delegate void InputDeviceChangedCallBack(int value);
  24. /// <summary>
  25. /// A callback function that notifies the change of seethrough state.
  26. /// * `0`: no seethrough
  27. /// * `1`: semi-transparent seethrough (e.g., the transition effect when entering seethrough in PICO Neo3 devices)
  28. /// * `2`: boundary and quick seethrough ('boundary' means that there is only the seethourgh scene visible after leaving the boundary)
  29. /// * `3`: background seethrough
  30. /// </summary>
  31. public delegate void SeethroughStateChangedCallBack(int value);
  32. /// <summary>
  33. /// A callback function that notifies the current connection status of PICO Motion Tracker and the number of motion trackers connected.
  34. /// For connection status, `0` indicates "disconnected" and `1` indicates "connected".
  35. /// </summary>
  36. public delegate void FitnessBandNumberOfConnectionsCallBack(int state, int value);
  37. /// <summary>
  38. /// A callback function that notifies calibration exceptions.
  39. /// The user then needs to recalibrate with PICO Motion Tracker.
  40. /// </summary>
  41. public delegate void FitnessBandAbnormalCalibrationDataCallBack(int state, int value);
  42. /// <summary>
  43. /// A callback function that notifies the battery of PICO Motion Traker.
  44. /// Value range: [0,5]. `0` indicates a low battery, which can affect the tracking accuracy.
  45. /// </summary>
  46. public delegate void FitnessBandElectricQuantityCallBack(int trackerID, int battery);
  47. /// <summary>
  48. /// A callback function that notifies the change of loglevel state.
  49. /// </summary>
  50. public delegate void LoglevelChangedCallBack(int value);
  51. public class PXR_System
  52. {
  53. /// <summary>
  54. /// Gets the SDK version.
  55. /// </summary>
  56. /// <returns>The SDK version.</returns>
  57. public static string GetSDKVersion()
  58. {
  59. return PXR_Plugin.System.UPxr_GetSDKVersion();
  60. }
  61. /// <summary>
  62. /// Gets the predicted time a frame will be displayed after being rendered.
  63. /// </summary>
  64. /// <returns>The predicted time (in miliseconds).</returns>
  65. public static double GetPredictedDisplayTime()
  66. {
  67. return PXR_Plugin.System.UPxr_GetPredictedDisplayTime();
  68. }
  69. /// <summary>
  70. /// Sets the extra latency mode. Note: Call this function once only.
  71. /// </summary>
  72. /// <param name="mode">The latency mode:
  73. /// * `0`: ExtraLatencyModeOff (Disable ExtraLatencyMode mode. This option will display the latest rendered frame for display)
  74. /// * `1`: ExtraLatencyModeOn (Enable ExtraLatencyMode mode. This option will display one frame prior to the latest rendered frame)
  75. /// * `2`: ExtraLatencyModeDynamic (Use system default setup)
  76. /// </param>
  77. /// <returns>Whether the extra latency mode has been set:
  78. /// * `true`: success
  79. /// * `false`: failure
  80. /// </returns>
  81. public static bool SetExtraLatencyMode(int mode)
  82. {
  83. return PXR_Plugin.System.UPxr_SetExtraLatencyMode(mode);
  84. }
  85. /// <summary>
  86. /// Gets the sensor's status.
  87. /// </summary>
  88. /// <returns>The sensor's status:
  89. /// * `0`: null
  90. /// * `1`: 3DoF
  91. /// * `3`: 6DoF
  92. /// </returns>
  93. public static int GetSensorStatus()
  94. {
  95. return PXR_Plugin.System.UPxr_GetSensorStatus();
  96. }
  97. /// <summary>
  98. /// Sets the system display frequency rate.
  99. /// </summary>
  100. /// <param name="rate">The frequency rate: `72`; `90`; `120`. Other values are invalid.</param>
  101. public static void SetSystemDisplayFrequency(float rate)
  102. {
  103. PXR_Plugin.System.UPxr_SetSystemDisplayFrequency(rate);
  104. }
  105. /// <summary>
  106. /// Gets the system display frequency rate.
  107. /// </summary>
  108. /// <returns>The system display frequency rate.</returns>
  109. public static float GetSystemDisplayFrequency()
  110. {
  111. return PXR_Plugin.System.UPxr_GetSystemDisplayFrequency();
  112. }
  113. /// <summary>
  114. /// Gets the predicted status of the sensor.
  115. /// </summary>
  116. /// <param name="sensorState">Sensor's coordinate:
  117. /// * `pose`: in-app coordinate
  118. /// * `globalPose`: global coordinate
  119. /// </param>
  120. /// <param name="sensorFrameIndex">Sensor frame index.</param>
  121. /// <returns>The predicted status of the sensor.</returns>
  122. public static int GetPredictedMainSensorStateNew(ref PxrSensorState2 sensorState, ref int sensorFrameIndex) {
  123. return PXR_Plugin.System.UPxr_GetPredictedMainSensorStateNew(ref sensorState, ref sensorFrameIndex);
  124. }
  125. public static int ContentProtect(int data) {
  126. return PXR_Plugin.System.UPxr_ContentProtect(data);
  127. }
  128. /// <summary>
  129. /// Enables/disables face tracking.
  130. /// @note Only supported by PICO 4 Pro and PICO 4 Enterprise.
  131. /// </summary>
  132. /// <param name="enable">Whether to enable/disable face tracking:
  133. /// * `true`: enable
  134. /// * `false`: disable
  135. /// </param>
  136. public static void EnableFaceTracking(bool enable) {
  137. PXR_Plugin.System.UPxr_EnableFaceTracking(enable);
  138. }
  139. /// <summary>
  140. /// Enables/disables lipsync.
  141. /// @note Only supported by PICO 4 Pro and PICO 4 Enterprise.
  142. /// </summary>
  143. /// <param name="enable">Whether to enable/disable lipsync:
  144. /// * `true`: enable
  145. /// * `false`: disable
  146. /// </param>
  147. public static void EnableLipSync(bool enable){
  148. PXR_Plugin.System.UPxr_EnableLipSync(enable);
  149. }
  150. /// <summary>
  151. /// Gets face tracking data.
  152. /// @note Only supported by PICO 4 Pro and PICO 4 Enterprise.
  153. /// </summary>
  154. /// <param name="ts">(Optional) A reserved parameter, pass `0`.</param>
  155. /// <param name="flags">The face tracking mode to retrieve data for. Enumertions:
  156. /// * `PXR_GET_FACE_DATA_DEFAULT` (invalid, only for making it compatible with older SDK version)
  157. /// * `PXR_GET_FACE_DATA`: face only
  158. /// * `PXR_GET_LIP_DATA`: lipsync only
  159. /// * `PXR_GET_FACELIP_DATA`: hybrid (both face and lipsync)
  160. /// </param>
  161. /// <param name="faceTrackingInfo">Returns the `PxrFaceTrackingInfo` struct that contains the following face tracking data:
  162. /// * `timestamp`: Int64, reserved field
  163. /// * `blendShapeWeight`: float[], pass `0`.
  164. /// * `videoInputValid`: float[], the input validity of the upper and lower parts of the face.
  165. /// * `laughingProb`: float[], the coefficient of laughter.
  166. /// * `emotionProb`: float[], the emotion factor.
  167. /// * `reserved`: float[], reserved field.
  168. /// </param>
  169. public static void GetFaceTrackingData(Int64 ts, GetDataType flags, ref PxrFaceTrackingInfo faceTrackingInfo) {
  170. PXR_Plugin.System.UPxr_GetFaceTrackingData( ts, (int)flags, ref faceTrackingInfo);
  171. }
  172. /// <summary>Sets a GPU or CPU level for the device.</summary>
  173. /// <param name="which">Choose to set a GPU or CPU level:
  174. /// * `CPU`
  175. /// * `GPU`
  176. /// </param>
  177. /// <param name="level">Select a level from the following:
  178. /// * `POWER_SAVINGS`: power-saving level
  179. /// * `SUSTAINED_LOW`: low level
  180. /// * `SUSTAINED_HIGH`: high level
  181. /// * `BOOST`: top-high level, be careful to use this level
  182. /// </param>
  183. /// <returns>
  184. /// * `0`: success
  185. /// * `1`: failure
  186. /// </returns>
  187. public static int SetPerformanceLevels(PxrPerfSettings which, PxrSettingsLevel level)
  188. {
  189. return PXR_Plugin.System.UPxr_SetPerformanceLevels(which, level);
  190. }
  191. /// <summary>Gets the device's GPU or CPU level.</summary>
  192. /// <param name="which">Choose to get GPU or CPU level:
  193. /// * `CPU`
  194. /// * `GPU`
  195. /// </param>
  196. /// <returns>
  197. /// Returns one of the following levels:
  198. /// * `POWER_SAVINGS`: power-saving level
  199. /// * `SUSTAINED_LOW`: low level
  200. /// * `SUSTAINED_HIGH`: high level
  201. /// * `BOOST`: top-high level, be careful to use this level
  202. /// </returns>
  203. public static PxrSettingsLevel GetPerformanceLevels(PxrPerfSettings which)
  204. {
  205. return PXR_Plugin.System.UPxr_GetPerformanceLevels(which);
  206. }
  207. /// <summary>Sets FOV in four directions (left, right, up, and down) for specified eye(s).</summary>
  208. /// <param name="eye">The eye to set FOV for:
  209. /// * `LeftEye`
  210. /// * `RightEye`
  211. /// * `BothEye`
  212. /// </param>
  213. /// <param name="fovLeft">The horizontal FOV (in degrees) for the left part of the eye, for example, `47.5`.</param>
  214. /// <param name="fovRight">The horizontal FOV (in degrees) for the right part of the eye..</param>
  215. /// <param name="fovUp">The vertical FOV (in degrees) for the upper part of the eye.</param>
  216. /// <param name="fovDown">The vertical FOV (in degrees) for the lower part of the eye.</param>
  217. /// <returns>
  218. /// * `0`: success
  219. /// * `1`: failure
  220. /// </returns>
  221. public static int SetEyeFOV(EyeType eye, float fovLeft, float fovRight, float fovUp, float fovDown)
  222. {
  223. return PXR_Plugin.Render.UPxr_SetEyeFOV(eye, fovLeft, fovRight, fovUp, fovDown);
  224. }
  225. /// <summary>
  226. /// Switches the face tracking mode.
  227. /// @note Only supported by PICO 4 Pro and PICO 4 Enterprise.
  228. /// </summary>
  229. /// <param name="value">
  230. /// `STOP_FT`: to stop the "Face Only" mode.
  231. /// `STOP_LIPSYNC`: to stop the "Lipsync Only" mode.
  232. /// `START_FT`: to start the "Face Only" mode.
  233. /// `START_LIPSYNC`: to start the "Lipsync Only" mode.
  234. /// </param>
  235. /// <returns>
  236. /// `0`: success
  237. /// `1`: failure
  238. /// </returns>
  239. public static int SetFaceTrackingStatus(PxrFtLipsyncValue value) {
  240. return PXR_Plugin.System.UPxr_SetFaceTrackingStatus(value);
  241. }
  242. /// <summary>
  243. /// Sets a tracking origin mode for the app.
  244. /// When the user moves in the virtual scene, the system tracks and calculates the user's positional changes based on the origin.
  245. /// </summary>
  246. /// <param name="originMode">Selects a tracking origin mode from the following:
  247. /// * `TrackingOriginModeFlags.Device`: Device mode. The system sets the device's initial position as the origin. The device's height from the floor is not calculated.
  248. /// * `TrackingOriginModeFlags.Floor`: Floor mode. The system sets an origin based on the device's original position and the device's height from the floor.
  249. /// </param>
  250. public static void SetTrackingOrigin(PxrTrackingOrigin originMode)
  251. {
  252. PXR_Plugin.System.UPxr_SetTrackingOrigin(originMode);
  253. }
  254. /// <summary>
  255. /// Gets the tracking origin mode of the app.
  256. /// </summary>
  257. /// <param name="originMode">Returns the app's tracking origin mode:
  258. /// * `TrackingOriginModeFlags.Device`: Device mode
  259. /// * `TrackingOriginModeFlags.Floor`: Floor mode
  260. /// For the description of each mode, refer to `SetTrackingOrigin`.
  261. /// </param>
  262. public static void GetTrackingOrigin(out PxrTrackingOrigin originMode)
  263. {
  264. originMode = PxrTrackingOrigin.Eye;
  265. PXR_Plugin.System.UPxr_GetTrackingOrigin(ref originMode);
  266. }
  267. }
  268. }
粤ICP备19079148号