From f2ed85e72141ea9c08bb7078a44a9007d022366c Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Sun, 29 Nov 2020 12:59:29 -0500 Subject: [PATCH] Fix/boundary system (#705) * Updated the boundary system so that it doesn't throw errors when no boundary data providers are registered for that platform * fixed boundary system profile inspector references * updated submodules --- Submodules/Examples | 2 +- Submodules/SDK | 2 +- Submodules/WindowsMixedReality | 2 +- ...tyBoundaryVisualizationProfileInspector.cs | 2 +- ...MixedRealityToolkitRootProfileInspector.cs | 8 +- ...file.cs => MixedRealityBoundaryProfile.cs} | 6 +- ...ta => MixedRealityBoundaryProfile.cs.meta} | 0 .../MixedRealityToolkitRootProfile.cs | 11 +- .../Utilities/ProfileMenuItemIndices.cs | 4 +- .../IMixedRealityBoundarySystem.cs | 9 ++ .../MixedRealityBoundarySystem.cs | 111 ++++++++++-------- .../Runtime/Services/MixedRealityToolkit.cs | 4 +- 12 files changed, 92 insertions(+), 69 deletions(-) rename XRTK-Core/Packages/com.xrtk.core/Runtime/Definitions/BoundarySystem/{MixedRealityBoundaryVisualizationProfile.cs => MixedRealityBoundaryProfile.cs} (92%) rename XRTK-Core/Packages/com.xrtk.core/Runtime/Definitions/BoundarySystem/{MixedRealityBoundaryVisualizationProfile.cs.meta => MixedRealityBoundaryProfile.cs.meta} (100%) diff --git a/Submodules/Examples b/Submodules/Examples index be87a333b..1d82e9652 160000 --- a/Submodules/Examples +++ b/Submodules/Examples @@ -1 +1 @@ -Subproject commit be87a333b5a05bf8b2e3d27e3be14307bd8aa1ea +Subproject commit 1d82e9652f22aaa0a02c852a70207ce5211b4a0f diff --git a/Submodules/SDK b/Submodules/SDK index c2cfc65af..2d52a9796 160000 --- a/Submodules/SDK +++ b/Submodules/SDK @@ -1 +1 @@ -Subproject commit c2cfc65af20d46a0d25b53e2c9071a6e581e1353 +Subproject commit 2d52a9796bf7da7c7af53a86c18081a555790a03 diff --git a/Submodules/WindowsMixedReality b/Submodules/WindowsMixedReality index fa3f2e1b7..397e391c8 160000 --- a/Submodules/WindowsMixedReality +++ b/Submodules/WindowsMixedReality @@ -1 +1 @@ -Subproject commit fa3f2e1b7a6df2bfae6597421a55ec83209b407f +Subproject commit 397e391c87541a4784b82b163231f7d7addae097 diff --git a/XRTK-Core/Packages/com.xrtk.core/Editor/Profiles/MixedRealityBoundaryVisualizationProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Editor/Profiles/MixedRealityBoundaryVisualizationProfileInspector.cs index 034a4bba9..06d70a34f 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Editor/Profiles/MixedRealityBoundaryVisualizationProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Editor/Profiles/MixedRealityBoundaryVisualizationProfileInspector.cs @@ -8,7 +8,7 @@ namespace XRTK.Editor.Profiles { - [CustomEditor(typeof(MixedRealityBoundaryVisualizationProfile))] + [CustomEditor(typeof(MixedRealityBoundaryProfile))] public class MixedRealityBoundaryVisualizationProfileInspector : MixedRealityServiceProfileInspector { private SerializedProperty showBoundary; diff --git a/XRTK-Core/Packages/com.xrtk.core/Editor/Profiles/MixedRealityToolkitRootProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Editor/Profiles/MixedRealityToolkitRootProfileInspector.cs index ee716be19..42d33824e 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Editor/Profiles/MixedRealityToolkitRootProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Editor/Profiles/MixedRealityToolkitRootProfileInspector.cs @@ -26,7 +26,7 @@ public class MixedRealityToolkitRootProfileInspector : BaseMixedRealityProfileIn // Boundary system properties private SerializedProperty enableBoundarySystem; private SerializedProperty boundarySystemType; - private SerializedProperty boundaryVisualizationProfile; + private SerializedProperty boundarySystemProfile; // Teleport system properties private SerializedProperty enableTeleportSystem; @@ -131,7 +131,7 @@ protected override void OnEnable() // Boundary system configuration enableBoundarySystem = serializedObject.FindProperty(nameof(enableBoundarySystem)); boundarySystemType = serializedObject.FindProperty(nameof(boundarySystemType)); - boundaryVisualizationProfile = serializedObject.FindProperty(nameof(boundaryVisualizationProfile)); + boundarySystemProfile = serializedObject.FindProperty(nameof(boundarySystemProfile)); // Teleport system configuration enableTeleportSystem = serializedObject.FindProperty(nameof(enableTeleportSystem)); @@ -196,8 +196,8 @@ internal void RenderSystemFields() EditorGUI.indentLevel++; typeLabel.tooltip = boundarySystemType.tooltip; EditorGUILayout.PropertyField(boundarySystemType, typeLabel); - profileLabel.tooltip = boundaryVisualizationProfile.tooltip; - EditorGUILayout.PropertyField(boundaryVisualizationProfile, profileLabel); + profileLabel.tooltip = boundarySystemProfile.tooltip; + EditorGUILayout.PropertyField(boundarySystemProfile, profileLabel); EditorGUI.indentLevel--; // Teleport System configuration diff --git a/XRTK-Core/Packages/com.xrtk.core/Runtime/Definitions/BoundarySystem/MixedRealityBoundaryVisualizationProfile.cs b/XRTK-Core/Packages/com.xrtk.core/Runtime/Definitions/BoundarySystem/MixedRealityBoundaryProfile.cs similarity index 92% rename from XRTK-Core/Packages/com.xrtk.core/Runtime/Definitions/BoundarySystem/MixedRealityBoundaryVisualizationProfile.cs rename to XRTK-Core/Packages/com.xrtk.core/Runtime/Definitions/BoundarySystem/MixedRealityBoundaryProfile.cs index e9aafe60c..22314a91a 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Runtime/Definitions/BoundarySystem/MixedRealityBoundaryVisualizationProfile.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Runtime/Definitions/BoundarySystem/MixedRealityBoundaryProfile.cs @@ -9,10 +9,10 @@ namespace XRTK.Definitions.BoundarySystem { /// - /// Configuration profile settings for setting up boundary visualizations. + /// Configuration profile settings for setting up the . /// - [CreateAssetMenu(menuName = "Mixed Reality Toolkit/Boundary Visualization Profile", fileName = "MixedRealityBoundaryVisualizationProfile", order = (int)CreateProfileMenuItemIndices.BoundaryVisualization)] - public class MixedRealityBoundaryVisualizationProfile : BaseMixedRealityServiceProfile + [CreateAssetMenu(menuName = "Mixed Reality Toolkit/Boundary Profile", fileName = "MixedRealityBoundaryProfile", order = (int)CreateProfileMenuItemIndices.Boundary)] + public class MixedRealityBoundaryProfile : BaseMixedRealityServiceProfile { #region General Settings diff --git a/XRTK-Core/Packages/com.xrtk.core/Runtime/Definitions/BoundarySystem/MixedRealityBoundaryVisualizationProfile.cs.meta b/XRTK-Core/Packages/com.xrtk.core/Runtime/Definitions/BoundarySystem/MixedRealityBoundaryProfile.cs.meta similarity index 100% rename from XRTK-Core/Packages/com.xrtk.core/Runtime/Definitions/BoundarySystem/MixedRealityBoundaryVisualizationProfile.cs.meta rename to XRTK-Core/Packages/com.xrtk.core/Runtime/Definitions/BoundarySystem/MixedRealityBoundaryProfile.cs.meta diff --git a/XRTK-Core/Packages/com.xrtk.core/Runtime/Definitions/MixedRealityToolkitRootProfile.cs b/XRTK-Core/Packages/com.xrtk.core/Runtime/Definitions/MixedRealityToolkitRootProfile.cs index 6a88a0381..036db0ee9 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Runtime/Definitions/MixedRealityToolkitRootProfile.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Runtime/Definitions/MixedRealityToolkitRootProfile.cs @@ -128,7 +128,7 @@ public SystemType InputSystemType /// public bool IsBoundarySystemEnabled { - get => boundarySystemType != null && boundarySystemType.Type != null && enableBoundarySystem && boundaryVisualizationProfile != null; + get => boundarySystemType != null && boundarySystemType.Type != null && enableBoundarySystem && BoundarySystemProfile != null; internal set => enableBoundarySystem = value; } @@ -147,15 +147,16 @@ public SystemType BoundarySystemSystemType [SerializeField] [Tooltip("Profile for wiring up boundary visualization assets.")] - private MixedRealityBoundaryVisualizationProfile boundaryVisualizationProfile; + [FormerlySerializedAs("boundaryVisualizationProfile")] + private MixedRealityBoundaryProfile boundarySystemProfile; /// /// Active profile for controller mapping configuration /// - public MixedRealityBoundaryVisualizationProfile BoundaryVisualizationProfile + public MixedRealityBoundaryProfile BoundarySystemProfile { - get => boundaryVisualizationProfile; - internal set => boundaryVisualizationProfile = value; + get => boundarySystemProfile; + internal set => boundarySystemProfile = value; } #endregion Boundary System Properties diff --git a/XRTK-Core/Packages/com.xrtk.core/Runtime/Definitions/Utilities/ProfileMenuItemIndices.cs b/XRTK-Core/Packages/com.xrtk.core/Runtime/Definitions/Utilities/ProfileMenuItemIndices.cs index a3f930be6..ea0378ffc 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Runtime/Definitions/Utilities/ProfileMenuItemIndices.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Runtime/Definitions/Utilities/ProfileMenuItemIndices.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) XRTK. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. namespace XRTK.Definitions.Utilities @@ -18,7 +18,7 @@ public enum CreateProfileMenuItemIndices InputDataProviders, InputProcessors, ControllerVisualization, - BoundaryVisualization, + Boundary, SpatialAwareness, SpatialAwarenessDataProviders, Networking, diff --git a/XRTK-Core/Packages/com.xrtk.core/Runtime/Interfaces/BoundarySystem/IMixedRealityBoundarySystem.cs b/XRTK-Core/Packages/com.xrtk.core/Runtime/Interfaces/BoundarySystem/IMixedRealityBoundarySystem.cs index a16a3d754..033ee883c 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Runtime/Interfaces/BoundarySystem/IMixedRealityBoundarySystem.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Runtime/Interfaces/BoundarySystem/IMixedRealityBoundarySystem.cs @@ -87,6 +87,15 @@ public interface IMixedRealityBoundarySystem : IMixedRealitySystem /// Edge[] BoundaryBounds { get; } + /// + /// Sets up the boundary using the specified. + /// + /// + /// + /// This method should usually be called from the method of the data provider itself. + /// + void SetupBoundary(IMixedRealityBoundaryDataProvider dataProvider); + /// /// Determines if a is within the area of the boundary space. /// diff --git a/XRTK-Core/Packages/com.xrtk.core/Runtime/Services/BoundarySystem/MixedRealityBoundarySystem.cs b/XRTK-Core/Packages/com.xrtk.core/Runtime/Services/BoundarySystem/MixedRealityBoundarySystem.cs index 4680c6b90..64a06c696 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Runtime/Services/BoundarySystem/MixedRealityBoundarySystem.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Runtime/Services/BoundarySystem/MixedRealityBoundarySystem.cs @@ -23,7 +23,7 @@ public class MixedRealityBoundarySystem : BaseSystem, IMixedRealityBoundarySyste /// Constructor. /// /// - public MixedRealityBoundarySystem(MixedRealityBoundaryVisualizationProfile profile) + public MixedRealityBoundarySystem(MixedRealityBoundaryProfile profile) : base(profile) { showBoundary = profile.ShowBoundary; @@ -278,50 +278,12 @@ private GameObject CeilingVisualization #region IMixedRealityService Implementation - /// - public override void Enable() - { - base.Enable(); - - BoundaryDataProvider = MixedRealityToolkit.GetService(); - - if (!Application.isPlaying || BoundaryDataProvider == null) { return; } - - // Reset the bounds - BoundaryBounds = new Edge[0]; - rectangularBounds = null; - - // Get the boundary geometry. - var boundaryGeometry = new List(0); - var boundaryEdges = new List(0); - - if (BoundaryDataProvider.TryGetBoundaryGeometry(ref boundaryGeometry) && boundaryGeometry.Count > 0) - { - for (int i = 0; i < boundaryGeometry.Count; i++) - { - var pointA = boundaryGeometry[i]; - var pointB = boundaryGeometry[(i + 1) % boundaryGeometry.Count]; - boundaryEdges.Add(new Edge(pointA, pointB)); - } - - BoundaryBounds = boundaryEdges.ToArray(); - // We always use the same seed so that from run to run, the inscribed bounds are consistent. - rectangularBounds = new InscribedRectangle(BoundaryBounds, Mathf.Abs("Mixed Reality Toolkit".GetHashCode())); - } - else - { - Debug.LogWarning("No Boundary Geometry found"); - } - - BoundarySystemVisualizationRoot.SetActive(true); - } - /// public override void Update() { base.Update(); - if (!Application.isPlaying || BoundaryDataProvider == null) { return; } + if (!Application.isPlaying || boundaryDataProvider == null) { return; } foreach (var trackedObjectStatus in trackedObjects) { @@ -401,7 +363,7 @@ public override void Disable() { base.Disable(); - if (!Application.isPlaying || BoundaryDataProvider == null) { return; } + if (!Application.isPlaying) { return; } if (!boundaryVisualizationRoot.IsNull()) { @@ -414,7 +376,7 @@ public override void Destroy() { base.Destroy(); - if (!Application.isPlaying || BoundaryDataProvider == null) { return; } + if (!Application.isPlaying) { return; } // Destroys the parent and all the child objects boundaryVisualizationRoot.Destroy(); @@ -430,26 +392,30 @@ public override void Destroy() /// public IReadOnlyList TrackedObjects => trackedObjects.Keys.Select(cache => cache.gameObject).ToList(); + private IMixedRealityBoundaryDataProvider boundaryDataProvider = null; + /// - public IMixedRealityBoundaryDataProvider BoundaryDataProvider { get; private set; } + public IMixedRealityBoundaryDataProvider BoundaryDataProvider + { + get => boundaryDataProvider ?? (boundaryDataProvider = MixedRealityToolkit.GetService()); + private set => boundaryDataProvider = value; + } /// public bool IsVisible { - get => BoundaryDataProvider != null && BoundaryDataProvider.IsPlatformBoundaryVisible || - BoundarySystemVisualizationRoot.activeInHierarchy && + get => (BoundaryDataProvider != null && BoundaryDataProvider.IsPlatformBoundaryVisible) || + !BoundarySystemVisualizationRoot.IsNull() && BoundarySystemVisualizationRoot.activeInHierarchy && (ShowBoundary || ShowFloor || ShowWalls || ShowCeiling); set { - if (BoundaryDataProvider != null) + if (!BoundarySystemVisualizationRoot.IsNull()) { - BoundaryDataProvider.IsPlatformBoundaryVisible = value; + BoundarySystemVisualizationRoot.SetActive(value); } - - BoundarySystemVisualizationRoot.SetActive(value); } } @@ -540,6 +506,53 @@ public bool ShowCeiling /// public Edge[] BoundaryBounds { get; private set; } = new Edge[0]; + /// + public void SetupBoundary(IMixedRealityBoundaryDataProvider dataProvider) + { + BoundaryDataProvider = dataProvider; + + if (!BoundaryDataProvider.IsPlatformConfigured) { return; } + + // Reset the bounds + BoundaryBounds = new Edge[0]; + rectangularBounds = null; + + // Get the boundary geometry. + var boundaryGeometry = new List(0); + var boundaryEdges = new List(0); + + if (BoundaryDataProvider.TryGetBoundaryGeometry(ref boundaryGeometry) && boundaryGeometry.Count > 0) + { + for (int i = 0; i < boundaryGeometry.Count; i++) + { + var pointA = boundaryGeometry[i]; + var pointB = boundaryGeometry[(i + 1) % boundaryGeometry.Count]; + boundaryEdges.Add(new Edge(pointA, pointB)); + } + + BoundaryBounds = boundaryEdges.ToArray(); + // We always use the same seed so that from run to run, the inscribed bounds are consistent. + rectangularBounds = new InscribedRectangle(BoundaryBounds, Mathf.Abs("Mixed Reality Toolkit".GetHashCode())); + } + else + { + Debug.LogWarning("No Boundary Geometry found"); + } + + // Clear the prev visualization objects. + if (!BoundarySystemVisualizationRoot.IsNull()) + { + boundaryVisualizationRoot.Destroy(); + } + + // Initialize the visualization objects. + ShowBoundary = showBoundary; + ShowCeiling = showCeiling; + ShowFloor = showFloor; + ShowWalls = showWalls; + IsVisible = ShowBoundary || ShowCeiling || ShowFloor || ShowWalls; + } + /// public bool IsInsideBoundary(Vector3 position, Space referenceSpace = Space.World) { diff --git a/XRTK-Core/Packages/com.xrtk.core/Runtime/Services/MixedRealityToolkit.cs b/XRTK-Core/Packages/com.xrtk.core/Runtime/Services/MixedRealityToolkit.cs index 958eba127..6e74f1c67 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Runtime/Services/MixedRealityToolkit.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Runtime/Services/MixedRealityToolkit.cs @@ -453,9 +453,9 @@ private void InitializeServiceLocator() if (ActiveProfile.IsBoundarySystemEnabled) { - if (TryCreateAndRegisterService(ActiveProfile.BoundarySystemSystemType, out var service, ActiveProfile.BoundaryVisualizationProfile) && BoundarySystem != null) + if (TryCreateAndRegisterService(ActiveProfile.BoundarySystemSystemType, out var service, ActiveProfile.BoundarySystemProfile) && BoundarySystem != null) { - TryRegisterDataProviderConfigurations(ActiveProfile.BoundaryVisualizationProfile.RegisteredServiceConfigurations, service); + TryRegisterDataProviderConfigurations(ActiveProfile.BoundarySystemProfile.RegisteredServiceConfigurations, service); } else {