Skip to content

Commit a87517b

Browse files
authored
Merge pull request #2402 from davidkline-ms/vNext-Boundary
vNext: Implement MixedRealityBoundaryManager and Profile
2 parents e887b0a + 405b271 commit a87517b

File tree

8 files changed

+339
-26
lines changed

8 files changed

+339
-26
lines changed

Assets/MixedRealityToolkit-SDK/Profiles/DefaultMixedRealityConfigurationProfile.asset

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ MonoBehaviour:
1111
m_Script: {fileID: 11500000, guid: 41718b8e5d86c37409b7ce6847fa00a3, type: 3}
1212
m_Name: DefaultMixedRealityConfigurationProfile
1313
m_EditorClassIdentifier:
14+
targetExperienceScale: 3
1415
enableCameraProfile: 1
1516
cameraProfile: {fileID: 11400000, guid: b9a895b32a50a7f45b1e4da728d50741, type: 2}
1617
enableInputSystem: 1
@@ -25,3 +26,8 @@ MonoBehaviour:
2526
enableControllerProfiles: 1
2627
controllersProfile: {fileID: 11400000, guid: 4319257468937c74ebb69e41792d60c5, type: 2}
2728
enableBoundarySystem: 1
29+
boundarySystemType:
30+
reference: Microsoft.MixedReality.Toolkit.Internal.Managers.MixedRealityBoundaryManager,
31+
Microsoft.MixedReality.Toolkit
32+
boundaryHeight: 3
33+
enablePlatformBoundaryRendering: 1

Assets/MixedRealityToolkit/_Core/Boundary/MixedRealityBoundarySystem.cs

Lines changed: 105 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using Microsoft.MixedReality.Toolkit.Internal.Definitions;
5+
using Microsoft.MixedReality.Toolkit.Internal.Definitions.Utilities;
56
using Microsoft.MixedReality.Toolkit.Internal.Interfaces;
7+
using System;
8+
using System.Collections.Generic;
9+
using UnityEngine;
10+
using UnityEngine.Experimental.XR;
11+
using UnityEngine.XR;
612

