Skip to content

Commit 0820083

Browse files
author
David Kline (ANALOG)
committed
update playarea and floor visualization, boundary vis profile
1 parent 26ac05a commit 0820083

17 files changed

+390
-500
lines changed

Assets/MixedRealityToolkit-Examples/Demos/Boundary/Scenes/BoundaryVisualization.unity

Lines changed: 141 additions & 356 deletions
Large diffs are not rendered by default.

Assets/MixedRealityToolkit-Examples/Demos/Boundary/Scripts/BoundaryVisualizationDemo.cs renamed to Assets/MixedRealityToolkit-Examples/Demos/Boundary/Scripts/BoundaryIndicatorDemo.cs

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4+
using Microsoft.MixedReality.Toolkit.Internal.Definitions.BoundarySystem;
45
using Microsoft.MixedReality.Toolkit.Internal.Interfaces;
56
using Microsoft.MixedReality.Toolkit.Internal.Managers;
6-
using Microsoft.MixedReality.Toolkit.Internal.Utilities;
77
using UnityEngine;
88
using UnityEngine.Experimental.XR;
99

@@ -12,29 +12,8 @@ namespace Microsoft.MixedReality.Toolkit.Examples.Demos
1212
/// <summary>
1313
/// Demo class to show different ways of using the boundary API.
1414
/// </summary>
15-
public class BoundaryVisualizationDemo : MonoBehaviour
15+
public class BoundaryIndicatorDemo : MonoBehaviour
1616
{
17-
/// <summary>
18-
/// The material used to display indicators that are within the boundary geometry.
19-
/// </summary>
20-
[SerializeField]
21-
[Tooltip("Material used to display indicators that are within the boundary geometry.")]
22-
private Material boundsMaterial = null;
23-
24-
/// <summary>
25-
/// The material used to display indicators that are outside of the boundary geometry.
26-
/// </summary>
27-
[SerializeField]
28-
[Tooltip("Material used to display indicators that are outside of the boundary geometry.")]
29-
private Material outOfBoundsMaterial = null;
30-
31-
/// <summary>
32-
/// The material used to display the indicators that are within the inscribed rectangle..
33-
/// </summary>
34-
[SerializeField]
35-
[Tooltip("Material used to display the indicators that are within the inscribed rectangle.")]
36-
private Material inscribedRectangleMaterial = null;
37-
3817
/// <summary>
3918
/// Boundary system implementation.
4019
/// </summary
@@ -66,6 +45,13 @@ private void AddIndicators()
6645
return;
6746
}
6847

48+
MixedRealityBoundaryVisualizationProfile visualizationProfile = MixedRealityManager.Instance.ActiveProfile.BoundaryVisualizationProfile;
49+
if (visualizationProfile == null)
50+
{
51+
// We do not have a visualization profile configured, therefore do not render the indicators.
52+
return;
53+
}
54+
6955
const int indicatorCount = 20;
7056
const float indicatorDistance = 0.2f;
7157
const float indicatorScale = 0.1f;
@@ -87,17 +73,17 @@ private void AddIndicators()
8773
marker.transform.localScale = Vector3.one * indicatorScale;
8874

8975
// Get the desired material for the marker.
90-
Material material = outOfBoundsMaterial;
76+
Material material = visualizationProfile.FloorPlaneMaterial;
9177

9278
// Check inscribed rectangle first
9379
if (BoundaryManager.Contains(position, Boundary.Type.PlayArea))
9480
{
95-
material = inscribedRectangleMaterial;
81+
material = visualizationProfile.PlayAreaMaterial;
9682
}
9783
// Then check geometry
9884
else if (BoundaryManager.Contains(position, Boundary.Type.TrackedArea))
9985
{
100-
material = boundsMaterial;
86+
material = visualizationProfile.TrackedAreaMaterial;
10187
}
10288

10389
marker.GetComponent<MeshRenderer>().sharedMaterial = material;

Assets/MixedRealityToolkit-Examples/Demos/Boundary/Scripts/BoundaryVisualizationDemo.cs.meta renamed to Assets/MixedRealityToolkit-Examples/Demos/Boundary/Scripts/BoundaryIndicatorDemo.cs.meta

