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,18 @@ 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+ Playspace = playspace ;
33+ }
34+
2435 #region IMixedRealityService Implementation
2536
2637 private BoundaryEventData boundaryEventData = null ;
@@ -30,25 +41,27 @@ public override void Initialize()
3041 {
3142 if ( ! Application . isPlaying ) { return ; }
3243
44+ MixedRealityBoundaryVisualizationProfile profile = ConfigurationProfile as MixedRealityBoundaryVisualizationProfile ;
45+ if ( profile == null ) { return ; }
46+
3347 boundaryEventData = new BoundaryEventData ( EventSystem . current ) ;
3448
35- Scale = MixedRealityToolkit . Instance . ActiveProfile . TargetExperienceScale ;
36- BoundaryHeight = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . BoundaryHeight ;
49+ BoundaryHeight = profile . BoundaryHeight ;
3750
3851 SetTrackingSpace ( ) ;
3952 CalculateBoundaryBounds ( ) ;
4053 Boundary . visible = true ;
4154
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 ;
55+ ShowFloor = profile . ShowFloor ;
56+ FloorPhysicsLayer = profile . FloorPhysicsLayer ;
57+ ShowPlayArea = profile . ShowPlayArea ;
58+ PlayAreaPhysicsLayer = profile . PlayAreaPhysicsLayer ;
59+ ShowTrackedArea = profile . ShowTrackedArea ;
60+ TrackedAreaPhysicsLayer = profile . TrackedAreaPhysicsLayer ;
61+ ShowBoundaryWalls = profile . ShowBoundaryWalls ;
62+ BoundaryWallsPhysicsLayer = profile . BoundaryWallsPhysicsLayer ;
63+ ShowBoundaryCeiling = profile . ShowBoundaryCeiling ;
64+ CeilingPhysicsLayer = profile . CeilingPhysicsLayer ;
5265
5366 if ( ShowFloor )
5467 {
@@ -245,6 +258,13 @@ public int GetHashCode(object obj)
245258
246259 #region IMixedRealityBoundarySystem Implementation
247260
261+ /// <summary>
262+ /// The transform of the playspace scene object. We use this transform to parent
263+ /// boundary visualizations that teleport with the user and to perform calculations
264+ /// to ensure proper alignment with the world.
265+ /// </summary>
266+ private Transform Playspace = null ;
267+
248268 /// <summary>
249269 /// The thickness of three dimensional generated boundary objects.
250270 /// </summary>
@@ -273,7 +293,7 @@ private GameObject BoundaryVisualizationParent
273293 }
274294
275295 var visualizationParent = new GameObject ( "Boundary System Visualizations" ) ;
276- visualizationParent . transform . parent = MixedRealityToolkit . Instance . MixedRealityPlayspace ;
296+ visualizationParent . transform . parent = Playspace ;
277297 return boundaryVisualizationParent = visualizationParent ;
278298 }
279299 }
@@ -570,7 +590,8 @@ public bool Contains(Vector3 location, Boundary.Type boundaryType = Boundary.Typ
570590 }
571591
572592 // Handle the user teleporting (boundary moves with them).
573- location = MixedRealityToolkit . Instance . MixedRealityPlayspace . InverseTransformPoint ( location ) ;
593+ // todo: update...
594+ location = Playspace . InverseTransformPoint ( location ) ;
574595
575596 if ( FloorHeight . Value > location . y ||
576597 BoundaryHeight < location . y )
@@ -613,7 +634,8 @@ public bool TryGetRectangularBoundsParams(out Vector2 center, out float angle, o
613634 }
614635
615636 // Handle the user teleporting (boundary moves with them).
616- Vector3 transformedCenter = MixedRealityToolkit . Instance . MixedRealityPlayspace . TransformPoint (
637+ // todo: update...
638+ Vector3 transformedCenter = Playspace . TransformPoint (
617639 new Vector3 ( rectangularBounds . Center . x , 0f , rectangularBounds . Center . y ) ) ;
618640
619641 center = new Vector2 ( transformedCenter . x , transformedCenter . z ) ;
@@ -633,24 +655,28 @@ public GameObject GetFloorVisualization()
633655 return currentFloorObject ;
634656 }
635657
658+ MixedRealityBoundaryVisualizationProfile profile = ConfigurationProfile as MixedRealityBoundaryVisualizationProfile ;
659+ if ( profile == null ) { return null ; }
660+
636661 if ( ! FloorHeight . HasValue )
637662 {
638663 // We were unable to locate the floor.
639664 return null ;
640665 }
641666
642- Vector2 floorScale = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . FloorScale ;
667+ Vector2 floorScale = profile . FloorScale ;
643668
644669 // Render the floor.
645670 currentFloorObject = GameObject . CreatePrimitive ( PrimitiveType . Cube ) ;
646671 currentFloorObject . name = "Boundary System Floor" ;
647672 currentFloorObject . transform . localScale = new Vector3 ( floorScale . x , boundaryObjectThickness , floorScale . y ) ;
673+ // todo: update...
648674 currentFloorObject . transform . Translate ( new Vector3 (
649- MixedRealityToolkit . Instance . MixedRealityPlayspace . position . x ,
675+ Playspace . position . x ,
650676 FloorHeight . Value - ( currentFloorObject . transform . localScale . y * 0.5f ) ,
651- MixedRealityToolkit . Instance . MixedRealityPlayspace . position . z ) ) ;
677+ Playspace . position . z ) ) ;
652678 currentFloorObject . layer = FloorPhysicsLayer ;
653- currentFloorObject . GetComponent < Renderer > ( ) . sharedMaterial = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . FloorMaterial ;
679+ currentFloorObject . GetComponent < Renderer > ( ) . sharedMaterial = profile . FloorMaterial ;
654680
655681 return currentFloorObject ;
656682 }
@@ -665,6 +691,9 @@ public GameObject GetPlayAreaVisualization()
665691 return currentPlayAreaObject ;
666692 }
667693
694+ MixedRealityBoundaryVisualizationProfile profile = ConfigurationProfile as MixedRealityBoundaryVisualizationProfile ;
695+ if ( profile == null ) { return null ; }
696+
668697 // Get the rectangular bounds.
669698 Vector2 center ;
670699 float angle ;
@@ -690,7 +719,7 @@ public GameObject GetPlayAreaVisualization()
690719 currentPlayAreaObject . transform . Translate ( new Vector3 ( center . x , boundaryObjectRenderOffset , center . y ) ) ;
691720 currentPlayAreaObject . transform . Rotate ( new Vector3 ( 90 , - angle , 0 ) ) ;
692721 currentPlayAreaObject . transform . localScale = new Vector3 ( width , height , 1.0f ) ;
693- currentPlayAreaObject . GetComponent < Renderer > ( ) . sharedMaterial = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . PlayAreaMaterial ;
722+ currentPlayAreaObject . GetComponent < Renderer > ( ) . sharedMaterial = profile . PlayAreaMaterial ;
694723
695724 currentPlayAreaObject . transform . parent = BoundaryVisualizationParent . transform ;
696725
@@ -707,6 +736,9 @@ public GameObject GetTrackedAreaVisualization()
707736 return currentTrackedAreaObject ;
708737 }
709738
739+ MixedRealityBoundaryVisualizationProfile profile = ConfigurationProfile as MixedRealityBoundaryVisualizationProfile ;
740+ if ( profile == null ) { return null ; }
741+
710742 if ( Bounds . Length == 0 )
711743 {
712744 // If we do not have boundary edges, we cannot render them.
@@ -726,16 +758,17 @@ public GameObject GetTrackedAreaVisualization()
726758 currentTrackedAreaObject = new GameObject ( "Tracked Area" ) ;
727759 currentTrackedAreaObject . layer = ignoreRaycastLayerValue ;
728760 currentTrackedAreaObject . AddComponent < LineRenderer > ( ) ;
761+ // todo: update...
729762 currentTrackedAreaObject . transform . Translate ( new Vector3 (
730- MixedRealityToolkit . Instance . MixedRealityPlayspace . position . x ,
763+ Playspace . position . x ,
731764 boundaryObjectRenderOffset ,
732- MixedRealityToolkit . Instance . MixedRealityPlayspace . position . z ) ) ;
765+ Playspace . position . z ) ) ;
733766 currentPlayAreaObject . layer = TrackedAreaPhysicsLayer ;
734767
735768 // Configure the renderer properties.
736769 float lineWidth = 0.01f ;
737770 LineRenderer lineRenderer = currentTrackedAreaObject . GetComponent < LineRenderer > ( ) ;
738- lineRenderer . sharedMaterial = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . TrackedAreaMaterial ;
771+ lineRenderer . sharedMaterial = profile . TrackedAreaMaterial ;
739772 lineRenderer . useWorldSpace = false ;
740773 lineRenderer . startWidth = lineWidth ;
741774 lineRenderer . endWidth = lineWidth ;
@@ -757,6 +790,9 @@ public GameObject GetBoundaryWallVisualization()
757790 return currentBoundaryWallObject ;
758791 }
759792
793+ MixedRealityBoundaryVisualizationProfile profile = ConfigurationProfile as MixedRealityBoundaryVisualizationProfile ;
794+ if ( profile == null ) { return null ; }
795+
760796 if ( ! FloorHeight . HasValue )
761797 {
762798 // We need a floor on which to place the walls.
@@ -778,7 +814,7 @@ public GameObject GetBoundaryWallVisualization()
778814 {
779815 GameObject wall = GameObject . CreatePrimitive ( PrimitiveType . Cube ) ;
780816 wall . name = $ "Wall { i } ";
781- wall . GetComponent < Renderer > ( ) . sharedMaterial = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . BoundaryWallMaterial ;
817+ wall . GetComponent < Renderer > ( ) . sharedMaterial = profile . BoundaryWallMaterial ;
782818 wall . transform . localScale = new Vector3 ( ( Bounds [ i ] . PointB - Bounds [ i ] . PointA ) . magnitude , BoundaryHeight , wallDepth ) ;
783819 wall . layer = ignoreRaycastLayerValue ;
784820
@@ -806,6 +842,9 @@ public GameObject GetBoundaryCeilingVisualization()
806842 return currentCeilingObject ;
807843 }
808844
845+ MixedRealityBoundaryVisualizationProfile profile = ConfigurationProfile as MixedRealityBoundaryVisualizationProfile ;
846+ if ( profile == null ) { return null ; }
847+
809848 if ( Bounds . Length == 0 )
810849 {
811850 // If we do not have boundary edges, we cannot render a ceiling.
@@ -830,7 +869,7 @@ public GameObject GetBoundaryCeilingVisualization()
830869 boundaryBoundingBox . center . x ,
831870 BoundaryHeight + ( currentCeilingObject . transform . localScale . y * 0.5f ) ,
832871 boundaryBoundingBox . center . z ) ) ;
833- currentCeilingObject . GetComponent < Renderer > ( ) . sharedMaterial = MixedRealityToolkit . Instance . ActiveProfile . BoundaryVisualizationProfile . BoundaryCeilingMaterial ;
872+ currentCeilingObject . GetComponent < Renderer > ( ) . sharedMaterial = profile . BoundaryCeilingMaterial ;
834873 currentCeilingObject . layer = CeilingPhysicsLayer ;
835874 currentCeilingObject . transform . parent = BoundaryVisualizationParent . transform ;
836875
0 commit comments