22// Licensed under the MIT License. See LICENSE in the project root for license information.
33
44using Microsoft . MixedReality . Toolkit . Internal . Definitions ;
5+ using Microsoft . MixedReality . Toolkit . Internal . Definitions . Utilities ;
56using 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
713namespace 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}
0 commit comments