File renamed without changes.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
using Microsoft.MixedReality.Toolkit.Internal.Definitions.BoundarySystem;
5+
using Microsoft.MixedReality.Toolkit.Internal.Managers;
6+
using UnityEngine;
7+
8+
namespace Microsoft.MixedReality.Toolkit.SDK.Boundary
9+
{
10+
/// <summary>
11+
/// Visualizes the floor plane.
12+
/// </summary>
13+
public class FloorPlaneVisualizer : MonoBehaviour
14+
{
15+
[Tooltip("Should the floor plane be visualized?")]
16+
[SerializeField]
17+
private bool isFloorPlaneVisualized = true;
18+
19+
/// <summary>
20+
/// Gets or sets a value indicating whether or not the floor plane is / should be visualized.
21+
/// </summary>
22+
public bool IsFloorPlaneVisualized
23+
{
24+
get { return isFloorPlaneVisualized; }
25+
set
26+
{
27+
if (value != isFloorPlaneVisualized)
28+
{
29+
isFloorPlaneVisualized = value;
30+
}
31+
}
32+
}
33+
34+
private MixedRealityBoundaryVisualizationProfile visualizationProfile;
35+
36+
/// <summary>
37+
/// The <see cref="GameObject"/> (Quad) used to visualize the play area.
38+
/// </summary>
39+
private GameObject floorPlane = null;
40+
41+
private void Start()
42+
{
43+
if (MixedRealityManager.HasActiveProfile && MixedRealityManager.Instance.ActiveProfile.IsBoundarySystemEnabled)
44+
{
45+
visualizationProfile = MixedRealityManager.Instance.ActiveProfile.BoundaryVisualizationProfile;
46+
}
47+
}
48+
49+
private void Update()
50+
{
51+
if ((floorPlane != null) && (isFloorPlaneVisualized != floorPlane.activeSelf))
52+
{
53+
// Show/hide the play area visualization
54+
floorPlane.SetActive(isFloorPlaneVisualized);
55+
}
56+
else if ((floorPlane == null) && (isFloorPlaneVisualized))
57+
{
58+
CreatePlayAreaObject();
59+
}
60+
}
61+
62+
/// <summary>
63+
/// Creates a rectangular <see cref="GameObject"/> to represent the
64+
/// play area within the configured boundary.
65+
/// </summary>
66+
private void CreatePlayAreaObject()
67+
{
68+
if (visualizationProfile == null)
69+
{
70+
// We do not have a visualization profile configured, therefore do not render the quad.
71+
return;
72+
}
73+
74+
// Render the floor.
75+
floorPlane = GameObject.CreatePrimitive(PrimitiveType.Quad);
76+
floorPlane.transform.SetParent(transform);
77+
floorPlane.transform.Translate(Vector3.zero);
78+
floorPlane.transform.Rotate(90, 0, 0);
79+
floorPlane.transform.localScale = visualizationProfile.FloorPlaneScale;
80+
floorPlane.GetComponent<Renderer>().sharedMaterial = visualizationProfile.FloorPlaneMaterial;
81+
}
82+
}
83+
}

Assets/MixedRealityToolkit-SDK/Features/Boundary/Components/Scripts/FloorPlaneVisualizer.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.

