diff --git a/ZEDCamera/Assets/ZED/Doc/ReleaseNotes.md b/ZEDCamera/Assets/ZED/Doc/ReleaseNotes.md index 0324d6ba..69f00107 100644 --- a/ZEDCamera/Assets/ZED/Doc/ReleaseNotes.md +++ b/ZEDCamera/Assets/ZED/Doc/ReleaseNotes.md @@ -1,15 +1,29 @@ - +### 2.7.0 + + * **Features**: + - Added toggle box to reveal a camera rig used for final HMD output, normally hidden, for advanced users + - Added toggle boxes for the fade-in effect when the ZED initializes, and setting the ZED rig Gameobject to "DontDestroyOnLoad" on start + + + * **Bug Fixes**: + - Fixed Rift/Vive controller drift when using ZED's tracking instead of the HMD's + - Changed the previously hard-coded layers the ZED plugin used (8-11) to be adjusted in the Inspector, and set them to 28-31 by default + - Changed greenscreen config file loading so that it will work in a build when placed in a Resources folder, and changed default save path accordingly + - Clarified error messages from playing SVOs in loop mode with tracking enabled + + + * **Compatibility**: + - Compatible with ZED SDK 2.7, CUDA 9.0 or 10.0. + ### 2.6.0 * **Features/Bug Fixes**: - Add WindowsMR support through SteamVR Only (Beta). - Fixed overwriting old mesh textures when Spatial mapping button is used while Save Mesh is checked. - - Forced pause state to false when starting a new mapping in case it's been left in a pause state from a previous mapping. + - Forced pasue state to false when stating a scan in case it's been left in a pause state from a previous scan. - Fixed restart (not) required when changing post-processing settings. - - Fixed repetitve UI error when not using plugin in VR mode in ZEDControllerTracker.cs. [issue #21 reported on github]. - - Simplified changing near and far planes in camera projection matrix. - - Fixed error messages when a wrong SVO path was provided for record or read. + - Fixed repetitve UI error when not using plugin in VR mode in ZEDControllerTracker.cs. [ssue #21 reported on github]. * **Documentation**: diff --git a/ZEDCamera/Assets/ZED/Editor/Scripts/ZEDCameraEditor.cs b/ZEDCamera/Assets/ZED/Editor/Scripts/ZEDCameraEditor.cs index fe23200f..5750e318 100644 --- a/ZEDCamera/Assets/ZED/Editor/Scripts/ZEDCameraEditor.cs +++ b/ZEDCamera/Assets/ZED/Editor/Scripts/ZEDCameraEditor.cs @@ -13,17 +13,28 @@ public class ZEDCameraEditor : Editor /// /// Reference to the ZEDManager instance we're editing. /// - ZEDManager manager; + ZEDManager manager; //Store copies of ZEDManager's fields to detect changes later with CheckChange(). + //These do not need to be SerializedProperties because they're only used for checking recent changes. sl.RESOLUTION resolution; sl.DEPTH_MODE depthmode; bool usespatialmemory; - bool usedepthocclusion = true; - bool usepostprocessing = true; + bool usedepthocclusion; + bool usepostprocessing; bool restartneeded = false; - + + SerializedProperty showadvanced; //Show advanced settings or not. + + SerializedProperty lefteyelayer; + SerializedProperty righteyelayer; + SerializedProperty lefteyelayerfinal; + SerializedProperty righteyelayerfinal; + + SerializedProperty showarrig; + SerializedProperty fadeinonstart; + SerializedProperty dontdestroyonload; private void OnEnable() { @@ -34,11 +45,23 @@ private void OnEnable() usespatialmemory = manager.enableSpatialMemory; usedepthocclusion = manager.depthOcclusion; usepostprocessing = manager.postProcessing; + + showadvanced = serializedObject.FindProperty("advancedPanelOpen"); + + showarrig = serializedObject.FindProperty("showarrig"); + + lefteyelayer = serializedObject.FindProperty("lefteyelayer"); + righteyelayer = serializedObject.FindProperty("righteyelayer"); + lefteyelayerfinal = serializedObject.FindProperty("lefteyelayerfinal"); + righteyelayerfinal = serializedObject.FindProperty("righteyelayerfinal"); + + fadeinonstart = serializedObject.FindProperty("fadeInOnStart"); + dontdestroyonload = serializedObject.FindProperty("dontDestroyOnLoad"); } public override void OnInspectorGUI() { - DrawDefaultInspector(); //Draws what you'd normally see in the inspector in absense of a custom inspector. + DrawDefaultInspector(); //Draws what you'd normally see in the inspector in absence of a custom inspector. if(GUI.changed) { @@ -72,13 +95,132 @@ public override void OnInspectorGUI() } } - GUIStyle standardStyle = new GUIStyle(EditorStyles.textField); - GUIStyle errorStyle = new GUIStyle(EditorStyles.textField); - errorStyle.normal.textColor = Color.red; + //Advanced Settings. GUILayout.Space(10); + GUIStyle boldfoldout = new GUIStyle(EditorStyles.foldout); + boldfoldout.fontStyle = FontStyle.Bold; + showadvanced.boolValue = EditorGUILayout.Foldout(showadvanced.boolValue, "Advanced Settings", boldfoldout); + if(showadvanced.boolValue) + { + EditorGUI.indentLevel++; + + GUILayout.Space(5); + EditorGUILayout.LabelField("ZED Plugin Layers", EditorStyles.boldLabel); + + //Style for the number boxes. + GUIStyle layerboxstyle = new GUIStyle(EditorStyles.numberField); + layerboxstyle.fixedWidth = 0; + layerboxstyle.stretchWidth = false; + layerboxstyle.alignment = TextAnchor.MiddleCenter; + + GUIStyle layerboxstyleerror = new GUIStyle(layerboxstyle); + layerboxstyleerror.normal.textColor = new Color(.8f, 0, 0); //Red color if number is invalid. + + + GUIContent lefteyelayerlabel = new GUIContent("Left Eye Layer", "Layer that the left canvas GameObject " + + "(showing the image from the left eye) is set to. The right camera in ZED_Rig_Stereo can't see this layer."); + lefteyelayer.intValue = EditorGUILayout.IntField(lefteyelayerlabel, manager.leftEyeLayer, + lefteyelayer.intValue < 32 ? layerboxstyle : layerboxstyleerror); + + GUIContent righteyelayerlabel = new GUIContent("Right Eye Layer", "Layer that the right canvas GameObject " + + "(showing the image from the right eye) is set to. The left camera in ZED_Rig_Stereo can't see this layer."); + righteyelayer.intValue = EditorGUILayout.IntField(righteyelayerlabel, manager.rightEyeLayer, + righteyelayer.intValue < 32 ? layerboxstyle : layerboxstyleerror); + + //Cache current final layers in case we need to unhide their old layers. + int oldleftfinal = manager.leftEyeLayerFinal; + int oldrightfinal = manager.rightEyeLayerFinal; + + GUIContent lefteyefinallayerlabel = new GUIContent("Final Left Eye Layer", "Layer that the final left image canvas " + + "in the hidden AR rig is set to. Hidden from all ZED cameras except the final left camera."); + lefteyelayerfinal.intValue = EditorGUILayout.IntField(lefteyefinallayerlabel, manager.leftEyeLayerFinal, + lefteyelayerfinal.intValue < 32 ? layerboxstyle : layerboxstyleerror); + + GUIContent righteyefinallayerlabel = new GUIContent("Final Right Eye Layer", "Layer that the final right image canvas " + + "in the hidden AR rig is set to. Hidden from all ZED cameras except the final right camera."); + righteyelayerfinal.intValue = EditorGUILayout.IntField(righteyefinallayerlabel, manager.rightEyeLayerFinal, + righteyelayerfinal.intValue < 32 ? layerboxstyle : layerboxstyleerror); + + //If either final eye layer changed, make sure the old layer is made visible. + if (oldleftfinal != lefteyelayerfinal.intValue) + { + Tools.visibleLayers |= (1 << oldleftfinal); + if (manager.showARRig) Tools.visibleLayers |= (1 << lefteyelayerfinal.intValue); + else Tools.visibleLayers &= ~(1 << lefteyelayerfinal.intValue); + } + if (oldrightfinal != righteyelayerfinal.intValue) + { + Tools.visibleLayers |= (1 << oldrightfinal); + if (manager.showARRig) Tools.visibleLayers |= (1 << righteyelayerfinal.intValue); + else Tools.visibleLayers &= ~(1 << righteyelayerfinal.intValue); + } + + //Show small error message if any of the above values are too big. + if(lefteyelayer.intValue > 31 || righteyelayer.intValue > 31 || lefteyelayerfinal.intValue > 31 || righteyelayerfinal.intValue > 31) + { + GUIStyle errormessagestyle = new GUIStyle(EditorStyles.label); + errormessagestyle.normal.textColor = layerboxstyleerror.normal.textColor; + errormessagestyle.wordWrap = true; + errormessagestyle.fontSize = 10; + + string errortext = "Unity doesn't support layers above 31."; + Rect labelrect = GUILayoutUtility.GetRect(new GUIContent(errortext, ""), errormessagestyle); + EditorGUI.LabelField(labelrect, errortext, errormessagestyle); + } + + + GUILayout.Space(7); + + EditorGUILayout.LabelField("Miscellaneous", EditorStyles.boldLabel); + + //Show AR Rig toggle. + GUIContent showarlabel = new GUIContent("Show Final AR Rig", "Whether to show the hidden camera rig used in stereo AR mode to " + + "prepare images for HMD output. You normally shouldn't tamper with this rig, but seeing it can be useful for " + + "understanding how the ZED output works."); + bool lastshowar = manager.showARRig; + showarrig.boolValue = EditorGUILayout.Toggle(showarlabel, manager.showARRig); + + if (showarrig.boolValue != lastshowar) + { + LayerMask arlayers = (1 << manager.leftEyeLayerFinal); + arlayers |= (1 << manager.rightEyeLayerFinal); + + if (showarrig.boolValue == true) + { + Tools.visibleLayers |= arlayers; + } + else + { + Tools.visibleLayers &= ~(arlayers); + } + + if (manager.zedRigDisplayer != null && Application.isPlaying) + { + manager.zedRigDisplayer.hideFlags = showarrig.boolValue ? HideFlags.None : HideFlags.HideAndDontSave; + } + } + + //Fade In At Start toggle. + GUIContent fadeinlabel = new GUIContent("Fade In At Start", "When enabled, makes the ZED image fade in from black when the application starts."); + fadeinonstart.boolValue = EditorGUILayout.Toggle(fadeinlabel, manager.fadeInOnStart); + + //Don't Destroy On Load toggle. + GUIContent dontdestroylable = new GUIContent("Don't Destroy on Load", "When enabled, applies DontDestroyOnLoad() on the ZED rig in Awake(), " + + "preserving it between scene transitions."); + dontdestroyonload.boolValue = EditorGUILayout.Toggle(dontdestroylable, manager.dontDestroyOnLoad); + + EditorGUI.indentLevel--; + } + serializedObject.ApplyModifiedProperties(); //Status window. + GUIStyle standardStyle = new GUIStyle(EditorStyles.textField); + GUIStyle errorStyle = new GUIStyle(EditorStyles.textField); + errorStyle.normal.textColor = Color.red; + + + GUILayout.Space(10); EditorGUILayout.LabelField("Status", EditorStyles.boldLabel); EditorGUI.BeginDisabledGroup(true); diff --git a/ZEDCamera/Assets/ZED/Examples/Drone Shooter/Scenes/DroneBattle.unity b/ZEDCamera/Assets/ZED/Examples/Drone Shooter/Scenes/DroneBattle.unity index 47885125..861b20f7 100644 --- a/ZEDCamera/Assets/ZED/Examples/Drone Shooter/Scenes/DroneBattle.unity +++ b/ZEDCamera/Assets/ZED/Examples/Drone Shooter/Scenes/DroneBattle.unity @@ -227,7 +227,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 093ceb9e77bac7a4ea5ec3013f638a87, type: 3} m_Name: m_EditorClassIdentifier: - SecondsToDisplayEffect: 1 + secondsToDisplayEffect: 1 --- !u!135 &78578991 SphereCollider: m_ObjectHideFlags: 0 @@ -599,6 +599,16 @@ Prefab: propertyPath: m_RootOrder value: 4 objectReference: {fileID: 0} + - target: {fileID: 114228649437443144, guid: d0ab09dfdb72e614aadbc6e474b9bc3e, + type: 2} + propertyPath: m_Enabled + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 114575857264643554, guid: d0ab09dfdb72e614aadbc6e474b9bc3e, + type: 2} + propertyPath: m_Enabled + value: 1 + objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: d0ab09dfdb72e614aadbc6e474b9bc3e, type: 2} m_IsPrefabParent: 0 @@ -974,7 +984,7 @@ MonoBehaviour: m_EditorClassIdentifier: resolution: 2 depthMode: 1 - enableTracking: 0 + enableTracking: 1 enableSpatialMemory: 0 pathSpatialMemory: depthOcclusion: 1 diff --git a/ZEDCamera/Assets/ZED/Examples/Drone Shooter/Scripts/Simple/LaserGun.cs b/ZEDCamera/Assets/ZED/Examples/Drone Shooter/Scripts/Simple/LaserGun.cs index e7700137..c8c6b617 100644 --- a/ZEDCamera/Assets/ZED/Examples/Drone Shooter/Scripts/Simple/LaserGun.cs +++ b/ZEDCamera/Assets/ZED/Examples/Drone Shooter/Scripts/Simple/LaserGun.cs @@ -90,7 +90,7 @@ IEnumerator Start() int children = transform.childCount; for (int i = 0; i < children; ++i) transform.GetChild(i).gameObject.SetActive(false); - this.enabled = false; + //this.enabled = false; } else { @@ -121,7 +121,7 @@ IEnumerator Start() for (int i = 0; i < children; ++i) transform.GetChild(i).gameObject.SetActive(false); - this.enabled = false; + //this.enabled = false; yield break; } } @@ -169,8 +169,24 @@ void Update () #if ZED_OCULUS - //We're controlling the fire Rate OVRInput doesn't have a GetDown function for the IndexTrigger. Only an axis output. + //Update whether the Touch controllers are active. + int children = transform.childCount; + if (OVRManager.isHmdPresent) + { + if (OVRInput.GetConnectedControllers().ToString() == "Touch") + { + for (int i = 0; i < children; ++i) + transform.GetChild(i).gameObject.SetActive(true); + + } + else + { + for (int i = 0; i < children; ++i) + transform.GetChild(i).gameObject.SetActive(false); + } + } + //We're controlling the fire Rate. OVRInput doesn't have a GetDown function for the IndexTrigger. Only an axis output. if (objecttracker != null) { if (OVRInput.GetConnectedControllers().ToString() == "Touch") diff --git a/ZEDCamera/Assets/ZED/Examples/Plane Detection/Scripts/BunnyPlacement.cs b/ZEDCamera/Assets/ZED/Examples/Plane Detection/Scripts/BunnyPlacement.cs index 920c375a..48ec92bb 100644 --- a/ZEDCamera/Assets/ZED/Examples/Plane Detection/Scripts/BunnyPlacement.cs +++ b/ZEDCamera/Assets/ZED/Examples/Plane Detection/Scripts/BunnyPlacement.cs @@ -158,7 +158,7 @@ private void Update() } #elif ZED_OCULUS //Check if a Controller is tracked. - if ((int)trackedObj.deviceToTrack == 0) + if ((int)tracker.deviceToTrack == 0) { //Oculus Touch Triggers aren't of Button type, but Axis. //So we have to create our own state for this Input, based on sensitivity from 0 to 1. @@ -186,7 +186,7 @@ private void Update() } } - if ((int)trackedObj.deviceToTrack == 1) + if ((int)tracker.deviceToTrack == 1) { if (OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, OVRInput.Controller.LTouch) > 0.5f) { diff --git a/ZEDCamera/Assets/ZED/Examples/Planetarium/Scene/Planetarium.unity b/ZEDCamera/Assets/ZED/Examples/Planetarium/Scene/Planetarium.unity index 45dd725c..f7238753 100644 --- a/ZEDCamera/Assets/ZED/Examples/Planetarium/Scene/Planetarium.unity +++ b/ZEDCamera/Assets/ZED/Examples/Planetarium/Scene/Planetarium.unity @@ -187,6 +187,90 @@ Prefab: propertyPath: RotationSpeed value: 0.1 objectReference: {fileID: 0} + - target: {fileID: 1456418382124404, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1065894053398672, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1327679182319948, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1068935605675398, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1113639041239522, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1876509408940188, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1395855026228300, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1967069747994080, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1406497146423282, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1216053433610926, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1429850908920910, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1547112317890944, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1473399838425352, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1777340317518810, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1193364920799576, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1664414613987934, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1167300427754674, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1381048154563754, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1836139974460200, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1803114377679374, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 1601571556097408, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} + propertyPath: m_Layer + value: 0 + objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: dda0baf117c99c04dbb8fb1c9e2d1c69, type: 2} m_IsPrefabParent: 0 @@ -234,6 +318,46 @@ Prefab: propertyPath: enableSpatialMemory value: 0 objectReference: {fileID: 0} + - target: {fileID: 114711245158774928, guid: e13ee7e0790c7d243b7aa67fe604acac, + type: 2} + propertyPath: lefteyelayer + value: 28 + objectReference: {fileID: 0} + - target: {fileID: 114711245158774928, guid: e13ee7e0790c7d243b7aa67fe604acac, + type: 2} + propertyPath: lefteyelayerfinal + value: 30 + objectReference: {fileID: 0} + - target: {fileID: 114711245158774928, guid: e13ee7e0790c7d243b7aa67fe604acac, + type: 2} + propertyPath: showarrig + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 114711245158774928, guid: e13ee7e0790c7d243b7aa67fe604acac, + type: 2} + propertyPath: righteyelayer + value: 29 + objectReference: {fileID: 0} + - target: {fileID: 114711245158774928, guid: e13ee7e0790c7d243b7aa67fe604acac, + type: 2} + propertyPath: advancedPanelOpen + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 114711245158774928, guid: e13ee7e0790c7d243b7aa67fe604acac, + type: 2} + propertyPath: righteyelayerfinal + value: 31 + objectReference: {fileID: 0} + - target: {fileID: 114711245158774928, guid: e13ee7e0790c7d243b7aa67fe604acac, + type: 2} + propertyPath: fadeInOnStart + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 114711245158774928, guid: e13ee7e0790c7d243b7aa67fe604acac, + type: 2} + propertyPath: dontDestroyOnLoad + value: 0 + objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: e13ee7e0790c7d243b7aa67fe604acac, type: 2} m_IsPrefabParent: 0 @@ -269,7 +393,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 454b1f0b0de2bb644a283d964ccf7f06, type: 3} m_Name: m_EditorClassIdentifier: - index: -1 deviceToTrack: 1 latencyCompensation: 78 SNHolder: @@ -313,7 +436,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 454b1f0b0de2bb644a283d964ccf7f06, type: 3} m_Name: m_EditorClassIdentifier: - index: -1 deviceToTrack: 0 latencyCompensation: 78 SNHolder: diff --git a/ZEDCamera/Assets/ZED/SDK/Helpers/Scripts/Display/ZEDRenderingPlane.cs b/ZEDCamera/Assets/ZED/SDK/Helpers/Scripts/Display/ZEDRenderingPlane.cs index 91ac2518..26e6a14f 100644 --- a/ZEDCamera/Assets/ZED/SDK/Helpers/Scripts/Display/ZEDRenderingPlane.cs +++ b/ZEDCamera/Assets/ZED/SDK/Helpers/Scripts/Display/ZEDRenderingPlane.cs @@ -388,7 +388,8 @@ private void Start() void ZEDReady() { //Add the fade-in effect for when the camera first becomes visible. - gameObject.AddComponent(); + if(ZEDManager.Instance.fadeInOnStart) gameObject.AddComponent(); + zedCamera = sl.ZEDCamera.GetInstance(); SetTextures(zedCamera,viewMode); canvas.SetActive(true); diff --git a/ZEDCamera/Assets/ZED/SDK/Helpers/Scripts/Interactions/ZEDControllerTracker.cs b/ZEDCamera/Assets/ZED/SDK/Helpers/Scripts/Interactions/ZEDControllerTracker.cs index 78c52729..6a6d6dcf 100644 --- a/ZEDCamera/Assets/ZED/SDK/Helpers/Scripts/Interactions/ZEDControllerTracker.cs +++ b/ZEDCamera/Assets/ZED/SDK/Helpers/Scripts/Interactions/ZEDControllerTracker.cs @@ -1,4 +1,5 @@ using UnityEngine; +using UnityEngine.VR; using System.Collections.Generic; #if ZED_STEAM_VR using Valve.VR; @@ -113,6 +114,12 @@ public enum Devices " If specified, overrides the 'Device to Track' selection.")] public string SNHolder = ""; + /// + /// Cached transform that represents the ZED's head, retrieved from ZEDManager.GetZedRootTransform(). + /// Used to find the offset between the HMD and tracked transform to compensate for drift. + /// + private Transform zedRigRoot; + /// /// Sets up the timed pose dictionary and identifies the VR SDK being used. /// @@ -122,6 +129,8 @@ void Awake() poseData.Add(1, new List()); //Create the list within the dictionary with its key and value. //Looking for the loaded device loadeddevice = UnityEngine.VR.VRSettings.loadedDeviceName; + + zedRigRoot = ZEDManager.Instance.GetZedRootTansform(); } /// @@ -405,6 +414,11 @@ private void RegisterPosition(int keyindex, Vector3 position, Quaternion rot) currentPoseData.timestamp = Time.time; currentPoseData.rotation = rot; currentPoseData.position = position; + + //Compensate for positional drift by measuring the distance between HMD and ZED rig root (the head's center). + Vector3 zedhmdposoffset = zedRigRoot.position - InputTracking.GetLocalPosition(VRNode.Head); + currentPoseData.position += zedhmdposoffset; + poseData[keyindex].Add(currentPoseData); } diff --git a/ZEDCamera/Assets/ZED/SDK/Helpers/Scripts/Utilities/ZEDSVOManager.cs b/ZEDCamera/Assets/ZED/SDK/Helpers/Scripts/Utilities/ZEDSVOManager.cs index e09b563e..97017ed0 100644 --- a/ZEDCamera/Assets/ZED/SDK/Helpers/Scripts/Utilities/ZEDSVOManager.cs +++ b/ZEDCamera/Assets/ZED/SDK/Helpers/Scripts/Utilities/ZEDSVOManager.cs @@ -60,7 +60,7 @@ public class ZEDSVOManager : MonoBehaviour "Dropped frames will cause a 'pause' in playback instead of a 'skip.'")] [SerializeField] [HideInInspector] - public bool realtimePlayback = true; + public bool realtimePlayback = false; /// /// Current frame being read from the SVO. Doesn't apply when recording. @@ -118,7 +118,7 @@ public int NumberFrameMax [Tooltip("Compression mode used when recording an SVO. " + "Uncompressed SVOs are extremely large (multiple gigabytes per minute).")] [SerializeField] - public sl.SVO_COMPRESSION_MODE compressionMode = sl.SVO_COMPRESSION_MODE.LOSSY_BASED; + public sl.SVO_COMPRESSION_MODE compressionMode = sl.SVO_COMPRESSION_MODE.AVCHD_BASED; /// /// Flag set to true when we need to force ZEDManager to grab a new frame, even though diff --git a/ZEDCamera/Assets/ZED/SDK/Helpers/Scripts/ZEDManager.cs b/ZEDCamera/Assets/ZED/SDK/Helpers/Scripts/ZEDManager.cs index 54aa67a9..ad565f17 100644 --- a/ZEDCamera/Assets/ZED/SDK/Helpers/Scripts/ZEDManager.cs +++ b/ZEDCamera/Assets/ZED/SDK/Helpers/Scripts/ZEDManager.cs @@ -60,6 +60,7 @@ public class ZEDManager : MonoBehaviour /// then the Camera_eyes object in ZED_Rig_Stereo will move while this object stays still. /// [Header("Motion Tracking")] + [Tooltip("If enabled, the ZED will move/rotate itself using its own inside-out tracking. " + "If false, the camera tracking will move with the VR HMD if connected and available.")] public bool enableTracking = true; @@ -125,6 +126,17 @@ public float CameraBrightness OnCamBrightnessChange(m_cameraBrightness); } } + /// + /// True to make the ZED image fade from black when the application starts. + /// + [HideInInspector] + public bool fadeInOnStart = true; + /// + /// True to apply DontDestroyOnLoad() on the ZED rig in Awake(), preserving it between scenes. + /// + [HideInInspector] + public bool dontDestroyOnLoad = false; + /// /// Delegate for OnCamBrightnessChange, which is used to update shader properties when the brightness setting changes. /// @@ -135,7 +147,32 @@ public float CameraBrightness /// public event onCamBrightnessChangeDelegate OnCamBrightnessChange; + /// + /// Whether to show the hidden camera rig used in stereo AR mode to prepare images for HMD output. + /// + [SerializeField] + [HideInInspector] + private bool showarrig = false; + /// + /// Whether to show the hidden camera rig used in stereo AR mode to prepare images for HMD output. + /// This is rarely needed, but can be useful for understanding how the ZED output works. + /// + public bool showARRig + { + get + { + return showarrig; + } + set + { + if(Application.isPlaying && showarrig != value && zedRigDisplayer != null) + { + zedRigDisplayer.hideFlags = value ? HideFlags.None : HideFlags.HideAndDontSave; + } + showarrig = value; + } + } //Strings used for the Status display in the Inspector. /// @@ -365,6 +402,14 @@ public sl.TRACKING_STATE ZEDTrackingState /// private Transform zedRigRoot = null; + /// + /// Whether the 'Advanced Settings' panel in the editor was open when used last, so the editor will + /// display it as it was last time. + /// + [SerializeField] + [HideInInspector] + private bool advancedPanelOpen = false; + /// /// Gets the center transform, which is the transform moved by the tracker in AR mode. /// This is the root object in ZED_Rig_Mono, and Camera_eyes in ZED_Rig_Stereo. @@ -441,22 +486,76 @@ public ulong ImageTimeStamp /// Layer that the left canvas GameObject (showing the image from the left eye) is set to. /// The right camera in ZED_Rig_Stereo can't see this layer. /// - private int layerLeftScreen = 8; + [SerializeField] + [HideInInspector] + private int lefteyelayer = 28; + /// + /// Layer that the left canvas GameObject (showing the image from the left eye) is set to. + /// The right camera in ZED_Rig_Stereo can't see this layer. + /// + public int leftEyeLayer + { + get + { + return lefteyelayer; + } + } + /// + /// Layer that the right canvas GameObject (showing the image from the right eye) is set to. + /// The left camera in ZED_Rig_Stereo can't see this layer. + /// + [SerializeField] + [HideInInspector] + private int righteyelayer = 29; /// /// Layer that the right canvas GameObject (showing the image from the right eye) is set to. /// The left camera in ZED_Rig_Stereo can't see this layer. /// - private int layerRightScreen = 10; + public int rightEyeLayer + { + get + { + return righteyelayer; + } + } + + /// + /// Layer that the final left image canvas in the hidden AR rig is set to. (See CreateZEDRigDisplayer()) + /// Hidden from all ZED cameras except the final left camera. + /// + [SerializeField] + [HideInInspector] + private int lefteyelayerfinal = 30; /// /// Layer that the final left image canvas in the hidden AR rig is set to. (See CreateZEDRigDisplayer()) /// Hidden from all ZED cameras except the final left camera. /// - private int layerLeftFinalScreen = 9; + public int leftEyeLayerFinal + { + get + { + return lefteyelayerfinal; + } + } + + /// + /// Layer that the final right image canvas in the hidden AR rig is set to. (See CreateZEDRigDisplayer()) + /// Hidden from all ZED cameras except the final right camera. + /// + [SerializeField] + [HideInInspector] + private int righteyelayerfinal = 31; /// /// Layer that the final right image canvas in the hidden AR rig is set to. (See CreateZEDRigDisplayer()) /// Hidden from all ZED cameras except the final right camera. /// - private int layerRightFinalScreen = 11; + public int rightEyeLayerFinal + { + get + { + return righteyelayerfinal; + } + } ///////////////////////////////////// @@ -520,20 +619,20 @@ private void CheckStereoMode() if (cam.stereoTargetEye == StereoTargetEyeMask.Left) { cameraLeft = cam.transform; - SetLayerRecursively(cameraLeft.gameObject, layerLeftScreen); + SetLayerRecursively(cameraLeft.gameObject, lefteyelayer); - cam.cullingMask &= ~(1 << layerRightScreen); - cam.cullingMask &= ~(1 << layerRightFinalScreen); - cam.cullingMask &= ~(1 << layerLeftFinalScreen); + cam.cullingMask &= ~(1 << righteyelayer); + cam.cullingMask &= ~(1 << righteyelayerfinal); + cam.cullingMask &= ~(1 << lefteyelayerfinal); cam.cullingMask &= ~(1 << sl.ZEDCamera.TagOneObject); } else if (cam.stereoTargetEye == StereoTargetEyeMask.Right) { cameraRight = cam.transform; - SetLayerRecursively(cameraRight.gameObject, layerRightScreen); - cam.cullingMask &= ~(1 << layerLeftScreen); - cam.cullingMask &= ~(1 << layerLeftFinalScreen); - cam.cullingMask &= ~(1 << layerRightFinalScreen); + SetLayerRecursively(cameraRight.gameObject, righteyelayer); + cam.cullingMask &= ~(1 << lefteyelayer); + cam.cullingMask &= ~(1 << lefteyelayerfinal); + cam.cullingMask &= ~(1 << righteyelayerfinal); cam.cullingMask &= ~(1 << sl.ZEDCamera.TagOneObject); } @@ -573,13 +672,13 @@ private void CheckStereoMode() { if (c != temp) { - c.cullingMask &= ~(1 << layerLeftScreen); + c.cullingMask &= ~(1 << lefteyelayer); c.cullingMask &= ~(1 << sl.ZEDCamera.Tag); } } if (cameraLeft.gameObject.transform.childCount > 0) { - cameraLeft.transform.GetChild(0).gameObject.layer = layerLeftScreen; + cameraLeft.transform.GetChild(0).gameObject.layer = lefteyelayer; } } } @@ -647,6 +746,14 @@ void OnApplicationQuit() zedCamera.Destroy(); zedCamera = null; } + + //Restore the AR layers that were hidden, if necessary. + if (!showarrig) + { + LayerMask layerNumberBinary = (1 << righteyelayerfinal); //Convert layer index into binary number. + layerNumberBinary |= (1 << lefteyelayerfinal); + UnityEditor.Tools.visibleLayers |= (layerNumberBinary); + } } /// @@ -657,8 +764,8 @@ void Awake() instance = this; zedReady = false; - DontDestroyOnLoad(transform.root); //If you want the ZED rig not to be destroyed when loading a scene. - + if(dontDestroyOnLoad) DontDestroyOnLoad(transform.root); //If you want the ZED rig not to be destroyed when loading a scene. + //Set first few parameters for initialization. This will get passed to the ZED SDK when initialized. initParameters = new sl.InitParameters(); initParameters.resolution = resolution; @@ -848,8 +955,8 @@ void AdjustZEDRigCameraPosition() //zedRigRoot transform (origin of the global camera) is placed on the HMD headset. Therefore, we move the //camera in front of it by offsetHmdZEDPosition to compensate for the ZED's position on the headset. //If values are wrong, tweak calibration file created in ZEDMixedRealityPlugin. - cameraLeft.localPosition = ar.HmdToZEDCalibration.translation; - cameraLeft.localRotation = ar.HmdToZEDCalibration.rotation; + cameraLeft.localPosition = arRig.HmdToZEDCalibration.translation; + cameraLeft.localRotation = arRig.HmdToZEDCalibration.rotation; if (cameraRight) cameraRight.localPosition = cameraLeft.localPosition + rightCameraOffset; //Space the eyes apart. if (cameraRight) cameraRight.localRotation = cameraLeft.localRotation; } @@ -1053,7 +1160,7 @@ private void ZEDReady() if (isStereoRig && VRDevice.isPresent) { - ZEDMixedRealityPlugin.Pose pose = ar.InitTrackingAR(); + ZEDMixedRealityPlugin.Pose pose = arRig.InitTrackingAR(); OriginPosition = pose.translation; OriginRotation = pose.rotation; zedRigRoot.localPosition = OriginPosition; @@ -1170,7 +1277,7 @@ public void UpdateImages() { if (!(enableTracking = (zedCamera.ResetTracking(initialRotation, initialPosition) == sl.ERROR_CODE.SUCCESS))) { - throw new Exception("Error: Tracking not available after SVO playback has looped."); + Debug.LogError("ZED Tracking disabled: Not available during SVO playback when Loop is enabled."); } zedRigRoot.localPosition = initialPosition; @@ -1213,15 +1320,15 @@ private void UpdateTracking() calibrationHasChanged = false; } - ar.ExtractLatencyPose (imageTimeStamp); //Find what HMD's pose was at ZED image's timestamp for latency compensation. - ar.AdjustTrackingAR (zedPosition, zedOrientation, out r, out v); + arRig.ExtractLatencyPose (imageTimeStamp); //Find what HMD's pose was at ZED image's timestamp for latency compensation. + arRig.AdjustTrackingAR (zedPosition, zedOrientation, out r, out v); zedRigRoot.localRotation = r; zedRigRoot.localPosition = v; ZEDSyncPosition = v; ZEDSyncRotation = r; - HMDSyncPosition = ar.LatencyPose ().translation; - HMDSyncRotation = ar.LatencyPose ().rotation; + HMDSyncPosition = arRig.LatencyPose ().translation; + HMDSyncRotation = arRig.LatencyPose ().rotation; } else //Not AR pass-through mode. { @@ -1231,9 +1338,9 @@ private void UpdateTracking() } else if (VRDevice.isPresent && isStereoRig) //ZED tracking is off but HMD tracking is on. Fall back to that. { isCameraTracked = true; - ar.ExtractLatencyPose (imageTimeStamp); //Find what HMD's pose was at ZED image's timestamp for latency compensation. - zedRigRoot.localRotation = ar.LatencyPose ().rotation; - zedRigRoot.localPosition = ar.LatencyPose ().translation; + arRig.ExtractLatencyPose (imageTimeStamp); //Find what HMD's pose was at ZED image's timestamp for latency compensation. + zedRigRoot.localRotation = arRig.LatencyPose ().rotation; + zedRigRoot.localPosition = arRig.LatencyPose ().translation; } else //The ZED is not tracked by itself or an HMD. isCameraTracked = false; @@ -1247,7 +1354,7 @@ private void UpdateTracking() void UpdateHmdPose() { if (IsStereoRig && VRDevice.isPresent) - ar.CollectPose(); //Save headset pose with current timestamp. + arRig.CollectPose(); //Save headset pose with current timestamp. } /// @@ -1296,7 +1403,7 @@ public void LateUpdate() { if (IsStereoRig && VRDevice.isPresent) { - ar.LateUpdateHmdRendering(); //Update textures on final AR rig for output to the headset. + arRig.LateUpdateHmdRendering(); //Update textures on final AR rig for output to the headset. } } #endregion @@ -1322,11 +1429,16 @@ private void OnDestroy() } -#region AR_CAMERAS - private GameObject zedRigDisplayer; - private ZEDMixedRealityPlugin ar; + #region AR_CAMERAS /// - /// Create a GameObject to display the ZED in an headset (ZED-M Only) + /// Stereo rig that adjusts images from ZED_Rig_Stereo to look correct in the HMD. + /// Hidden by default as it rarely needs to be changed. + /// + [HideInInspector] + public GameObject zedRigDisplayer; + private ZEDMixedRealityPlugin arRig; + /// + /// Create a GameObject to display the ZED in an headset (ZED-M Only). /// /// private GameObject CreateZEDRigDisplayer() @@ -1335,10 +1447,9 @@ private GameObject CreateZEDRigDisplayer() if (zedRigDisplayer != null) return zedRigDisplayer; zedRigDisplayer = new GameObject("ZEDRigDisplayer"); - ar = zedRigDisplayer.AddComponent(); + arRig = zedRigDisplayer.AddComponent(); - - /*Screens : Left and right */ + /*Screens left and right */ GameObject leftScreen = GameObject.CreatePrimitive(PrimitiveType.Quad); MeshRenderer meshLeftScreen = leftScreen.GetComponent(); meshLeftScreen.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off; @@ -1347,7 +1458,7 @@ private GameObject CreateZEDRigDisplayer() meshLeftScreen.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion; meshLeftScreen.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; meshLeftScreen.sharedMaterial = Resources.Load("Materials/Unlit/Mat_ZED_Unlit") as Material; - leftScreen.layer = layerLeftFinalScreen; + leftScreen.layer = lefteyelayerfinal; GameObject.Destroy(leftScreen.GetComponent()); GameObject rightScreen = GameObject.CreatePrimitive(PrimitiveType.Quad); @@ -1359,7 +1470,7 @@ private GameObject CreateZEDRigDisplayer() meshRightScreen.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; GameObject.Destroy(rightScreen.GetComponent()); meshRightScreen.sharedMaterial = Resources.Load("Materials/Unlit/Mat_ZED_Unlit") as Material; - rightScreen.layer = layerRightFinalScreen; + rightScreen.layer = righteyelayerfinal; /*Camera left and right*/ GameObject camLeft = new GameObject("cameraLeft"); @@ -1369,7 +1480,7 @@ private GameObject CreateZEDRigDisplayer() camL.renderingPath = RenderingPath.Forward;//Minimal overhead camL.clearFlags = CameraClearFlags.Color; camL.backgroundColor = Color.black; - camL.cullingMask = 1 << layerLeftFinalScreen; + camL.cullingMask = 1 << lefteyelayerfinal; camL.allowHDR = false; camL.allowMSAA = false; @@ -1380,30 +1491,33 @@ private GameObject CreateZEDRigDisplayer() camR.clearFlags = CameraClearFlags.Color; camR.backgroundColor = Color.black; camR.stereoTargetEye = StereoTargetEyeMask.Both; //Temporary setting to fix loading screen issue. - camR.cullingMask = 1 << layerRightFinalScreen; + camR.cullingMask = 1 << righteyelayerfinal; camR.allowHDR = false; camR.allowMSAA = false; - SetLayerRecursively (camRight, layerRightFinalScreen); - SetLayerRecursively (camLeft, layerLeftFinalScreen); - - //Hide camera in editor + SetLayerRecursively (camRight, righteyelayerfinal); + SetLayerRecursively (camLeft, lefteyelayerfinal); + + //Hide camera in editor. #if UNITY_EDITOR - LayerMask layerNumberBinary = (1 << layerRightFinalScreen); //Convert layer index into binary number. - layerNumberBinary |= (1 << layerLeftFinalScreen); - LayerMask flippedVisibleLayers = ~UnityEditor.Tools.visibleLayers; - UnityEditor.Tools.visibleLayers = ~(flippedVisibleLayers | layerNumberBinary); + if (!showarrig) + { + LayerMask layerNumberBinary = (1 << righteyelayerfinal); //Convert layer index into binary number. + layerNumberBinary |= (1 << lefteyelayerfinal); + LayerMask flippedVisibleLayers = ~UnityEditor.Tools.visibleLayers; + UnityEditor.Tools.visibleLayers = ~(flippedVisibleLayers | layerNumberBinary); + } #endif leftScreen.transform.SetParent(zedRigDisplayer.transform); rightScreen.transform.SetParent(zedRigDisplayer.transform); - ar.finalCameraLeft = camLeft; - ar.finalCameraRight = camRight; - ar.ZEDEyeLeft = cameraLeft.gameObject; - ar.ZEDEyeRight = cameraRight.gameObject; - ar.quadLeft = leftScreen.transform; - ar.quadRight = rightScreen.transform; + arRig.finalCameraLeft = camLeft; + arRig.finalCameraRight = camRight; + arRig.ZEDEyeLeft = cameraLeft.gameObject; + arRig.ZEDEyeRight = cameraRight.gameObject; + arRig.quadLeft = leftScreen.transform; + arRig.quadRight = rightScreen.transform; ZEDMixedRealityPlugin.OnHmdCalibChanged += CalibrationHasChanged; @@ -1475,7 +1589,6 @@ public void Reset() } - #region EventHandler /// /// Changes the real-world brightness by setting the brightness value in the shaders. diff --git a/ZEDCamera/Assets/ZED/SDK/NativeInterface/ZEDCamera.cs b/ZEDCamera/Assets/ZED/SDK/NativeInterface/ZEDCamera.cs index 3b723a87..f4aeae25 100644 --- a/ZEDCamera/Assets/ZED/SDK/NativeInterface/ZEDCamera.cs +++ b/ZEDCamera/Assets/ZED/SDK/NativeInterface/ZEDCamera.cs @@ -286,7 +286,7 @@ public static int TagOneObject /// /// Cuurent Plugin Version. /// - public static readonly System.Version PluginVersion = new System.Version(2, 6, 0); + public static readonly System.Version PluginVersion = new System.Version(2, 7, 0); /******** DLL members ***********/ @@ -1076,7 +1076,7 @@ public void ResetSelfCalibration() /// Filename. Whether it ends with .svo or .avi defines its file type. /// How much compression to use /// An ERROR_CODE that defines if the file was successfully created and can be filled with images. - public ERROR_CODE EnableRecording(string videoFileName, SVO_COMPRESSION_MODE compressionMode = SVO_COMPRESSION_MODE.LOSSLESS_BASED) + public ERROR_CODE EnableRecording(string videoFileName, SVO_COMPRESSION_MODE compressionMode = SVO_COMPRESSION_MODE.AVCHD_BASED) { return (ERROR_CODE)dllz_enable_recording(StringUtf8ToByte(videoFileName), (int)compressionMode); } diff --git a/ZEDCamera/Assets/ZED/SDK/NativeInterface/ZEDCommon.cs b/ZEDCamera/Assets/ZED/SDK/NativeInterface/ZEDCommon.cs index bf53bf8b..f12f5ddb 100644 --- a/ZEDCamera/Assets/ZED/SDK/NativeInterface/ZEDCommon.cs +++ b/ZEDCamera/Assets/ZED/SDK/NativeInterface/ZEDCommon.cs @@ -746,7 +746,15 @@ public enum SVO_COMPRESSION_MODE /// /// Lossy compression based on jpeg. Average size = 22% of RAW. /// - LOSSY_BASED + LOSSY_BASED, + /// + /// AVCHD Based compression (H264). Available since ZED SDK 2.7 + /// + AVCHD_BASED, + /// + /// HEVC Based compression (H265). Available since ZED SDK 2.7 + /// + HEVC_BASED, } /// diff --git a/ZEDCamera/Assets/ZED/SDK/Plugins/win64/sl_unitywrapper.dll b/ZEDCamera/Assets/ZED/SDK/Plugins/win64/sl_unitywrapper.dll index f952a2b7..ccbf8a43 100644 Binary files a/ZEDCamera/Assets/ZED/SDK/Plugins/win64/sl_unitywrapper.dll and b/ZEDCamera/Assets/ZED/SDK/Plugins/win64/sl_unitywrapper.dll differ