713
namespace Microsoft.MixedReality.Toolkit.Internal.Managers
814
{
@@ -11,45 +17,130 @@ namespace Microsoft.MixedReality.Toolkit.Internal.Managers
1117
/// </summary>
1218
public class MixedRealityBoundaryManager : BaseManager, IMixedRealityBoundarySystem
1319
{
20+
/// <inheritdoc/>
21+
public ExperienceScale Scale { get; set; } = ExperienceScale.Room;
22+
23+
/// <inheritdoc/>
24+
public float BoundaryHeight { get; set; } = 3.0f;
25+
26+
/// <inheritdoc/>
27+
public bool EnablePlatformBoundaryRendering { get; set; } = true;
28+
29+
/// <inheritdoc/>
30+
public Bounds OutscribedVolume { get; private set; } = new Bounds();
31+
32+
/// <inheritdoc/>
33+
public Bounds InscribedVolume { get; private set; } = new Bounds();
34+
1435
/// <summary>
1536
/// MixedRealityBoundaryManager constructor
1637
/// </summary>
1738
public MixedRealityBoundaryManager()
1839
{
19-
// TODO define any constructor requirements
40+
Scale = MixedRealityManager.Instance.ActiveProfile.TargetExperienceScale;
41+
BoundaryHeight = MixedRealityManager.Instance.ActiveProfile.BoundaryHeight;
42+
EnablePlatformBoundaryRendering = MixedRealityManager.Instance.ActiveProfile.EnablePlatformBoundaryRendering;
2043
}
2144

22-
/// <summary>
23-
/// The initialize function is used to setup the manager once created.
24-
/// This method is called once all managers have been registered in the Mixed Reality Manager.
25-
/// </summary>
45+
/// <inheritdoc/>
2646
public override void Initialize()
2747
{
28-
// TODO Initialize stuff
48+
base.Initialize();
49+
InitializeInternal();
2950
}
3051

3152
/// <summary>
32-
/// Optional ProfileUpdate function to allow reconfiguration when the active configuration profile of the Mixed Reality Manager is replaced
53+
/// Performs initialization tasks for the BoundaryManager.
3354
/// </summary>
55+
private void InitializeInternal()
56+
{
57+
SetTrackingSpace();
58+
CalculateBoundaryBounds();
59+
SetPlatformBoundaryVisibility();
60+
}
61+
62+
/// <inheritdoc/>
3463
public override void Reset()
3564
{
36-
// TODO React to profile change
65+
base.Reset();
66+
InitializeInternal();
3767
}
3868

3969
/// <summary>
40-
/// Optional Update function to perform per-frame updates of the manager
70+
/// Retrieves the boundary geometry and creates the boundary and inscribed playspace volumes.
4171
/// </summary>
42-
public override void Update()
72+
private void CalculateBoundaryBounds()
4373
{
44-
// TODO Update stuff
74+
if (XRDevice.GetTrackingSpaceType() != TrackingSpaceType.RoomScale)
75+
{
76+
// Boundaries are supported for Room Scale experiences only.
77+
return;
78+
}
79+
80+
OutscribedVolume = new Bounds();
81+
82+
// Get the boundary geometry.
83+
List<Vector3> boundaryGeometry = new List<Vector3>(0);
84+
if (Boundary.TryGetGeometry(boundaryGeometry))
85+
{
86+
for (int i = 0; i < boundaryGeometry.Count; i++)
87+
{
88+
OutscribedVolume.Encapsulate(boundaryGeometry[i]);
89+
}
90+
91+
// todo: CreateInscribedBounds()
92+
93+
// Set the "ceiling" of the space using the configured height.
94+
OutscribedVolume.Encapsulate(new Vector3(0f, BoundaryHeight, 0f));
95+
}
96+
}
97+
98+
/// <summary>
99+
/// Updates the <see cref="TrackingSpaceType"/> on the XR device.
100+
/// </summary>
101+
private void SetTrackingSpace()
102+
{
103+
TrackingSpaceType trackingSpace;
104+
105+
// In current versions of Unity, there are two types of tracking spaces. For boundaries, if the scale
106+
// is not Room or Standing, it currently maps to TrackingSpaceType.Stationary.
107+
switch (Scale)
108+
{
109+
case ExperienceScale.Standing:
110+
case ExperienceScale.Room:
111+
trackingSpace = TrackingSpaceType.RoomScale;
112+
break;
113+
114+
case ExperienceScale.OrientationOnly:
115+
case ExperienceScale.Seated:
116+
case ExperienceScale.World:
117+
trackingSpace = TrackingSpaceType.Stationary;
118+
break;
119+
120+
default:
121+
trackingSpace = TrackingSpaceType.Stationary;
122+
Debug.LogWarning("Unknown / unsupported ExperienceScale. Defaulting to Stationary tracking space.");
123+
break;
124+
}
125+
126+
XRDevice.SetTrackingSpaceType(trackingSpace);
45127
}
46128

47129
/// <summary>
48-
/// Optional Destroy function to perform cleanup of the manager before the Mixed Reality Manager is destroyed
130+
/// Sets the property indicating if the boundary should be rendered by the platform.
49131
/// </summary>
50-
public override void Destroy()
132+
/// <remarks>
133+
/// Not all platforms support specifying whether or not to render the playspace boundary.
134+
/// For platforms without boundary rendering control, the default behavior will be unchanged
135+
/// regardless of the value provided.
136+
/// </remarks>
137+
private void SetPlatformBoundaryVisibility()
51138
{
52-
// TODO Destroy stuff
139+
if (Boundary.configured)
140+
{
141+
// This value cannot be configured on Windows Mixed Reality. Automatic boundary rendering is performed.
142+
Boundary.visible = EnablePlatformBoundaryRendering;
143+
}
53144
}
54145
}
55146
}

Assets/MixedRealityToolkit/_Core/Definitions/MixedRealityConfigurationProfile.cs

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ public class MixedRealityConfigurationProfile : ScriptableObject, ISerialization
4343

4444
#region Mixed Reality Manager configurable properties
4545

