Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Fix/boundary system (#705)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
StephenHodgson authored Nov 29, 2020
1 parent 8f4e3e5 commit 84d0e5d
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace XRTK.Editor.Profiles
{
[CustomEditor(typeof(MixedRealityBoundaryVisualizationProfile))]
[CustomEditor(typeof(MixedRealityBoundaryProfile))]
public class MixedRealityBoundaryVisualizationProfileInspector : MixedRealityServiceProfileInspector
{
private SerializedProperty showBoundary;
Expand Down
8 changes: 4 additions & 4 deletions Editor/Profiles/MixedRealityToolkitRootProfileInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
namespace XRTK.Definitions.BoundarySystem
{
/// <summary>
/// Configuration profile settings for setting up boundary visualizations.
/// Configuration profile settings for setting up the <see cref="IMixedRealityBoundarySystem"/>.
/// </summary>
[CreateAssetMenu(menuName = "Mixed Reality Toolkit/Boundary Visualization Profile", fileName = "MixedRealityBoundaryVisualizationProfile", order = (int)CreateProfileMenuItemIndices.BoundaryVisualization)]
public class MixedRealityBoundaryVisualizationProfile : BaseMixedRealityServiceProfile<IMixedRealityBoundaryDataProvider>
[CreateAssetMenu(menuName = "Mixed Reality Toolkit/Boundary Profile", fileName = "MixedRealityBoundaryProfile", order = (int)CreateProfileMenuItemIndices.Boundary)]
public class MixedRealityBoundaryProfile : BaseMixedRealityServiceProfile<IMixedRealityBoundaryDataProvider>
{
#region General Settings

Expand Down
11 changes: 6 additions & 5 deletions Runtime/Definitions/MixedRealityToolkitRootProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public SystemType InputSystemType
/// </summary>
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;
}

Expand All @@ -147,15 +147,16 @@ public SystemType BoundarySystemSystemType

[SerializeField]
[Tooltip("Profile for wiring up boundary visualization assets.")]
private MixedRealityBoundaryVisualizationProfile boundaryVisualizationProfile;
[FormerlySerializedAs("boundaryVisualizationProfile")]
private MixedRealityBoundaryProfile boundarySystemProfile;

/// <summary>
/// Active profile for controller mapping configuration
/// </summary>
public MixedRealityBoundaryVisualizationProfile BoundaryVisualizationProfile
public MixedRealityBoundaryProfile BoundarySystemProfile
{
get => boundaryVisualizationProfile;
internal set => boundaryVisualizationProfile = value;
get => boundarySystemProfile;
internal set => boundarySystemProfile = value;
}

#endregion Boundary System Properties
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Definitions/Utilities/ProfileMenuItemIndices.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,7 +18,7 @@ public enum CreateProfileMenuItemIndices
InputDataProviders,
InputProcessors,
ControllerVisualization,
BoundaryVisualization,
Boundary,
SpatialAwareness,
SpatialAwarenessDataProviders,
Networking,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ public interface IMixedRealityBoundarySystem : IMixedRealitySystem
/// </remarks>
Edge[] BoundaryBounds { get; }

/// <summary>
/// Sets up the boundary using the <see cref="IMixedRealityBoundaryDataProvider"/> specified.
/// </summary>
/// <param name="dataProvider"></param>
/// <remarks>
/// This method should usually be called from the <see cref="IMixedRealityService.Enable"/> method of the data provider itself.
/// </remarks>
void SetupBoundary(IMixedRealityBoundaryDataProvider dataProvider);

/// <summary>
/// Determines if a <see cref="position"/> is within the area of the boundary space.
/// </summary>
Expand Down
111 changes: 62 additions & 49 deletions Runtime/Services/BoundarySystem/MixedRealityBoundarySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class MixedRealityBoundarySystem : BaseSystem, IMixedRealityBoundarySyste
/// Constructor.
/// </summary>
/// <param name="profile"></param>
public MixedRealityBoundarySystem(MixedRealityBoundaryVisualizationProfile profile)
public MixedRealityBoundarySystem(MixedRealityBoundaryProfile profile)
: base(profile)
{
showBoundary = profile.ShowBoundary;
Expand Down Expand Up @@ -278,50 +278,12 @@ private GameObject CeilingVisualization

#region IMixedRealityService Implementation

/// <inheritdoc/>
public override void Enable()
{
base.Enable();

BoundaryDataProvider = MixedRealityToolkit.GetService<IMixedRealityBoundaryDataProvider>();

if (!Application.isPlaying || BoundaryDataProvider == null) { return; }

// Reset the bounds
BoundaryBounds = new Edge[0];
rectangularBounds = null;

// Get the boundary geometry.
var boundaryGeometry = new List<Vector3>(0);
var boundaryEdges = new List<Edge>(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);
}

/// <inheritdoc/>
public override void Update()
{
base.Update();

if (!Application.isPlaying || BoundaryDataProvider == null) { return; }
if (!Application.isPlaying || boundaryDataProvider == null) { return; }

foreach (var trackedObjectStatus in trackedObjects)
{
Expand Down Expand Up @@ -401,7 +363,7 @@ public override void Disable()
{
base.Disable();

if (!Application.isPlaying || BoundaryDataProvider == null) { return; }
if (!Application.isPlaying) { return; }

if (!boundaryVisualizationRoot.IsNull())
{
Expand All @@ -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();
Expand All @@ -430,26 +392,30 @@ public override void Destroy()
/// <inheritdoc />
public IReadOnlyList<GameObject> TrackedObjects => trackedObjects.Keys.Select(cache => cache.gameObject).ToList();

private IMixedRealityBoundaryDataProvider boundaryDataProvider = null;

/// <inheritdoc />
public IMixedRealityBoundaryDataProvider BoundaryDataProvider { get; private set; }
public IMixedRealityBoundaryDataProvider BoundaryDataProvider
{
get => boundaryDataProvider ?? (boundaryDataProvider = MixedRealityToolkit.GetService<IMixedRealityBoundaryDataProvider>());
private set => boundaryDataProvider = value;
}

/// <inheritdoc />
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);
}
}

Expand Down Expand Up @@ -540,6 +506,53 @@ public bool ShowCeiling
/// <inheritdoc />
public Edge[] BoundaryBounds { get; private set; } = new Edge[0];

/// <inheritdoc />
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<Vector3>(0);
var boundaryEdges = new List<Edge>(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;
}

/// <inheritdoc />
public bool IsInsideBoundary(Vector3 position, Space referenceSpace = Space.World)
{
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Services/MixedRealityToolkit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,9 @@ private void InitializeServiceLocator()

if (ActiveProfile.IsBoundarySystemEnabled)
{
if (TryCreateAndRegisterService<IMixedRealityBoundarySystem>(ActiveProfile.BoundarySystemSystemType, out var service, ActiveProfile.BoundaryVisualizationProfile) && BoundarySystem != null)
if (TryCreateAndRegisterService<IMixedRealityBoundarySystem>(ActiveProfile.BoundarySystemSystemType, out var service, ActiveProfile.BoundarySystemProfile) && BoundarySystem != null)
{
TryRegisterDataProviderConfigurations(ActiveProfile.BoundaryVisualizationProfile.RegisteredServiceConfigurations, service);
TryRegisterDataProviderConfigurations(ActiveProfile.BoundarySystemProfile.RegisteredServiceConfigurations, service);
}
else
{
Expand Down

0 comments on commit 84d0e5d

Please sign in to comment.