44using Microsoft . MixedReality . Toolkit . Core . Definitions . BoundarySystem ;
55using Microsoft . MixedReality . Toolkit . Core . Definitions . Utilities ;
66using Microsoft . MixedReality . Toolkit . Core . EventDatum . Boundary ;
7+ using Microsoft . MixedReality . Toolkit . Core . Interfaces ;
78using Microsoft . MixedReality . Toolkit . Core . Interfaces . BoundarySystem ;
89using Microsoft . MixedReality . Toolkit . Core . Services ;
910using Microsoft . MixedReality . Toolkit . Core . Utilities ;
@@ -19,8 +20,23 @@ namespace Microsoft.MixedReality.Toolkit.Services.BoundarySystem
1920 /// <summary>
2021 /// The Boundary system controls the presentation and display of the users boundary in a scene.
2122 /// </summary>
22- public class MixedRealityBoundarySystem : BaseEventSystem , IMixedRealityBoundarySystem
23+ public class MixedRealityBoundarySystem : BaseCoreSystem , IMixedRealityBoundarySystem
2324 {
25+ public MixedRealityBoundarySystem (
26+ IMixedRealityServiceRegistrar registrar ,
27+ MixedRealityBoundaryVisualizationProfile profile ,
28+ Transform playspace ,
29+ ExperienceScale scale ) : base ( registrar , profile )
30+ {
31+ Scale = scale ;
32+
33+ if ( playspace == null )
34+ {
35+ Debug . LogError ( "The MixedRealityBoundarySystem object requires a valid playspace Transform." ) ;
36+ }
37+ Playspace = playspace ;
38+ }
39+
2440 #region IMixedRealityService Implementation
2541
2642 private BoundaryEventData boundaryEventData = null ;
@@ -30,25 +46,27 @@ public override void Initialize()
3046 {
3147 if ( ! Application . isPlaying ) { return ; }
3248
49+ MixedRealityBoundaryVisualizationProfile profile = ConfigurationProfile as MixedRealityBoundaryVisualizationProfile ;
50+ if ( profile == null ) { return ; }
51+
3352 boundaryEventData = new BoundaryEventData ( EventSystem . current ) ;
3453
35- Scale = MixedRealityToolkit . Instance . ActiveProfile . TargetExperienceScale ;
36- BoundaryHeight = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . BoundaryHeight ;
54+ BoundaryHeight = profile . BoundaryHeight ;
3755
3856 SetTrackingSpace ( ) ;
3957 CalculateBoundaryBounds ( ) ;
4058 Boundary . visible = true ;
4159
42- ShowFloor = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . ShowFloor ;
43- FloorPhysicsLayer = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . FloorPhysicsLayer ;
44- ShowPlayArea = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . ShowPlayArea ;
45- PlayAreaPhysicsLayer = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . PlayAreaPhysicsLayer ;
46- ShowTrackedArea = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . ShowTrackedArea ;
47- TrackedAreaPhysicsLayer = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . TrackedAreaPhysicsLayer ;
48- ShowBoundaryWalls = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . ShowBoundaryWalls ;
49- BoundaryWallsPhysicsLayer = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . BoundaryWallsPhysicsLayer ;
50- ShowBoundaryCeiling = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . ShowBoundaryCeiling ;
51- CeilingPhysicsLayer = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . CeilingPhysicsLayer ;
60+ ShowFloor = profile . ShowFloor ;
61+ FloorPhysicsLayer = profile . FloorPhysicsLayer ;
62+ ShowPlayArea = profile . ShowPlayArea ;
63+ PlayAreaPhysicsLayer = profile . PlayAreaPhysicsLayer ;
64+ ShowTrackedArea = profile . ShowTrackedArea ;
65+ TrackedAreaPhysicsLayer = profile . TrackedAreaPhysicsLayer ;
66+ ShowBoundaryWalls = profile . ShowBoundaryWalls ;
67+ BoundaryWallsPhysicsLayer = profile . BoundaryWallsPhysicsLayer ;
68+ ShowBoundaryCeiling = profile . ShowBoundaryCeiling ;
69+ CeilingPhysicsLayer = profile . CeilingPhysicsLayer ;
5270
5371 if ( ShowFloor )
5472 {
@@ -245,6 +263,13 @@ public int GetHashCode(object obj)
245263
246264 #region IMixedRealityBoundarySystem Implementation
247265
266+ /// <summary>
267+ /// The transform of the playspace scene object. We use this transform to parent
268+ /// boundary visualizations that teleport with the user and to perform calculations
269+ /// to ensure proper alignment with the world.
270+ /// </summary>
271+ private Transform Playspace = null ;
272+
248273 /// <summary>
249274 /// The thickness of three dimensional generated boundary objects.
250275 /// </summary>
@@ -273,7 +298,7 @@ private GameObject BoundaryVisualizationParent
273298 }
274299
275300 var visualizationParent = new GameObject ( "Boundary System Visualizations" ) ;
276- visualizationParent . transform . parent = MixedRealityToolkit . Instance . MixedRealityPlayspace ;
301+ visualizationParent . transform . parent = Playspace ;
277302 return boundaryVisualizationParent = visualizationParent ;
278303 }
279304 }
@@ -570,7 +595,7 @@ public bool Contains(Vector3 location, Boundary.Type boundaryType = Boundary.Typ
570595 }
571596
572597 // Handle the user teleporting (boundary moves with them).
573- location = MixedRealityToolkit . Instance . MixedRealityPlayspace . InverseTransformPoint ( location ) ;
598+ location = Playspace . InverseTransformPoint ( location ) ;
574599
575600 if ( FloorHeight . Value > location . y ||
576601 BoundaryHeight < location . y )
@@ -613,7 +638,7 @@ public bool TryGetRectangularBoundsParams(out Vector2 center, out float angle, o
613638 }
614639
615640 // Handle the user teleporting (boundary moves with them).
616- Vector3 transformedCenter = MixedRealityToolkit . Instance . MixedRealityPlayspace . TransformPoint (
641+ Vector3 transformedCenter = Playspace . TransformPoint (
617642 new Vector3 ( rectangularBounds . Center . x , 0f , rectangularBounds . Center . y ) ) ;
618643
619644 center = new Vector2 ( transformedCenter . x , transformedCenter . z ) ;
@@ -633,24 +658,27 @@ public GameObject GetFloorVisualization()
633658 return currentFloorObject ;
634659 }
635660
661+ MixedRealityBoundaryVisualizationProfile profile = ConfigurationProfile as MixedRealityBoundaryVisualizationProfile ;
662+ if ( profile == null ) { return null ; }
663+
636664 if ( ! FloorHeight . HasValue )
637665 {
638666 // We were unable to locate the floor.
639667 return null ;
640668 }
641669
642- Vector2 floorScale = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . FloorScale ;
670+ Vector2 floorScale = profile . FloorScale ;
643671
644672 // Render the floor.
645673 currentFloorObject = GameObject . CreatePrimitive ( PrimitiveType . Cube ) ;
646674 currentFloorObject . name = "Boundary System Floor" ;
647675 currentFloorObject . transform . localScale = new Vector3 ( floorScale . x , boundaryObjectThickness , floorScale . y ) ;
648676 currentFloorObject . transform . Translate ( new Vector3 (
649- MixedRealityToolkit . Instance . MixedRealityPlayspace . position . x ,
677+ Playspace . position . x ,
650678 FloorHeight . Value - ( currentFloorObject . transform . localScale . y * 0.5f ) ,
651- MixedRealityToolkit . Instance . MixedRealityPlayspace . position . z ) ) ;
679+ Playspace . position . z ) ) ;
652680 currentFloorObject . layer = FloorPhysicsLayer ;
653- currentFloorObject . GetComponent < Renderer > ( ) . sharedMaterial = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . FloorMaterial ;
681+ currentFloorObject . GetComponent < Renderer > ( ) . sharedMaterial = profile . FloorMaterial ;
654682
655683 return currentFloorObject ;
656684 }
@@ -665,6 +693,9 @@ public GameObject GetPlayAreaVisualization()
665693 return currentPlayAreaObject ;
666694 }
667695
696+ MixedRealityBoundaryVisualizationProfile profile = ConfigurationProfile as MixedRealityBoundaryVisualizationProfile ;
697+ if ( profile == null ) { return null ; }
698+
668699 // Get the rectangular bounds.
669700 Vector2 center ;
670701 float angle ;
@@ -690,7 +721,7 @@ public GameObject GetPlayAreaVisualization()
690721 currentPlayAreaObject . transform . Translate ( new Vector3 ( center . x , boundaryObjectRenderOffset , center . y ) ) ;
691722 currentPlayAreaObject . transform . Rotate ( new Vector3 ( 90 , - angle , 0 ) ) ;
692723 currentPlayAreaObject . transform . localScale = new Vector3 ( width , height , 1.0f ) ;
693- currentPlayAreaObject . GetComponent < Renderer > ( ) . sharedMaterial = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . PlayAreaMaterial ;
724+ currentPlayAreaObject . GetComponent < Renderer > ( ) . sharedMaterial = profile . PlayAreaMaterial ;
694725
695726 currentPlayAreaObject . transform . parent = BoundaryVisualizationParent . transform ;
696727
@@ -707,6 +738,9 @@ public GameObject GetTrackedAreaVisualization()
707738 return currentTrackedAreaObject ;
708739 }
709740
741+ MixedRealityBoundaryVisualizationProfile profile = ConfigurationProfile as MixedRealityBoundaryVisualizationProfile ;
742+ if ( profile == null ) { return null ; }
743+
710744 if ( Bounds . Length == 0 )
711745 {
712746 // If we do not have boundary edges, we cannot render them.
@@ -727,15 +761,15 @@ public GameObject GetTrackedAreaVisualization()
727761 currentTrackedAreaObject . layer = ignoreRaycastLayerValue ;
728762 currentTrackedAreaObject . AddComponent < LineRenderer > ( ) ;
729763 currentTrackedAreaObject . transform . Translate ( new Vector3 (
730- MixedRealityToolkit . Instance . MixedRealityPlayspace . position . x ,
764+ Playspace . position . x ,
731765 boundaryObjectRenderOffset ,
732- MixedRealityToolkit . Instance . MixedRealityPlayspace . position . z ) ) ;
766+ Playspace . position . z ) ) ;
733767 currentPlayAreaObject . layer = TrackedAreaPhysicsLayer ;
734768
735769 // Configure the renderer properties.
736770 float lineWidth = 0.01f ;
737771 LineRenderer lineRenderer = currentTrackedAreaObject . GetComponent < LineRenderer > ( ) ;
738- lineRenderer . sharedMaterial = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . TrackedAreaMaterial ;
772+ lineRenderer . sharedMaterial = profile . TrackedAreaMaterial ;
739773 lineRenderer . useWorldSpace = false ;
740774 lineRenderer . startWidth = lineWidth ;
741775 lineRenderer . endWidth = lineWidth ;
@@ -757,6 +791,9 @@ public GameObject GetBoundaryWallVisualization()
757791 return currentBoundaryWallObject ;
758792 }
759793
794+ MixedRealityBoundaryVisualizationProfile profile = ConfigurationProfile as MixedRealityBoundaryVisualizationProfile ;
795+ if ( profile == null ) { return null ; }
796+
760797 if ( ! FloorHeight . HasValue )
761798 {
762799 // We need a floor on which to place the walls.
@@ -778,7 +815,7 @@ public GameObject GetBoundaryWallVisualization()
778815 {
779816 GameObject wall = GameObject . CreatePrimitive ( PrimitiveType . Cube ) ;
780817 wall . name = $ "Wall { i } ";
781- wall . GetComponent < Renderer > ( ) . sharedMaterial = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . BoundaryWallMaterial ;
818+ wall . GetComponent < Renderer > ( ) . sharedMaterial = profile . BoundaryWallMaterial ;
782819 wall . transform . localScale = new Vector3 ( ( Bounds [ i ] . PointB - Bounds [ i ] . PointA ) . magnitude , BoundaryHeight , wallDepth ) ;
783820 wall . layer = ignoreRaycastLayerValue ;
784821
@@ -806,6 +843,9 @@ public GameObject GetBoundaryCeilingVisualization()
806843 return currentCeilingObject ;
807844 }
808845
846+ MixedRealityBoundaryVisualizationProfile profile = ConfigurationProfile as MixedRealityBoundaryVisualizationProfile ;
847+ if ( profile == null ) { return null ; }
848+
809849 if ( Bounds . Length == 0 )
810850 {
811851 // If we do not have boundary edges, we cannot render a ceiling.
@@ -830,7 +870,7 @@ public GameObject GetBoundaryCeilingVisualization()
830870 boundaryBoundingBox . center . x ,
831871 BoundaryHeight + ( currentCeilingObject . transform . localScale . y * 0.5f ) ,
832872 boundaryBoundingBox . center . z ) ) ;
833- currentCeilingObject . GetComponent < Renderer > ( ) . sharedMaterial = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . BoundaryCeilingMaterial ;
873+ currentCeilingObject . GetComponent < Renderer > ( ) . sharedMaterial = profile . BoundaryCeilingMaterial ;
834874 currentCeilingObject . layer = CeilingPhysicsLayer ;
835875 currentCeilingObject . transform . parent = BoundaryVisualizationParent . transform ;
836876
0 commit comments