API_GSXR_Slam.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class API_GSXR_Slam
  6. {
  7. public static GSXRManager SlamManager
  8. {
  9. get
  10. {
  11. return GSXRManager.Instance;
  12. }
  13. }
  14. public enum TrackMode
  15. {
  16. Mode_3Dof,
  17. Mode_6Dof,
  18. }
  19. ///API-No.1
  20. /// <summary>
  21. /// 设置眼镜进入模式,运行过程中可修改
  22. /// </summary>
  23. public static void GSXR_Set_TrackMode(TrackMode mode)
  24. {
  25. if (API_GSXR_Slam.SlamManager != null)
  26. {
  27. int trackingMode = API_GSXR_Slam.SlamManager.plugin.GetTrackingMode();
  28. if (mode == TrackMode.Mode_6Dof)
  29. {
  30. trackingMode |= (int)GSXRPlugin.TrackingMode.kTrackingPosition;
  31. }
  32. else
  33. {
  34. trackingMode &= (int)(~(1 << 1));
  35. }
  36. API_GSXR_Slam.SlamManager.plugin.SetTrackingMode(trackingMode);
  37. }
  38. }
  39. ///API-No.2
  40. /// <summary>
  41. /// Slam系统是否在运行
  42. /// </summary>
  43. /// <returns>true表示在运行,false表示未运行(Pause时为false)</returns>
  44. public static bool GSXR_Is_SlamRunning()
  45. {
  46. if (API_GSXR_Slam.SlamManager != null)
  47. {
  48. return API_GSXR_Slam.SlamManager.status.running;
  49. }
  50. return false;
  51. }
  52. ///API-No.3
  53. /// <summary>
  54. /// Slam系统是否初始化完成
  55. /// </summary>
  56. /// <returns></returns>
  57. public static bool GSXR_Is_SlamInitialized()
  58. {
  59. if (API_GSXR_Slam.SlamManager != null)
  60. {
  61. return API_GSXR_Slam.SlamManager.status.initialized;
  62. }
  63. return false;
  64. }
  65. ///API-No.4
  66. /// <summary>
  67. /// 设置Slam初始化完成时的回调
  68. /// </summary>
  69. /// <param name="action"></param>
  70. public static void GSXR_Add_InitializedCallBack(Action action)
  71. {
  72. API_GSXR_Slam.SlamManager.SvrInitializedCallBack += action;
  73. }
  74. ///API-No.5
  75. public static void GSXR_Remove_InitializedCallBack(Action action)
  76. {
  77. API_GSXR_Slam.SlamManager.SvrInitializedCallBack -= action;
  78. }
  79. ///API-No.6
  80. /// <summary>
  81. /// 设置渲染帧率,只能在Start中调用
  82. /// </summary>
  83. /// <param name="frameRate">默认-1表示系统默认帧率,设置范围0-200</param>
  84. public static void GSXR_Set_RenderFrame(int frameRate = -1)
  85. {
  86. if (API_GSXR_Slam.SlamManager != null)
  87. {
  88. if (frameRate == -1)
  89. {
  90. API_GSXR_Slam.SlamManager.plugin.SetVSyncCount((int)(API_GSXR_Slam.SlamManager.settings.vSyncCount = GSXRManager.SvrSettings.eVSyncCount.k1));
  91. QualitySettings.vSyncCount = (int)(API_GSXR_Slam.SlamManager.settings.vSyncCount = GSXRManager.SvrSettings.eVSyncCount.k1);//Vsync
  92. }
  93. else
  94. {
  95. API_GSXR_Slam.SlamManager.plugin.SetVSyncCount((int)(API_GSXR_Slam.SlamManager.settings.vSyncCount = GSXRManager.SvrSettings.eVSyncCount.k0));
  96. QualitySettings.vSyncCount = (int)(API_GSXR_Slam.SlamManager.settings.vSyncCount = GSXRManager.SvrSettings.eVSyncCount.k0);//Don't sync
  97. Application.targetFrameRate = (frameRate >= 0 && frameRate < 200) ? frameRate : 75;
  98. }
  99. }
  100. }
  101. ///API-No.7
  102. /// <summary>
  103. /// 获取左右眼摄像头
  104. /// </summary>
  105. /// <returns>List[0]左眼 List[1]右眼,空表示系统未启动完成</returns>
  106. public static List<Camera> GSXR_Get_EyeCameras()
  107. {
  108. List<Camera> cameraList = new List<Camera>(2);
  109. if (API_GSXR_Slam.SlamManager != null && API_GSXR_Slam.SlamManager.status.running == true)
  110. {
  111. cameraList.Add(API_GSXR_Slam.SlamManager.leftCamera);
  112. cameraList.Add(API_GSXR_Slam.SlamManager.rightCamera);
  113. }
  114. return cameraList;
  115. }
  116. ///API-No.8
  117. /// <summary>
  118. /// 获取左右眼渲染的画面,为获取当前帧的渲染结果,当前帧结束时调用
  119. /// </summary>
  120. /// <returns>List[0]左眼 List[1]右眼,空表示系统未启动完成</returns>
  121. public static List<RenderTexture> GSXR_Get_RenderTexure()
  122. {
  123. List<Camera> cameraList = GSXR_Get_EyeCameras();
  124. List<RenderTexture> RTList = new List<RenderTexture>(2);
  125. foreach (var item in cameraList)
  126. {
  127. RTList.Add(item.targetTexture);
  128. }
  129. return RTList;
  130. }
  131. ///API-No.9
  132. /// <summary>
  133. /// 获取头部物体,如果想获取头部的旋转移动等数据,在LateUpdate方法里调用
  134. /// </summary>
  135. /// <returns>空表示系统未启动完成</returns>
  136. public static Transform GSXR_Get_Head()
  137. {
  138. if (API_GSXR_Slam.SlamManager != null && API_GSXR_Slam.SlamManager.status.running == true)
  139. {
  140. return API_GSXR_Slam.SlamManager.head;
  141. }
  142. return null;
  143. }
  144. ///API-No.10
  145. /// <summary>
  146. /// 设置瞳距,Awake时调用,Start后调用无效
  147. /// </summary>
  148. /// <param name="offset">瞳距的偏移量,单位米</param>
  149. public static void GSXR_Set_PD(float offset = 0)
  150. {
  151. if (API_GSXR_Slam.SlamManager != null)
  152. {
  153. //API_GSXR_Slam.SlamManager.leftCameraOffsetPostion += offset / 2 * Vector3.left;
  154. //API_GSXR_Slam.SlamManager.rightCameraOffsetPostion += offset / 2 * Vector3.right;
  155. }
  156. }
  157. ///API-No.11
  158. /// <summary>
  159. /// 重定位,若无效果,表示系统初始化未完成,且只有在眼镜上有效
  160. /// </summary>
  161. public static void GSXR_RecenterTracking()
  162. {
  163. if (API_GSXR_Slam.SlamManager != null)
  164. {
  165. API_GSXR_Slam.SlamManager.RecenterTracking();
  166. }
  167. }
  168. ///API-No.12
  169. /// <summary>
  170. /// StartSlam
  171. /// </summary>
  172. public static void GSXR_Start_Slam()
  173. {
  174. if (API_GSXR_Slam.SlamManager != null)
  175. {
  176. API_GSXR_Slam.SlamManager.StartSlam();
  177. }
  178. }
  179. ///API-No.13
  180. /// <summary>
  181. /// StopSlam
  182. /// When a StartSlam is running (not completed), calling StopSlam will not work
  183. /// </summary>
  184. public static void GSXR_Stop_Slam()
  185. {
  186. if (API_GSXR_Slam.SlamManager != null)
  187. {
  188. API_GSXR_Slam.SlamManager.StopSlam();
  189. }
  190. }
  191. ///API-No.14
  192. /// <summary>
  193. /// ResetSlam
  194. /// </summary>
  195. public static void GSXR_Reset_Slam()
  196. {
  197. if (API_GSXR_Slam.SlamManager != null)
  198. {
  199. API_GSXR_Slam.SlamManager.ResetSlam();
  200. }
  201. }
  202. ///API-No.15
  203. /// <summary>
  204. /// IS Slam 6Dof DataLost
  205. /// </summary>
  206. public static bool GSXR_Is_SlamDataLost
  207. {
  208. get
  209. {
  210. if (API_GSXR_Slam.SlamManager != null)
  211. {
  212. return API_GSXR_Slam.SlamManager.IsTrackingValid;
  213. }
  214. return true;
  215. }
  216. }
  217. ///API-No.16
  218. /// <summary>
  219. /// Get QvrCamera Data
  220. /// </summary>
  221. public static int GSXR_Get_LatestQVRCameraBinocularData(ref bool outBUdate, ref uint outCurrFrameIndex, ref ulong outFrameExposureNano, byte[] outLeftFrameData, byte[] outRightFrameData)
  222. {
  223. if (API_GSXR_Slam.SlamManager && API_GSXR_Slam.SlamManager.plugin != null)
  224. {
  225. PermissionRequest.getInstance.GetPerssion(UnityEngine.Android.Permission.Camera);
  226. return API_GSXR_Slam.SlamManager.plugin.GSXR_Get_LatestQVRCameraBinocularData(ref outBUdate, ref outCurrFrameIndex, ref outFrameExposureNano, outLeftFrameData, outRightFrameData);
  227. }
  228. return 0;
  229. }
  230. public static int GSXR_Get_PointCloudData(ref int dataNum, ref ulong dataTimestamp, float[] dataArray)
  231. {
  232. if (API_GSXR_Slam.SlamManager && API_GSXR_Slam.SlamManager.plugin != null)
  233. {
  234. return API_GSXR_Slam.SlamManager.plugin.GSXR_Get_PointCloudData(ref dataNum, ref dataTimestamp, dataArray);
  235. }
  236. return 0;
  237. }
  238. public static int GSXR_Get_OfflineMapRelocState()
  239. {
  240. if (API_GSXR_Slam.SlamManager && API_GSXR_Slam.SlamManager.plugin != null)
  241. {
  242. return API_GSXR_Slam.SlamManager.plugin.GSXR_Get_OfflineMapRelocState();
  243. }
  244. return 0;
  245. }
  246. public static int GSXR_ResaveMap(string path)
  247. {
  248. if (API_GSXR_Slam.SlamManager && API_GSXR_Slam.SlamManager.plugin != null)
  249. {
  250. return API_GSXR_Slam.SlamManager.plugin.GSXR_ResaveMap(path);
  251. }
  252. return 0;
  253. }
  254. public static int GSXR_Get_Gnss(ref double dt, float[] gnss)
  255. {
  256. if (API_GSXR_Slam.SlamManager && API_GSXR_Slam.SlamManager.plugin != null)
  257. {
  258. return API_GSXR_Slam.SlamManager.plugin.GSXR_Get_Gnss(ref dt, gnss);
  259. }
  260. return 0;
  261. }
  262. public static int GSXR_Get_PanelNum()
  263. {
  264. if (API_GSXR_Slam.SlamManager && API_GSXR_Slam.SlamManager.plugin != null)
  265. {
  266. return API_GSXR_Slam.SlamManager.plugin.GSXR_Get_PanelNum();
  267. }
  268. return 0;
  269. }
  270. public static int GSXR_Get_PanelInfo(float[] info)
  271. {
  272. if (API_GSXR_Slam.SlamManager && API_GSXR_Slam.SlamManager.plugin != null)
  273. {
  274. return API_GSXR_Slam.SlamManager.plugin.GSXR_Get_PanelInfo(info);
  275. }
  276. return 0;
  277. }
  278. }