123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573 |
- using SC.XR.Unity;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class API_GSXR_Slam
- {
- public static GSXRManager SlamManager
- {
- get
- {
- return GSXRManager.Instance;
- }
- }
- public static GSXRPlugin plugin
- {
- get
- {
- return GSXRPlugin.Instance;
- }
- }
- ///API-No.1
- /// <summary>
- /// 设置眼镜进入模式,运行过程中可修改
- /// </summary>
- public static void GSXR_Set_TrackMode(TrackMode mode)
- {
- if (API_GSXR_Slam.SlamManager != null)
- {
- int trackingMode = API_GSXR_Slam.plugin.GetTrackingMode();
- if (mode == TrackMode.Mode_6Dof)
- {
- trackingMode |= (int)GSXRPlugin.TrackingMode.kTrackingPosition;
- }
- else
- {
- trackingMode &= (int)(~(1 << 1));
- }
- API_GSXR_Slam.plugin.SetTrackingMode(trackingMode);
- }
- }
- ///API-No.2
- /// <summary>
- /// Slam系统是否在运行
- /// </summary>
- /// <returns>true表示在运行,false表示未运行(Pause时为false)</returns>
- public static bool GSXR_Is_SlamRunning() {
- if (API_GSXR_Slam.SlamManager != null) {
- return API_GSXR_Slam.SlamManager.status.running;
- }
- return false;
- }
- ///API-No.3
- /// <summary>
- /// Slam系统是否初始化完成
- /// </summary>
- /// <returns></returns>
- public static bool GSXR_Is_SlamInitialized() {
- if (API_GSXR_Slam.SlamManager != null) {
- return API_GSXR_Slam.SlamManager.status.initialized;
- }
- return false;
- }
- ///API-No.4
- /// <summary>
- /// 设置Slam初始化完成时的回调
- /// </summary>
- /// <param name="action"></param>
- public static void GSXR_Add_InitializedCallBack(Action action)
- {
- GSXRManager.SlamInitializedCallBack += action;
- }
- ///API-No.5
- public static void GSXR_Remove_InitializedCallBack(Action action)
- {
- GSXRManager.SlamInitializedCallBack -= action;
- }
- ///API-No.6
- /// <summary>
- /// 设置渲染帧率,只能在Start中调用
- /// </summary>
- /// <param name="frameRate">默认-1表示系统默认帧率,设置范围0-200</param>
- public static void GSXR_Set_RenderFrame(int frameRate = -1)
- {
- if (API_GSXR_Slam.SlamManager != null)
- {
- if (frameRate == -1)
- {
- API_GSXR_Slam.plugin.SetVSyncCount((int)(API_GSXR_Slam.SlamManager.settings.vSyncCount = GSXRManager.SlamSettings.eVSyncCount.k1));
- QualitySettings.vSyncCount = (int)(API_GSXR_Slam.SlamManager.settings.vSyncCount = GSXRManager.SlamSettings.eVSyncCount.k1);//Vsync
- }
- else
- {
- API_GSXR_Slam.plugin.SetVSyncCount((int)(API_GSXR_Slam.SlamManager.settings.vSyncCount = GSXRManager.SlamSettings.eVSyncCount.k0));
- QualitySettings.vSyncCount = (int)(API_GSXR_Slam.SlamManager.settings.vSyncCount = GSXRManager.SlamSettings.eVSyncCount.k0);//Don't sync
- Application.targetFrameRate = (frameRate >= 0 && frameRate < 200) ? frameRate : 75;
- }
- }
- }
- ///API-No.7
- /// <summary>
- /// 获取左右眼摄像头
- /// </summary>
- /// <returns>List[0]左眼 List[1]右眼,空表示系统未启动完成</returns>
- public static List<Camera> GSXR_Get_EyeCameras()
- {
- List<Camera> cameraList = new List<Camera>(2);
- if (API_GSXR_Slam.SlamManager != null && API_GSXR_Slam.SlamManager.status.running == true)
- {
- cameraList.Add(Camera.main);
- cameraList.Add(API_GSXR_Slam.SlamManager.rightCamera);
- }
- return cameraList;
- }
- ///API-No.8
- /// <summary>
- /// 获取左右眼渲染的画面,为获取当前帧的渲染结果,当前帧结束时调用
- /// </summary>
- /// <returns>List[0]左眼 List[1]右眼,空表示系统未启动完成</returns>
- public static List<RenderTexture> GSXR_Get_RenderTexure()
- {
- List<Camera> cameraList = GSXR_Get_EyeCameras();
- List<RenderTexture> RTList = new List<RenderTexture>(2);
- foreach (var item in cameraList)
- {
- RTList.Add(item.targetTexture);
- }
- return RTList;
- }
- ///API-No.9
- /// <summary>
- /// 获取头部物体,如果想获取头部的旋转移动等数据,在LateUpdate方法里调用
- /// </summary>
- /// <returns>空表示系统未启动完成</returns>
- public static Transform GSXR_Get_Head()
- {
- return Camera.main.transform;
- }
- ///API-No.10
- /// <summary>
- /// 设置瞳距,Awake时调用,Start后调用无效
- /// </summary>
- /// <param name="offset">瞳距的偏移量,单位米</param>
- public static void GSXR_Set_PD(float offset = 0)
- {
- if (API_GSXR_Slam.SlamManager != null) {
- API_GSXR_Slam.plugin.GSXR_SetMeshOffset(0, offset / 2);
- API_GSXR_Slam.plugin.GSXR_SetMeshOffset(2, offset / 2);
- //Camera.mainOffsetPostion += offset / 2 * Vector3.left;
- //API_GSXR_Slam.SlamManager.rightCameraOffsetPostion += offset / 2 * Vector3.right;
- }
- }
- ///API-No.11
- /// <summary>
- /// 获取瞳距,
- /// </summary>
- /// <param name="type">右眼类型:2,左眼类型:0</param>
- public static float GSXR_Get_PD(int type)
- {
- if (API_GSXR_Slam.SlamManager != null)
- {
- return API_GSXR_Slam.plugin.GSXR_GetMeshOffset(type)+0.064f;
- }
- return -1;
- }
- ///API-No.12
- /// <summary>
- /// 重定位,若无效果,表示系统初始化未完成,且只有在眼镜上有效
- /// </summary>
- public static void GSXR_RecenterTracking()
- {
- if (API_GSXR_Slam.SlamManager != null)
- {
- API_GSXR_Slam.SlamManager.RecenterTracking();
- }
- }
- ///API-No.13
- /// <summary>
- /// StartSlam
- /// </summary>
- public static void GSXR_Start_Slam()
- {
- if (API_GSXR_Slam.SlamManager != null)
- {
- API_GSXR_Slam.SlamManager.StartSlam();
- }
- }
- ///API-No.14
- /// <summary>
- /// StopSlam
- /// When a StartSlam is running (not completed), calling StopSlam will not work
- /// </summary>
- public static void GSXR_Stop_Slam()
- {
- if (API_GSXR_Slam.SlamManager != null)
- {
- API_GSXR_Slam.SlamManager.StopSlam();
- }
- }
- ///API-No.15
- /// <summary>
- /// ResetSlam
- /// </summary>
- public static void GSXR_Reset_Slam()
- {
- if (API_GSXR_Slam.SlamManager != null)
- {
- API_GSXR_Slam.SlamManager.ResetSlam();
- }
- }
- public static void GSXR_Reset_Slam_V2()
- {
- GSXR_ResaveMap("resetslam");
- }
- ///API-No.16
- /// <summary>
- /// IS Slam 6Dof DataLost
- /// </summary>
- public static bool GSXR_Is_SlamDataLost
- {
- get
- {
- if (API_GSXR_Slam.SlamManager != null)
- {
- return API_GSXR_Slam.SlamManager.IsTrackingValid;
- }
- return true;
- }
- }
- ///API-No.17
- /// <summary>
- /// Get FishEye Data
- /// </summary>
- public static int GSXR_Get_LatestFishEyeBinocularData(ref bool outBUdate, ref uint outCurrFrameIndex, ref ulong outFrameExposureNano, byte[] outLeftFrameData, byte[] outRightFrameData)
- {
- if (API_GSXR_Slam.plugin != null)
- {
- PermissionRequest.getInstance.GetPerssion(UnityEngine.Android.Permission.Camera);
- return API_GSXR_Slam.plugin.GSXR_Get_LatestFishEyeBinocularData(ref outBUdate, ref outCurrFrameIndex, ref outFrameExposureNano, outLeftFrameData, outRightFrameData);
- }
- return 0;
- }
- static bool isOpen=false;
- public static bool GSXR_Is_EnablePointCloudData()
- {
- return isOpen;
- }
- public static void GSXR_Set_PointCloudData(bool _isOpen)
- {
- isOpen = _isOpen;
- }
- public static int GSXR_Get_PointCloudData(ref int dataNum, ref ulong dataTimestamp, float[] dataArray)
- {
- if (isOpen == false) {
- dataNum = 0;
- return 0;
- }
- if (API_GSXR_Slam.plugin != null)
- {
- return API_GSXR_Slam.plugin.GSXR_Get_PointCloudData(ref dataNum, ref dataTimestamp, dataArray);
- }
- return 0;
- }
- public static int GSXR_Get_OfflineMapRelocState()
- {
- if (API_GSXR_Slam.plugin != null)
- {
- return API_GSXR_Slam.plugin.GSXR_Get_OfflineMapRelocState();
- }
- return 0;
- }
- public static int GSXR_ResaveMap(string path)
- {
- if (API_GSXR_Slam.plugin != null)
- {
- return API_GSXR_Slam.plugin.GSXR_ResaveMap(path);
- }
- return 0;
- }
- public static void GSXR_SaveMap()
- {
- if (API_GSXR_Slam.plugin != null) {
- API_GSXR_Slam.plugin.GSXR_SaveMap();
- }
- }
- public static int GSXR_Get_Gnss(ref double dt, float[] gnss)
- {
- if (API_GSXR_Slam.plugin != null)
- {
- return API_GSXR_Slam.plugin.GSXR_Get_Gnss(ref dt, gnss);
- }
- return 0;
- }
- public static int GSXR_Get_PanelNum()
- {
- if (API_GSXR_Slam.plugin != null)
- {
- return API_GSXR_Slam.plugin.GSXR_Get_PanelNum();
- }
- return -1;
- }
- public static int GSXR_Get_PanelInfo(float[] info)
- {
- if (API_GSXR_Slam.plugin != null)
- {
- return API_GSXR_Slam.plugin.GSXR_Get_PanelInfo(info);
- }
- return -1;
- }
- public static int GSXR_Set_HeadOrigin(Vector3 postion) {
- if (API_GSXR_Slam.plugin != null) {
- API_GSXR_Slam.SlamManager.transform.position = (API_GSXR_Slam.SlamManager.transform.position - Camera.main.transform.position) + postion;
- return 1;
- }
- return -1;
- }
- public static int GSXR_Set_WorldOrigin(Vector3 postion) {
- if (API_GSXR_Slam.plugin != null) {
- API_GSXR_Slam.SlamManager.transform.position = Matrix4x4.TRS(-postion, Quaternion.identity, Vector3.one).MultiplyPoint(API_GSXR_Slam.SlamManager.transform.position);
- return 1;
- }
- return -1;
- }
- #region Old KS API
- /// <summary>
- /// Controller Vibrate
- /// </summary>
- /// <param name="index">0-LeftController 1-RightController</param>
- /// <param name="isOn"></param>
- /// <param name="vibrateOnType"></param>
- /// <param name="time"></param>
- public static void GSXR_Set_ControllerVibrate(int index, bool isOn, GSXRManager.VibrateOnType vibrateOnType = GSXRManager.VibrateOnType.OneShot, float time = 0.1f) {
- if (API_GSXR_Slam.plugin != null) {
- API_GSXR_Slam.SlamManager.GSXR_Set_ControllerVibrate(index, isOn, vibrateOnType, time);
- }
- }
- /// <summary>
- /// GSXR_Get_ControllerVibrateStatus
- /// </summary>
- /// <param name="index">0-LeftController 1-RightController</param>
- /// <returns></returns>
- public static bool GSXR_Get_ControllerVibrateStatus(int index)
- {
- if (API_GSXR_Slam.plugin != null)
- {
- return API_GSXR_Slam.SlamManager.GSXR_Get_ControllerVibrateStatus(index);
- }
- return false;
- }
- #endregion
- #region NEW KS Controller API
- /// <summary>
- /// Controller Vibrate
- /// </summary>
- /// <param name="index"></param>
- /// <param name="isOn"></param>
- /// <param name="amplitude"></param>
- /// <param name="frequency"></param>
- /// <param name="time"></param>
- /// <returns></returns>
- public static int GSXR_Set_ControllerVibrate(int index, bool isOn, float amplitude, float frequency, float time)
- {
- if (API_GSXR_Slam.plugin != null)
- {
- return API_GSXR_Slam.SlamManager.GSXR_Set_ControllerVibrate(index, isOn, amplitude, frequency, time);
- }
- return -1;
- }
- [Obsolete("Please Use NEW KS Vibrate GSXR_Set_ControllerVibrate(int index, bool isOn, float amplitude, float frequency, float time)")]
- public static int GSXR_Set_ControllerVibrate(int index, bool isOn, int amplitude, int frequency, int time)
- {
- if (API_GSXR_Slam.plugin != null)
- {
- return API_GSXR_Slam.SlamManager.GSXR_Set_ControllerVibrate(index, isOn, amplitude/15f, frequency/15f, time/10f);
- }
- return -1;
- }
- /// <summary>
- /// GSXR_Get_ControllerVibrateState,
- /// return:"0" is false ,"1" is true
- /// </summary>
- /// <param name="index">0-LeftController 1-RightController</param>
- /// <returns></returns>
- public static int GSXR_Get_ControllerVibrateState(int index)
- {
- if (API_GSXR_Slam.plugin != null)
- {
- return API_GSXR_Slam.SlamManager.GSXR_Get_ControllerVibrateState(index);
- }
- return -1;
- }
- #endregion
- #region Other API
- /// <summary>
- /// GSXR_Set_OnFloorOrOnHead
- /// </summary>
- /// <param name="type">0-Head, 1-Floor</param>
- public static void GSXR_Set_OnFloorOrOnHead(int type)
- {
- if (API_GSXR_Slam.plugin != null)
- {
- API_GSXR_Slam.SlamManager.GSXR_Set_OnFloorOrOnHead(type);
- }
- }
- public static void GSXR_Bind_Controller(int index,int type)
- {
- if (API_GSXR_Slam.plugin != null)
- {
- API_GSXR_Slam.SlamManager.GSXR_Bind_Controller(index, type);
- }
- }
- public static void GSXR_Unbind_Controller(int index, int type)
- {
- if (API_GSXR_Slam.plugin != null)
- {
- API_GSXR_Slam.SlamManager.GSXR_Unbind_Controller(index, type);
- }
- }
- public static int GSXR_Get_ControllerBondState()
- {
- if (API_GSXR_Slam.plugin != null)
- {
- return API_GSXR_Slam.SlamManager.GSXR_Get_ControllerBondState();
- }
- return -2;
- }
- /// <summary>
- /// Whether to Enable the Controller binding status callback interface
- /// </summary>
- public static void GSXR_Set_ControllerBondEventCallback(bool isEnable)
- {
- if (API_GSXR_Slam.plugin != null)
- {
- API_GSXR_Slam.SlamManager.GSXR_Set_ControllerBondEventCallback(isEnable);
- }
- }
- /// <summary>
- /// Add Controller binding state callback event
- /// </summary>
- /// <param name="callback"></param>
- public static void GSXR_Add_ControllerBondEventCallback(Action<int> callback)
- {
- if (API_GSXR_Slam.plugin != null)
- {
- API_GSXR_Slam.SlamManager.GSXR_Add_ControllerBondEventCallback(callback);
- }
- }
- /// <summary>
- /// Remove Controller binding state callback event
- /// </summary>
- /// <param name="callback"></param>
- public static void GSXR_Remove_ControllerBondEventCallback(Action<int> callback)
- {
- if (API_GSXR_Slam.plugin != null)
- {
- API_GSXR_Slam.SlamManager.GSXR_Remove_ControllerBondEventCallback(callback);
- }
- }
- #endregion
- #region SeeThrough API
- /// <summary>
- /// GSXR_StartSeeThrough
- /// </summary>
- public static void GSXR_StartSeeThrough()
- {
- if (API_GSXR_Slam.plugin != null)
- {
- API_GSXR_Slam.plugin.GSXR_StartSeeThrough();
- }
- }
- /// <summary>
- /// GSXR_StopSeeThrough
- /// </summary>
- public static void GSXR_StopSeeThrough()
- {
- if (API_GSXR_Slam.plugin != null)
- {
- API_GSXR_Slam.plugin.GSXR_StopSeeThrough();
- }
- }
- public static void GSXR_Add_SeeThrough_Callback(Action<bool> callback)
- {
- if (API_GSXR_Slam.plugin != null)
- {
- API_GSXR_Slam.plugin.GSXR_Regist_SeeThrough_Callback(callback);
- }
- }
- public static void GSXR_Remove_SeeThrough_Callback(Action<bool> callback)
- {
- if (API_GSXR_Slam.plugin != null)
- {
- API_GSXR_Slam.plugin.GSXR_UnRegist_SeeThrough_Callbak(callback);
- }
- }
- #endregion
- /// <summary>
- /// GSXR_Add_SlamPauseCallback
- /// </summary>
- /// <param name="callback"></param>
- public static void GSXR_Add_SlamPauseCallback(GSXRManager.OnApplicationPauseDele callback)
- {
- GSXRManager.onApplicationPauseDele += callback;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="callback"></param>
- public static void GSXR_Remove_SlamPauseCallback(GSXRManager.OnApplicationPauseDele callback)
- {
- GSXRManager.onApplicationPauseDele -= callback;
- }
- }
|