46+
[SerializeField]
47+
[Tooltip("The scale of the Mixed Reality experience.")]
48+
private ExperienceScale targetExperienceScale = ExperienceScale.Room;
49+
50+
/// <summary>
51+
/// The desired the scale of the experience.
52+
/// </summary>
53+
public ExperienceScale TargetExperienceScale
54+
{
55+
get { return targetExperienceScale; }
56+
set { targetExperienceScale = value; }
57+
}
58+
4659
[SerializeField]
4760
[Tooltip("Enable the Camera Profile on Startup")]
4861
private bool enableCameraProfile = false;
@@ -84,9 +97,7 @@ public bool EnableInputSystem
8497
{
8598
get
8699
{
87-
return inputSystemType != null &&
88-
inputSystemType?.Type != null &&
89-
inputActionsProfile != null &&
100+
return inputActionsProfile != null &&
90101
enableInputSystem;
91102
}
92103
private set { enableInputSystem = value; }
@@ -176,12 +187,62 @@ public MixedRealityControllerMappingProfile ControllersProfile
176187
private bool enableBoundarySystem = false;
177188

178189
/// <summary>
179-
/// Enable and configure the Boundary component on the Mixed Reality Camera
190+
/// Enable and configure the boundary system.
180191
/// </summary>
181192
public bool EnableBoundarySystem
182193
{
183-
get { return enableBoundarySystem; }
184-
private set { enableBoundarySystem = value; }
194+
get
195+
{
196+
return boundarySystemType?.Type != null &&
197+
enableBoundarySystem;
198+
}
199+
private set { enableInputSystem = value; }
200+
}
201+
202+
[SerializeField]
203+
[Tooltip("Boundary System Class to instantiate at runtime.")]
204+
[Implements(typeof(IMixedRealityBoundarySystem), TypeGrouping.ByNamespaceFlat)]
205+
private SystemType boundarySystemType;
206+
207+
/// <summary>
208+
/// Boundary System Script File to instantiate at runtime.
209+
/// </summary>
210+
public SystemType BoundarySystemSystemType
211+
{
212+
get { return boundarySystemType; }
213+
private set { boundarySystemType = value; }
214+
}
215+
216+
[SerializeField]
217+
[Tooltip("The approximate height of the playspace, in meters.")]
218+
private float boundaryHeight = 3.0f;
219+
220+
/// <summary>
221+
/// The approximate height of the playspace, in meters.
222+
/// </summary>
223+
/// <remarks>
224+
/// The BoundaryHeight property is used to create a three dimensional volume for the playspace.
225+
/// </remarks>
226+
public float BoundaryHeight
227+
{
228+
get { return boundaryHeight; }
229+
set { boundaryHeight = value; }
230+
}
231+
232+
[SerializeField]
233+
[Tooltip("Instruct the platform whether or not to render the playspace boundary. Note: not all platforms support configuring this option.")]
234+
private bool enablePlatformBoundaryRendering = true;
235+
236+
/// <summary>
237+
/// Instruct the platform whether or not to render the playspace boundary.
238+
/// </summary>
239+
/// <remarks>
240+
/// Not all platforms support the EnablePlatformBoundaryRendering property.
241+
/// </remarks>
242+
public bool EnablePlatformBoundaryRendering
243+
{
244+
get { return enablePlatformBoundaryRendering; }
245+
set { enablePlatformBoundaryRendering = value; }
185246
}
186247

187248
#endregion Mixed Reality Manager configurable properties
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
namespace Microsoft.MixedReality.Toolkit.Internal.Definitions.Utilities
5+
{
6+
/// <summary>
7+
/// The ExperienceScale identifies the environment for which the experience is designed.
8+
/// </summary>
9+
[System.Serializable]
10+
public enum ExperienceScale
11+
{
12+
/// <summary>
13+
/// An experience which utilizes only the headset orientantion and is gravity aligned. The coordinate system origin is at head level.
14+
/// </summary>
15+
OrientationOnly = 0,
16+
/// <summary>
17+
/// An experience designed for seated use. The coordinate system origin is at head level.
18+
/// </summary>
19+
Seated,
20+
/// <summary>
21+
/// An experience designed for stationary standing use. The coordinate system origin is at floor level.
22+
/// </summary>
23+
Standing,
24+
/// <summary>
25+
/// An experience designed to support movement thoughtout a room. The coordinate system origin is at floor level.
26+
/// </summary>
27+
Room,
28+
/// <summary>
29+
/// An experience designed to utilize and move through the physical world. The coordinate system origin is at head level.
30+
/// </summary>
31+
World
32+
}
33+
}

Assets/MixedRealityToolkit/_Core/Definitions/Utilities/ExperienceScale.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)