/// <summary> /// Enables the thread to get the trackingr.up /// </summary> void EnableTrackingThreaded() { enablePoseSmoothing = enableSpatialMemory; lock (grabLock) { //Make sure we have "grabbed" on frame first sl.ERROR_CODE e = zedCamera.Grab(ref runtimeParameters); int timeOut_grab = 0; while (e != sl.ERROR_CODE.SUCCESS && timeOut_grab < 100) { e = zedCamera.Grab(ref runtimeParameters); Thread.Sleep(10); timeOut_grab++; } //Make sure the .area path is valid if (pathSpatialMemory != "" && !System.IO.File.Exists(pathSpatialMemory)) { Debug.Log("Specified path to .area file '" + pathSpatialMemory + "' does not exist. Ignoring."); pathSpatialMemory = ""; } //Now enable the tracking with the proper parameters //if (!(enableTracking = (zedCamera.EnableTracking(ref initialRotation, ref initialPosition, enableSpatialMemory, enablePoseSmoothing, pathSpatialMemory) == sl.ERROR_CODE.SUCCESS))) if (!(enableTracking = (zedCamera.EnableTracking(ref zedOrientation, ref zedPosition, enableSpatialMemory, enablePoseSmoothing, pathSpatialMemory) == sl.ERROR_CODE.SUCCESS))) { throw new Exception(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.TRACKING_NOT_INITIALIZED)); } else { isTrackingEnable = true; } } }
void MeshIsOver() { #if UNITY_5_6_OR_NEWER UpdateNavMesh(); //Nav mesh has been build. Clear the sources as we don't need them sources.Clear(); //Draw the nav mesh is possible (triangulation from navmesh has return an area) bool isDrawn = Draw(); #endif if (isDrawn) { PositionEventArgs args = new PositionEventArgs(); args.position = NavMeshPosition; args.valid = isDrawn; args.agentTypeID = agentTypeID; System.EventHandler <PositionEventArgs> handler = OnNavMeshReady; if (handler != null) { handler(this, args); } } else { Debug.LogWarning(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.NAVMESH_NOT_GENERATED)); } isOver = true; }
/// <summary> /// Re-enable canvas elements and change message when ZED is disconnected. /// GameObjects were disabled before because the ZED had to have finished initializing before. /// </summary> void ZEDDisconnected() { if (warningmono) //Using the mono rig. { warningmono.SetActive(true); imagemono.SetActive(true); warningmono.transform.GetChild(0).gameObject.SetActive(true); textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.ZED_IS_DISCONNECETD); warningmono.layer = 30; ready = false; } if (warningleft) //Using the stereo rig. { warningleft.SetActive(true); imageleft.SetActive(true); warningleft.transform.GetChild(0).gameObject.SetActive(true); textleft.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.ZED_IS_DISCONNECETD); warningleft.layer = 30; warningright.SetActive(true); imageright.SetActive(true); warningright.transform.GetChild(0).gameObject.SetActive(true); textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.ZED_IS_DISCONNECETD); warningright.layer = 30; ready = false; } }
const string packageName = "Oculus"; //Switch to OVR for old plugin. public override void OnInspectorGUI() { if (EditorPrefs.GetBool(packageName) && CheckPackageExists(packageName) && isDefineActivated()) { DrawDefaultInspector(); } else { // Should not be needed but in just in case... GUILayout.Space(20); if (GUILayout.Button("Activate Oculus")) { if (CheckPackageExists(packageName)) { ActivateDefine(); } } //if OVR package does not exist, undef ZED_OCULUS to avoid build errors if (!CheckPackageExists(packageName)) { EditorGUILayout.HelpBox(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.OVR_NOT_INSTALLED), MessageType.Warning); DesactivateDefine(); } } }
void OnValidate() { if (zedCamera != null) { if (!isTrackingEnable && enableTracking) { //Enables the tracking and initializes the first position of the camera enablePoseSmoothing = enableSpatialMemory; if (!(enableTracking = (zedCamera.EnableTracking(ref zedOrientation, ref zedPosition, enableSpatialMemory, enablePoseSmoothing, pathSpatialMemory) == sl.ERROR_CODE.SUCCESS))) { isZEDTracked = false; throw new Exception(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.TRACKING_NOT_INITIALIZED)); } else { isZEDTracked = true; isTrackingEnable = true; } } if (isTrackingEnable && !enableTracking) { isZEDTracked = false; lock (grabLock) { zedCamera.DisableTracking(); } isTrackingEnable = false; } setRenderingSettings(); } }
/// <summary> /// Enables the thread to get the trackingr.up /// </summary> void EnableTrackingThreaded() { enablePoseSmoothing = enableSpatialMemory; lock (grabLock) { //Make sure we have "grabbed" on frame first sl.ERROR_CODE e = zedCamera.Grab(ref runtimeParameters); int timeOut_grab = 0; while (e != sl.ERROR_CODE.SUCCESS && timeOut_grab < 100) { e = zedCamera.Grab(ref runtimeParameters); Thread.Sleep(10); timeOut_grab++; } //Now enable the tracking with the proper parameters if (!(enableTracking = (zedCamera.EnableTracking(ref initialRotation, ref initialPosition, enableSpatialMemory, enablePoseSmoothing, pathSpatialMemory) == sl.ERROR_CODE.SUCCESS))) { throw new Exception(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.TRACKING_NOT_INITIALIZED)); } else { isTrackingEnable = true; } } }
/// <summary> /// Event if ZED is disconnected /// </summary> void ZEDDisconnected() { warning.SetActive(true); warning.transform.GetChild(0).gameObject.SetActive(true); text.GetComponent <RectTransform>().localPosition = Vector3.zero; text.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.ZED_IS_DISCONNECETD); text.alignment = TextAnchor.MiddleCenter; text.fontSize = 200; warning.layer = 30; }
/// <summary> /// Creates canvas(es) and canvas elements depending on whether the ZED rig is mono (ZED_Rig_Mono) /// or stereo (ZED_Rig_Stereo). /// </summary> private void Awake() { zedManager = GetComponent <ZEDManager> (); oldInitStatus = sl.ERROR_CODE.ERROR_CODE_LAST; if (!zedManager.IsStereoRig) //Without VR, we use a Screen Space - Overlay canvas. { //Instantiate the mono warning prefab and set basic settings for it. warningmono = Instantiate(Resources.Load("PrefabsUI/Warning") as GameObject, transform); warningmono.SetActive(true); warningmono.GetComponent <Canvas> ().renderMode = RenderMode.ScreenSpaceCamera; warningmono.GetComponent <Canvas> ().worldCamera = zedManager.GetLeftCameraTransform().GetComponent <Camera>(); textmono = warningmono.GetComponentInChildren <UnityEngine.UI.Text>(); textmono.color = Color.white; if (!sl.ZEDCamera.CheckPlugin()) { textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_NOT_INSTALLED); } imagemono = warningmono.transform.GetChild(0).GetChild(1).gameObject; imagemono.transform.parent.gameObject.SetActive(true); ready = false; } else //In VR, we use two Screen Space - Camera canvases, one for each eye. { //Instantiate the left warning prefab and set basic settings for it. warningleft = Instantiate(Resources.Load("PrefabsUI/Warning_VR") as GameObject, zedManager.GetLeftCameraTransform()); warningleft.SetActive(true); warningleft.GetComponent <Canvas>().worldCamera = zedManager.GetLeftCameraTransform().GetComponent <Camera>(); warningleft.GetComponent <Canvas>().planeDistance = 1; textleft = warningleft.GetComponentInChildren <UnityEngine.UI.Text>(); textleft.color = Color.white; imageleft = warningleft.transform.GetChild(0).GetChild(1).gameObject; imageleft.transform.parent.gameObject.SetActive(true); //Instantiate the right warning prefab and set basic settings for it. warningright = Instantiate(Resources.Load("PrefabsUI/Warning_VR") as GameObject, zedManager.GetRightCameraTransform()); warningright.SetActive(true); warningright.GetComponent <Canvas>().worldCamera = zedManager.GetRightCameraTransform().GetComponent <Camera>(); warningright.GetComponent <Canvas>().planeDistance = 1; textright = warningright.GetComponentInChildren <UnityEngine.UI.Text>(); textright.color = Color.white; imageright = warningright.transform.GetChild(0).GetChild(1).gameObject; imageright.transform.parent.gameObject.SetActive(true); if (!sl.ZEDCamera.CheckPlugin()) //Warn the use there's no SDK installed. { textleft.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_NOT_INSTALLED); textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_NOT_INSTALLED); } ready = false; } }
private void Awake() { oldInitStatus = ERROR_CODE.ERROR_CODE_LAST; if (!ZEDManager.IsStereoRig) //Without VR, we use a Screen Space - Overlay canvas. { warningmono = Instantiate(Resources.Load("PrefabsUI/Warning") as GameObject, transform); warningmono.SetActive(true); textmono = warningmono.GetComponentInChildren <Text>(); textmono.color = Color.white; if (!ZEDCamera.CheckPlugin()) { textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_NOT_INSTALLED); } imagemono = warningmono.transform.GetChild(0).GetChild(1).gameObject; imagemono.transform.parent.gameObject.SetActive(true); ready = false; } else //In VR, we use two Screen Space - Camera canvases, one for each eye. { //Setup the left warning prefab warningleft = Instantiate(Resources.Load("PrefabsUI/Warning_VR") as GameObject, ZEDManager.Instance.GetLeftCameraTransform()); warningleft.SetActive(true); warningleft.GetComponent <Canvas>().worldCamera = ZEDManager.Instance.GetLeftCameraTransform().GetComponent <Camera>(); warningleft.GetComponent <Canvas>().planeDistance = 1; textleft = warningleft.GetComponentInChildren <Text>(); textleft.color = Color.white; imageleft = warningleft.transform.GetChild(0).GetChild(1).gameObject; imageleft.transform.parent.gameObject.SetActive(true); //Setup the right warning prefab warningright = Instantiate(Resources.Load("PrefabsUI/Warning_VR") as GameObject, ZEDManager.Instance.GetRightCameraTransform()); warningright.SetActive(true); warningright.GetComponent <Canvas>().worldCamera = ZEDManager.Instance.GetRightCameraTransform().GetComponent <Camera>(); warningright.GetComponent <Canvas>().planeDistance = 1; textright = warningright.GetComponentInChildren <Text>(); textright.color = Color.white; imageright = warningright.transform.GetChild(0).GetChild(1).gameObject; imageright.transform.parent.gameObject.SetActive(true); if (!ZEDCamera.CheckPlugin()) { textleft.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_NOT_INSTALLED); textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_NOT_INSTALLED); } ready = false; } }
static void Update() { if (!sl.ZEDCamera.CheckPlugin()) { errorMessage = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_DEPENDENCIES_ISSUE); window = GetWindow <ZEDPluginInspector>(true); window.maxSize = new Vector2(400, 500); window.minSize = window.maxSize; window.Show(true); } EditorApplication.update -= Update; }
private void Awake() { cameraRig = GameObject.Find("[CameraRig]"); if (cameraRig == null) { Debug.LogWarning(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.VR_CAMERA_RIG_NOT_FOUND)); controllerManager = FindObjectOfType(typeof(SteamVR_ControllerManager)) as SteamVR_ControllerManager; if (controllerManager == null) { Debug.LogWarning(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.VR_CAMERA_RIG_CONTROLLER_NOT_FOUND)); } } }
private void Awake() { warning = Instantiate(Resources.Load("PrefabsUI/Warning" + (ZEDManager.IsStereoRig ? "_VR" :"")) as GameObject, transform); warning.SetActive(true); text = warning.GetComponentInChildren <UnityEngine.UI.Text>(); text.color = Color.white; if (!sl.ZEDCamera.CheckPlugin()) { text.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_NOT_INSTALLED); } image = warning.transform.GetChild(0).GetChild(1).gameObject; image.transform.parent.gameObject.SetActive(true); ready = false; }
public override void OnInspectorGUI() { if (EditorPrefs.GetBool(packageName)) { DrawDefaultInspector(); } else { GUILayout.Space(20); if (GUILayout.Button("Load SteamVR data")) { if (CheckPackageExists(packageName)) { ActivateDefine(); } } EditorGUILayout.HelpBox(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.STEAMVR_NOT_INSTALLED), MessageType.Warning); } }
// Update is called once per frame void Update() { if (!init) { sl.ERROR_CODE e = ZEDManager.LastInitStatus; if (e == sl.ERROR_CODE.SUCCESS) { timer += Time.deltaTime; if (timer > 0.2f) { text.text = ""; } image.gameObject.SetActive(false); } else if (e == sl.ERROR_CODE.ERROR_CODE_LAST) { text.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_LOADING); text.color = Color.white; } else if (e == sl.ERROR_CODE.CAMERA_NOT_DETECTED) { text.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.UNABLE_TO_OPEN_CAMERA); } else { text.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_NOT_INITIALIZED); } if (ready) { timerWarning += Time.deltaTime; if (timerWarning > 0.5f) { warning.SetActive(false); init = true; timerWarning = 0; } image.gameObject.transform.parent.gameObject.SetActive(false); } } }
public override void OnInspectorGUI() { if (CheckPackageExists("SteamVR")) { defineName = "ZED_STEAM_VR"; packageName = "SteamVR"; } else if (CheckPackageExists("Oculus") || CheckPackageExists("OVR")) { defineName = "ZED_OCULUS"; packageName = "Oculus"; } if (EditorPrefs.GetBool(packageName)) { DrawDefaultInspector(); } else { GUILayout.Space(20); if (GUILayout.Button("Load " + packageName + " data")) { if (CheckPackageExists(packageName)) { ActivateDefine(); } } if (packageName == "SteamVR") { EditorGUILayout.HelpBox(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.STEAMVR_NOT_INSTALLED), MessageType.Warning); } else if (packageName == "Oculus") { EditorGUILayout.HelpBox(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.OVR_NOT_INSTALLED), MessageType.Warning); } } }
public override void OnInspectorGUI() //Called when the Inspector is visible. { //if (CheckPackageExists("OpenVR")) if (CheckPackageExists("SteamVR_Camera.cs")) { defineName = "ZED_STEAM_VR"; packageName = "SteamVR"; } //else if (CheckPackageExists("Oculus") || CheckPackageExists("OVR")) else if (CheckPackageExists("OVRManager")) { defineName = "ZED_OCULUS"; packageName = "Oculus"; } if (EditorPrefs.GetBool(packageName)) //Has it been set? { DrawDefaultInspector(); } else //No package loaded, but one has been detected. Present a button to load it. { GUILayout.Space(20); if (GUILayout.Button("Load " + packageName + " data")) { if (CheckPackageExists(packageName)) { ActivateDefine(); } } if (packageName == "SteamVR") { EditorGUILayout.HelpBox(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.STEAMVR_NOT_INSTALLED), MessageType.Warning); } else if (packageName == "Oculus") { EditorGUILayout.HelpBox(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.OVR_NOT_INSTALLED), MessageType.Warning); } } }
System.Collections.IEnumerator InitZED() { zedReady = false; while (LastInitStatus != sl.ERROR_CODE.SUCCESS) { //Initialize the camera if (!openingLaunched) { threadOpening = new Thread(new ThreadStart(OpenZEDInBackground)); if (LastInitStatus != sl.ERROR_CODE.SUCCESS) { #if UNITY_EDITOR numberTriesOpening++; if (numberTriesOpening % 2 == 0 && LastInitStatus == PreviousInitStatus) { Debug.LogWarning("[ZEDPlugin]: " + LastInitStatus); } if (numberTriesOpening > MAX_OPENING_TRIES) { Debug.Log("[ZEDPlugin]: Stops initialization"); yield break; } #endif PreviousInitStatus = LastInitStatus; } threadOpening.Start(); } yield return(new WaitForSeconds(0.3f)); } //ZED has opened if (LastInitStatus == sl.ERROR_CODE.SUCCESS) { threadOpening.Join(); //Initialize the threading mode, the positions with the AR and the SVO if needed //Launch the threading to enable the tracking ZEDReady(); //Wait until the ZED of the init of the tracking while (enableTracking && !isTrackingEnable) { yield return(new WaitForSeconds(0.5f)); } //Calls all the observers, the ZED is ready :) if (OnZEDReady != null) { OnZEDReady(); } float ratio = (float)Screen.width / (float)Screen.height; float target = 16.0f / 9.0f; if (Mathf.Abs(ratio - target) > 0.01) { ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SCREEN_RESOLUTION); } //If not already launched, launch the grabbing thread if (!running) { running = true; requestNewFrame = true; threadGrab = new Thread(new ThreadStart(ThreadedZEDGrab)); threadGrab.Start(); } zedReady = true; isDisconnected = false; //In case we just regained connection setRenderingSettings(); AdjustZEDRigCameraPosition(); } }
/// <summary> /// Update is called every frame. /// For SteamVR plugin this is where the device Index is set up. /// For Oculus plugin this is where the tracking is done. /// </summary> private void Update() { #if ZED_OCULUS //Check if the VR headset is connected. if (OVRManager.isHmdPresent && loadedDevice == "Oculus") { if (OVRInput.GetConnectedControllers().ToString() == "Touch") { //Depending on which tracked device we are looking for, start tracking it. if (deviceToTrack == devices.LeftController) //Track the Left Oculus Controller. { RegisterPosition(1, OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch), OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch)); } if (deviceToTrack == devices.RightController) //Track the Right Oculus Controller. { RegisterPosition(1, OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch), OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch)); } if (deviceToTrack == devices.Hmd) //Track the Oculus Hmd. { RegisterPosition(1, UnityEngine.VR.InputTracking.GetLocalPosition(UnityEngine.VR.VRNode.CenterEye), UnityEngine.VR.InputTracking.GetLocalRotation(UnityEngine.VR.VRNode.CenterEye)); } //Taking our saved positions, and applying a delay before assigning it to our Transform. if (poseData.Count > 0) { sl.Pose p; //Delaying the saved values inside GetValuePosition() by a factor of latencyCompensation to the millisecond. p = GetValuePosition(1, (float)(_latencyCompensation / 1000.0f)); transform.position = p.translation; //Assign new delayed Position transform.rotation = p.rotation; //Assign new delayed Rotation. } } } //Enabling the updates of the internal state of OVRInput. OVRInput.Update(); #endif #if ZED_STEAM_VR //Timer for checking on devices timerVive += Time.deltaTime; if (timerVive <= timerMaxVive) { return; } timerVive = 0f; //Checks if a device has been assigned if (index == EIndex.None && loadedDevice == "OpenVR") { if (BIsManufacturerController("HTC") || BIsManufacturerController("Oculus")) { //We look for any device that has "tracker" in its 3D model mesh name. //We're doing this since the device ID changes based on how many devices are connected to Steam VR. //This way if there's no controllers or just one, it's going to get the right ID for the Tracker. if (deviceToTrack == devices.ViveTracker) { var error = ETrackedPropertyError.TrackedProp_Success; for (uint i = 0; i < 16; i++) { var result = new StringBuilder(64); OpenVR.System.GetStringTrackedDeviceProperty(i, ETrackedDeviceProperty.Prop_RenderModelName_String, result, 64, ref error); if (result.ToString().Contains("tracker")) { index = (EIndex)i; break; //We break out of the loop, but we can use this to set up multiple Vive Trackers if we want to. } } } //Looks for a device with the role of a Right Hand. if (deviceToTrack == devices.RightController) { index = (EIndex)OpenVR.System.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole .RightHand); } //Looks for a device with the role of a Left Hand. if (deviceToTrack == devices.LeftController) { index = (EIndex)OpenVR.System.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole .LeftHand); } //Assigns the Hmd if (deviceToTrack == devices.Hmd) { index = EIndex.Hmd; } } //Display Warning if there was supposed to be a calibration file, and none was found. if (SNHolder.Equals("NONE")) { Debug.LogWarning(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.PAD_CAMERA_CALIBRATION_NOT_FOUND)); } else if (SNHolder != null && index != EIndex.None) { if (!SteamVR.instance.GetStringProperty(ETrackedDeviceProperty.Prop_SerialNumber_String, (uint)index) .Contains(SNHolder)) { Debug.LogWarning(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.PAD_CAMERA_CALIBRATION_MISMATCH) + SNHolder); //... then look for that device through all the connected devices. for (var i = 0; i < 16; i++) { //If a device with the same Serial Number is found, then change the device to track of this script. if (SteamVR.instance .GetStringProperty(ETrackedDeviceProperty.Prop_SerialNumber_String, (uint)i) .Contains(SNHolder)) { index = (EIndex)i; var deviceRole = OpenVR.System.GetControllerRoleForTrackedDeviceIndex((uint)index) .ToString(); if (deviceRole.Equals("RightHand")) { deviceToTrack = devices.RightController; } else if (deviceRole.Equals("LeftHand")) { deviceToTrack = devices.LeftController; } else if (deviceRole.Equals("Invalid")) { var error = ETrackedPropertyError.TrackedProp_Success; var result = new StringBuilder(64); OpenVR.System.GetStringTrackedDeviceProperty((uint)index, ETrackedDeviceProperty.Prop_RenderModelName_String, result, 64, ref error); if (result.ToString().Contains("tracker")) { deviceToTrack = devices.ViveTracker; } } Debug.Log("A connected device with the correct Serial Number was found, and assigned to " + this + " the correct device to track."); break; } } } } oldDevice = deviceToTrack; } if (deviceToTrack != oldDevice) { index = EIndex.None; } #endif }
/// <summary> /// Update is called every frame. /// For SteamVR plugin this is where the device Index is set up. /// For Oculus plugin this is where the tracking is done. /// </summary> protected virtual void Update() { #if ZED_OCULUS //Used only if the Oculus Integration plugin is detected. //Check if the VR headset is connected. if (OVRManager.isHmdPresent && loadeddevice == "Oculus") { if (OVRInput.GetConnectedControllers().ToString().ToLower().Contains("touch")) { //Depending on which tracked device we are looking for, start tracking it. if (deviceToTrack == Devices.LeftController) //Track the Left Oculus Controller. { RegisterPosition(1, OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch), OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch)); } if (deviceToTrack == Devices.RightController) //Track the Right Oculus Controller. { RegisterPosition(1, OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch), OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch)); } if (deviceToTrack == Devices.Hmd) //Track the Oculus Hmd. { RegisterPosition(1, InputTracking.GetLocalPosition(XRNode.CenterEye), InputTracking.GetLocalRotation(XRNode.CenterEye)); } //Use our saved positions to apply a delay before assigning it to this object's Transform. if (poseData.Count > 0) { sl.Pose p; //Delay the saved values inside GetValuePosition() by a factor of latencyCompensation in milliseconds. p = GetValuePosition(1, (float)(latencyCompensation / 1000.0f)); transform.position = p.translation; //Assign new delayed Position transform.rotation = p.rotation; //Assign new delayed Rotation. } } } //Enable updating the internal state of OVRInput. OVRInput.Update(); #endif #if ZED_STEAM_VR UpdateControllerState(); //Get the button states so we can check if buttons are down or not. timerSteamVR += Time.deltaTime; //Increment timer for checking on devices if (timerSteamVR <= timerMaxSteamVR) { return; } timerSteamVR = 0f; //Checks if a device has been assigned if (index == EIndex.None && loadeddevice == "OpenVR") { //We look for any device that has "tracker" in its 3D model mesh name. //We're doing this since the device ID changes based on how many devices are connected to SteamVR. //This way, if there's no controllers or just one, it's going to get the right ID for the Tracker. if (deviceToTrack == Devices.ViveTracker) { var error = ETrackedPropertyError.TrackedProp_Success; for (uint i = 0; i < 16; i++) { var result = new System.Text.StringBuilder((int)64); OpenVR.System.GetStringTrackedDeviceProperty(i, ETrackedDeviceProperty.Prop_RenderModelName_String, result, 64, ref error); if (result.ToString().Contains("tracker")) { index = (EIndex)i; break; //We break out of the loop, but we can use this to set up multiple Vive Trackers if we want to. } } } //Looks for a device with the role of a Right Hand. if (deviceToTrack == Devices.RightController) { index = (EIndex)OpenVR.System.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.RightHand); } //Looks for a device with the role of a Left Hand. if (deviceToTrack == Devices.LeftController) { index = (EIndex)OpenVR.System.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.LeftHand); } //Assigns the HMD. if (deviceToTrack == Devices.Hmd) { index = EIndex.Hmd; } //Display a warning if there was supposed to be a calibration file, and none was found. if (SNHolder.Equals("NONE")) { Debug.LogWarning(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.PAD_CAMERA_CALIBRATION_NOT_FOUND)); } else if (SNHolder != null && index != EIndex.None) // { //If the Serial number of the Calibrated device isn't the same as the current tracked device by this script... var snerror = ETrackedPropertyError.TrackedProp_Success; var snresult = new System.Text.StringBuilder((int)64); OpenVR.System.GetStringTrackedDeviceProperty((uint)index, ETrackedDeviceProperty.Prop_SerialNumber_String, snresult, 64, ref snerror); if (!snresult.ToString().Contains(SNHolder)) { Debug.LogWarning(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.PAD_CAMERA_CALIBRATION_MISMATCH) + " Serial Number: " + SNHolder); //... then look for that device through all the connected devices. for (int i = 0; i < 16; i++) { //If a device with the same Serial Number is found, then change the device to track of this script. var chsnresult = new System.Text.StringBuilder((int)64); OpenVR.System.GetStringTrackedDeviceProperty((uint)i, ETrackedDeviceProperty.Prop_SerialNumber_String, chsnresult, 64, ref snerror); if (snresult.ToString().Contains(SNHolder)) { index = (EIndex)i; string deviceRole = OpenVR.System.GetControllerRoleForTrackedDeviceIndex((uint)index).ToString(); if (deviceRole.Equals("RightHand")) { deviceToTrack = Devices.RightController; } else if (deviceRole.Equals("LeftHand")) { deviceToTrack = Devices.LeftController; } else if (deviceRole.Equals("Invalid")) { var error = ETrackedPropertyError.TrackedProp_Success; var result = new System.Text.StringBuilder((int)64); OpenVR.System.GetStringTrackedDeviceProperty((uint)index, ETrackedDeviceProperty.Prop_RenderModelName_String, result, 64, ref error); if (result.ToString().Contains("tracker")) { deviceToTrack = Devices.ViveTracker; } } Debug.Log("A connected device with the correct Serial Number was found, and assigned to " + this + " the correct device to track."); break; } } } } oldDevice = deviceToTrack; } if (deviceToTrack != oldDevice) { index = EIndex.None; } #endif }
private void Update() { timerVive += Time.deltaTime; if (timerVive > timerMaxVive) { timerVive = 0; if (!padsSet) { GetPadIndex(); } if (devices.Count != delayedPads.Count) { CreateNewPads(); } if (devices.Count >= 2) { padsAreInit = true; } //if (devices.Count < 2) //{ // Debug.LogWarning(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.NOT_ENOUGH_PAD_DETECTED) + devices.Count); //} if (controllerIndexZEDHolder == -1) { if (SNHolder.Equals("NONE")) { Debug.LogWarning(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.PAD_CAMERA_CALIBRATION_NOT_FOUND)); controllerIndexZEDHolder = -2; padsAreInit = true; } else { foreach (SteamVR_Controller.Device d in devices) { if (SteamVR.instance.GetStringProperty(Valve.VR.ETrackedDeviceProperty.Prop_SerialNumber_String, (uint)d.index).Equals(SNHolder)) { controllerIndexZEDHolder = (int)d.index; padsAreInit = true; } } if (controllerIndexZEDHolder == -1 && devices.Count >= 2) { Debug.LogWarning(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.PAD_CAMERA_CALIBRATION_MISMATCH) + SNHolder); } } } if (previousStateIndex != controllerIndexZEDHolder && controllerIndexZEDHolder != -1) { previousStateIndex = controllerIndexZEDHolder; if (ZEDOnPadIndexSet != null) { ZEDOnPadIndexSet(); } } } }
/// <summary> /// If visible, print the loading status of the ZED, including relevant errors. /// </summary> void Update() { if (!init) //This check will pass until 0.5 seconds after the ZED is done initializing. { sl.ERROR_CODE e = zedManager.LastInitStatus; if (e == sl.ERROR_CODE.SUCCESS) //Last initialization attempt was successful. { if (!ready) { if (textmono) { textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_MODULE_LOADING); } else if (textleft) { textleft.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_MODULE_LOADING); textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SDK_MODULE_LOADING); } } else { timer += Time.deltaTime; //Clear text after a short delay. if (timer > 0.2f) { if (textmono) { textmono.text = ""; } else if (textleft) { textleft.text = ""; textright.text = ""; } } if (imagemono) //Disable mono rig canvas. { imagemono.gameObject.SetActive(false); } else if (imageleft) //Disable stereo rig canvases. { imageleft.gameObject.SetActive(false); imageright.gameObject.SetActive(false); } } } else if (e == sl.ERROR_CODE.ERROR_CODE_LAST) //"Loading..." { //Initial error code set before an initialization attempt has returned successful or failed. //In short, it means it's still loading. if (textmono) { textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_LOADING); } else if (textleft) { textleft.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_LOADING); textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_LOADING); } } else if (e == sl.ERROR_CODE.CAMERA_NOT_DETECTED && oldInitStatus == sl.ERROR_CODE.CAMERA_NOT_DETECTED) //"Camera not detected" { if (textmono) { textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.UNABLE_TO_OPEN_CAMERA); } else if (textleft) { textleft.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.UNABLE_TO_OPEN_CAMERA); textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.UNABLE_TO_OPEN_CAMERA); } } else if (e == sl.ERROR_CODE.CAMERA_DETECTION_ISSUE && oldInitStatus == sl.ERROR_CODE.CAMERA_DETECTION_ISSUE) //"Unable to open camera" { if (textmono) { textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_DETECTION_ISSUE); } else if (textleft) { textleft.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_DETECTION_ISSUE); textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_DETECTION_ISSUE); } } else if (e == sl.ERROR_CODE.SENSOR_NOT_DETECTED && oldInitStatus == sl.ERROR_CODE.SENSOR_NOT_DETECTED) //"Camera motion sensor not detected" { if (textmono) { textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SENSOR_NOT_DETECTED); } else if (textleft) { textleft.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SENSOR_NOT_DETECTED); textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SENSOR_NOT_DETECTED); } } else if (e == sl.ERROR_CODE.LOW_USB_BANDWIDTH && oldInitStatus == sl.ERROR_CODE.LOW_USB_BANDWIDTH) //"Low USB bandwidth" { if (textmono) { textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.LOW_USB_BANDWIDTH); } else if (textleft) { textleft.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.LOW_USB_BANDWIDTH); textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.LOW_USB_BANDWIDTH); } } else if (e == sl.ERROR_CODE.INVALID_SVO_FILE && oldInitStatus == sl.ERROR_CODE.INVALID_SVO_FILE) { if (textmono) { textmono.text = "Invalid SVO File/Path"; } else if (textleft) { textleft.text = "Invalid SVO File/Path"; textright.text = "Invalid SVO File/Path"; } } else if (e == oldInitStatus) { if (textmono) { textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_NOT_INITIALIZED); } else if (textleft) { textleft.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_NOT_INITIALIZED); textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_NOT_INITIALIZED); } } oldInitStatus = e; } if (ready) //ZED has finished initializing. Set a timer, then disable texts after it expires. { timerWarning += Time.deltaTime; if (timerWarning > 0.5f) { if (warningmono) { warningmono.SetActive(false); } else if (warningleft) { warningleft.SetActive(false); warningright.SetActive(false); } } init = true; //Prevents logic above the if (ready) check from running each frame. if (imagemono) { imagemono.gameObject.transform.parent.gameObject.SetActive(false); } else if (imageleft) { imageleft.gameObject.transform.parent.gameObject.SetActive(false); imageright.gameObject.transform.parent.gameObject.SetActive(false); } } }
/// <summary> /// Load the mesh and the corresponding area file if it exists. It can be quite time comsuming if you mapped a large area. /// If there are no areas found, the mesh will not be loaded /// </summary> public bool LoadMesh(string meshFilePath = "ZEDMesh.obj") { if (OnMeshStarted != null) { OnMeshStarted(); } //If a spatail mapping have started, disable it DisableSpatialMapping(); //Find and load the area string basePath = meshFilePath.Substring(0, meshFilePath.LastIndexOf(".")); if (!System.IO.File.Exists(basePath + ".area")) { Debug.LogWarning(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.TRACKING_BASE_AREA_NOT_FOUND)); return(false); } zedCamera.DisableTracking(); Quaternion quat = Quaternion.identity; Vector3 tr = Vector3.zero; if (zedCamera.EnableTracking(ref quat, ref tr, true, false, System.IO.File.Exists(basePath + ".area") ? basePath + ".area" : "") != sl.ERROR_CODE.SUCCESS) { Debug.LogWarning(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.TRACKING_NOT_INITIALIZED)); return(false); } updateTexture = false; updatedTexture = false; bool meshUpdatedLoad = false; lock (lockScanning) { ClearMeshes(); meshUpdatedLoad = zedSpatialMapping.LoadMesh(meshFilePath); if (meshUpdatedLoad) { //Checks if a texture exists if (zedSpatialMapping.GetWidthTexture() != -1) { updateTexture = true; updatedTexture = true; } //Retrieves the mesh sizes to be updated in the unity's buffer later if (!updateTexture) { zedSpatialMapping.RetrieveMesh(); } } } if (meshUpdatedLoad) { //Update the buffer on the unity's side UpdateMeshMainthread(false); //Add colliders and scan for gravity if (hasColliders) { if (!ZEDManager.IsStereoRig && gravityEstimation != Vector3.zero) { Quaternion rotationToApplyForGravity = Quaternion.Inverse(Quaternion.FromToRotation(Vector3.up, -gravityEstimation.normalized)); holder.transform.rotation = rotationToApplyForGravity; zedManager.gravityRotation = rotationToApplyForGravity; } UpdateMeshCollider(); foreach (Chunk c in ChunkList) { c.o.transform.localRotation = Quaternion.identity; } } if (OnMeshReady != null) { OnMeshReady(); } return(true); } return(false); }
// Update is called once per frame private void Update() { if (!init) { var e = ZEDManager.LastInitStatus; if (e == ERROR_CODE.SUCCESS) { timer += Time.deltaTime; if (timer > 0.2f) { if (textmono) { textmono.text = ""; } else if (textleft) { textleft.text = ""; textright.text = ""; } } if (imagemono) { imagemono.gameObject.SetActive(false); } else if (imageleft) { imageleft.gameObject.SetActive(false); imageright.gameObject.SetActive(false); } } else if (e == ERROR_CODE.ERROR_CODE_LAST) { if (textmono) { textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_LOADING); //textmono.color = Color.white; } else if (textleft) { textleft.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_LOADING); //textleft.color = Color.white; textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_LOADING); //textright.color = Color.white; } } else if (e == ERROR_CODE.CAMERA_NOT_DETECTED && oldInitStatus == ERROR_CODE.CAMERA_NOT_DETECTED) { if (textmono) { textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.UNABLE_TO_OPEN_CAMERA); } else if (textleft) { textleft.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.UNABLE_TO_OPEN_CAMERA); textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.UNABLE_TO_OPEN_CAMERA); } } else if (e == ERROR_CODE.CAMERA_DETECTION_ISSUE && oldInitStatus == ERROR_CODE.CAMERA_DETECTION_ISSUE) { if (textmono) { textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_DETECTION_ISSUE); } else if (textleft) { textleft.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_DETECTION_ISSUE); textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_DETECTION_ISSUE); } } else if (e == ERROR_CODE.SENSOR_NOT_DETECTED && oldInitStatus == ERROR_CODE.SENSOR_NOT_DETECTED) { if (textmono) { textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SENSOR_NOT_DETECTED); } else if (textleft) { textleft.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SENSOR_NOT_DETECTED); textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.SENSOR_NOT_DETECTED); } } else if (e == ERROR_CODE.LOW_USB_BANDWIDTH && oldInitStatus == ERROR_CODE.LOW_USB_BANDWIDTH) { if (textmono) { textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.LOW_USB_BANDWIDTH); } else if (textleft) { textleft.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.LOW_USB_BANDWIDTH); textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.LOW_USB_BANDWIDTH); } } else if (e == oldInitStatus) { if (textmono) { textmono.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_NOT_INITIALIZED); } else if (textleft) { textleft.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_NOT_INITIALIZED); textright.text = ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.CAMERA_NOT_INITIALIZED); } } oldInitStatus = e; } if (ready) { timerWarning += Time.deltaTime; if (timerWarning > 0.5f) { if (warningmono) { warningmono.SetActive(false); } else if (warningleft) { warningleft.SetActive(false); warningright.SetActive(false); } } init = true; //timerWarning = 0; if (imagemono) { imagemono.gameObject.transform.parent.gameObject.SetActive(false); } else if (imageleft) { imageleft.gameObject.transform.parent.gameObject.SetActive(false); imageright.gameObject.transform.parent.gameObject.SetActive(false); } } }
void OnValidate() { if (zedCamera != null) { if (!isTrackingEnable && enableTracking) { //Enables the tracking and initializes the first position of the camera Quaternion quat = Quaternion.identity; Vector3 vec = new Vector3(0, 0, 0); enablePoseSmoothing = enableSpatialMemory; if (!(enableTracking = (zedCamera.EnableTracking(ref quat, ref vec, enableSpatialMemory, enablePoseSmoothing, pathSpatialMemory) == sl.ERROR_CODE.SUCCESS))) { isZEDTracked = false; throw new Exception(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.TRACKING_NOT_INITIALIZED)); } else { isZEDTracked = true; isTrackingEnable = true; } } if (isTrackingEnable && !enableTracking) { isZEDTracked = false; lock (grabLock) { zedCamera.DisableTracking(); } isTrackingEnable = false; } //Create ZEDTextureOverlay object to handle left images ZEDRenderingPlane textureLeftOverlay = GetLeftCameraTransform().GetComponent <ZEDRenderingPlane>(); textureLeftOverlay.SetPostProcess(postProcessing); Shader.SetGlobalFloat("_ZEDFactorAffectReal", cameraBrightness); //Create ZEDTextureOverlay object to handle Right images if a right camera is present if (IsStereoRig) { ZEDRenderingPlane textureRightOverlay = GetRightCameraTransform().GetComponent <ZEDRenderingPlane>(); textureRightOverlay.SetPostProcess(postProcessing); } if (renderingPath == ZEDRenderingMode.FORWARD) { if (depthOcclusion) { textureLeftOverlay.ManageKeyWordPipe(false, "NO_DEPTH_OCC"); if (IsStereoRig) { textureLeftOverlay.ManageKeyWordPipe(false, "NO_DEPTH_OCC"); } } else { textureLeftOverlay.ManageKeyWordPipe(true, "NO_DEPTH_OCC"); if (IsStereoRig) { textureLeftOverlay.ManageKeyWordPipe(true, "NO_DEPTH_OCC"); } } } else if (renderingPath == ZEDRenderingMode.DEFERRED) { if (depthOcclusion) { textureLeftOverlay.ManageKeyWordDefferedMat(false, "NO_DEPTH_OCC"); if (IsStereoRig) { textureLeftOverlay.ManageKeyWordDefferedMat(false, "NO_DEPTH_OCC"); } } else { textureLeftOverlay.ManageKeyWordDefferedMat(true, "NO_DEPTH_OCC"); if (IsStereoRig) { textureLeftOverlay.ManageKeyWordDefferedMat(true, "NO_DEPTH_OCC"); } } } } }