Assets/MixedRealityToolkit-SDK/Features/Boundary/Components/Scripts/VisualizePlayArea.cs renamed to Assets/MixedRealityToolkit-SDK/Features/Boundary/Components/Scripts/PlayAreaVisualizer.cs

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using Microsoft.MixedReality.Toolkit.Internal.Interfaces;
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+
using Microsoft.MixedReality.Toolkit.Internal.Definitions.BoundarySystem;
5+
using Microsoft.MixedReality.Toolkit.Internal.Interfaces;
26
using Microsoft.MixedReality.Toolkit.Internal.Managers;
37
using Microsoft.MixedReality.Toolkit.Internal.Utilities;
48
using UnityEngine;
@@ -8,27 +12,14 @@ namespace Microsoft.MixedReality.Toolkit.SDK.Boundary
812
/// <summary>
913
/// Visualizes the inscribed rectangular play area within the configured boundary.
1014
/// </summary>
11-
public class VisualizePlayArea : MonoBehaviour
15+
public class PlayAreaVisualizer : MonoBehaviour
1216
{
13-
[Tooltip("The material to use when visualizing the play area rectangle.")]
14-
[SerializeField]
15-
private Material playAreaMaterial = null;
16-
17-
/// <summary>
18-
/// The material to use when visualizing the play area rectangle.
19-
/// </summary>
20-
public Material PlayAreaMaterial
21-
{
22-
get { return playAreaMaterial; }
23-
set { playAreaMaterial = value; }
24-
}
25-
2617
[Tooltip("Should the play area be visualized?")]
2718
[SerializeField]
2819
private bool isPlayAreaVisualized = true;
2920

3021
/// <summary>
31-
/// Gets or sets a value indicating whether or not the play area is visualized.
22+
/// Gets or sets a value indicating whether or not the play area is / should be visualized.
3223
/// </summary>
3324
public bool IsPlayAreaVisualized
3425
{
@@ -48,26 +39,32 @@ public bool IsPlayAreaVisualized
4839
private IMixedRealityBoundarySystem boundaryManager = null;
4940
private IMixedRealityBoundarySystem BoundaryManager => boundaryManager ?? (boundaryManager = MixedRealityManager.Instance.GetManager<IMixedRealityBoundarySystem>());
5041

42+
private MixedRealityBoundaryVisualizationProfile visualizationProfile;
43+
5144
/// <summary>
5245
/// The <see cref="GameObject"/> (Quad) used to visualize the play area.
5346
/// </summary>
5447
private GameObject playArea = null;
5548

49+
private void Start()
50+
{
51+
if (MixedRealityManager.HasActiveProfile && MixedRealityManager.Instance.ActiveProfile.IsBoundarySystemEnabled)
52+
{
53+
visualizationProfile = MixedRealityManager.Instance.ActiveProfile.BoundaryVisualizationProfile;
54+
}
55+
}
56+
5657
private void Update()
5758
{
58-
if (!isPlayAreaVisualized)
59+
if ((playArea != null) &&
60+
(isPlayAreaVisualized != playArea.activeSelf))
5961
{
60-
// Hide the play area object.
61-
playArea?.SetActive(false);
62+
// Show/hide the play area visualization
63+
playArea.SetActive(isPlayAreaVisualized);
6264
}
63-
else
65+
else if ((playArea == null) && (isPlayAreaVisualized))
6466
{
65-
// Show or create the play area object.
66-
if (playArea != null)
67-
{
68-
playArea.SetActive(true);
69-
}
70-
else
67+
if (MixedRealityManager.HasActiveProfile && MixedRealityManager.Instance.ActiveProfile.IsBoundarySystemEnabled)
7168
{
7269
CreatePlayAreaObject();
7370
}
@@ -85,12 +82,14 @@ private void CreatePlayAreaObject()
8582
float angle;
8683
float width;
8784
float height;
88-
if ((BoundaryManager == null) || !BoundaryManager.TryGetRectangularBoundsParams(out center, out angle, out width, out height))
85+
if ((BoundaryManager == null) ||
86+
!BoundaryManager.TryGetRectangularBoundsParams(out center, out angle, out width, out height) ||
87+
(visualizationProfile == null))
8988
{
9089
// No rectangular bounds, therefore do not render the quad.
9190
return;
9291
}
93-
92+
9493
// Render the rectangular bounds.
9594
if (EdgeUtilities.IsValidPoint(center))
9695
{
@@ -99,7 +98,7 @@ private void CreatePlayAreaObject()
9998
playArea.transform.Translate(new Vector3(center.x, 0.005f, center.y)); // Add fudge factor to avoid z-fighting
10099
playArea.transform.Rotate(new Vector3(90, -angle, 0));
101100
playArea.transform.localScale = new Vector3(width, height, 1.0f);
102-
playArea.GetComponent<Renderer>().sharedMaterial = playAreaMaterial;
101+
playArea.GetComponent<Renderer>().sharedMaterial = visualizationProfile.PlayAreaMaterial;
103102
}
104103
}
105104
}

Assets/MixedRealityToolkit-SDK/Features/Boundary/Components/Scripts/VisualizePlayArea.cs.meta renamed to Assets/MixedRealityToolkit-SDK/Features/Boundary/Components/Scripts/PlayAreaVisualizer.cs.meta

File renamed without changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_PrefabParentObject: {fileID: 0}
7+
m_PrefabInternal: {fileID: 0}
8+
m_GameObject: {fileID: 0}
9+
m_Enabled: 1
10+
m_EditorHideFlags: 0
11+
m_Script: {fileID: 11500000, guid: 8989e381a7c097840b2d40378a63497a, type: 3}
12+
m_Name: DefaultMixedRealityBoundaryVisualizationProfile
13+
m_EditorClassIdentifier:
14+
playAreaMaterial: {fileID: 2100000, guid: 30d693ff62c571241b431ef4e206b09a, type: 2}
15+
trackedAreaMaterial: {fileID: 2100000, guid: 1ab3a050711c97243a200ca653272343, type: 2}
16+
floorPlaneMaterial: {fileID: 2100000, guid: e106645f46550d54bacf6c82811c99e6, type: 2}
17+
floorPlaneScale: {x: 3, y: 3, z: 1}

Assets/MixedRealityToolkit-SDK/Profiles/DefaultMixedRealityBoundaryVisualizationProfile.asset.meta

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

Assets/MixedRealityToolkit-SDK/Profiles/DefaultMixedRealityConfigurationProfile.asset

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ MonoBehaviour:
3737
Microsoft.MixedReality.Toolkit.BoundarySystem
3838
boundaryHeight: 3
3939
enablePlatformBoundaryRendering: 1
40+
boundaryVisualizationProfile: {fileID: 11400000, guid: c1f4aa213e301a446aca3858e6f4ad17,
41+
type: 2}

0 commit comments

Comments
 (0)