-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2530 from Microsoft/june18_dev
2017.4.1 Stabilization and Merge PR
- Loading branch information
Showing
184 changed files
with
25,164 additions
and
7,495 deletions.
There are no files selected for viewing
1,630 changes: 1,496 additions & 134 deletions
1,630
Assets/HoloToolkit-Examples/Boundary/Scenes/BoundaryTest.unity
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
Assets/HoloToolkit-Examples/Boundary/Scripts/BoundaryVisualizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using UnityEngine; | ||
|
||
namespace HoloToolkit.Unity.Boundary.Tests | ||
{ | ||
/// <summary> | ||
/// Demo class to show different ways of using the boundary API. | ||
/// </summary> | ||
public class BoundaryVisualizer : MonoBehaviour | ||
{ | ||
#if UNITY_2017_2_OR_NEWER | ||
[SerializeField] | ||
[Tooltip("Material used to draw the inscribed rectangle bounds.")] | ||
private Material boundsMaterial = null; | ||
|
||
[SerializeField] | ||
[Tooltip("Material used to draw items in the tracked area bounds.")] | ||
private Material trackedAreaBoundsMaterial = null; | ||
|
||
private void Start() | ||
{ | ||
AddQuad(); | ||
AddIndicators(); | ||
} | ||
|
||
/// <summary> | ||
/// Displays the boundary as a quad primitive. | ||
/// </summary> | ||
private void AddQuad() | ||
{ | ||
Vector3 center; | ||
float angle; | ||
float width; | ||
float height; | ||
BoundaryManager.Instance.TryGetBoundaryRectangleParams(out center, out angle, out width, out height); | ||
|
||
var quad = GameObject.CreatePrimitive(PrimitiveType.Quad); | ||
quad.transform.SetParent(transform); | ||
quad.transform.Translate(center + new Vector3(0.0f, 0.005f, 0.0f)); // Add fudge factor to avoid z-fighting | ||
quad.transform.Rotate(new Vector3(90, -angle, 0)); | ||
quad.transform.localScale = new Vector3(width, height, 1.0f); | ||
} | ||
|
||
/// <summary> | ||
/// Displays the boundary as a rectangle using a LineRenderer. | ||
/// </summary> | ||
private void AddRectangleBounds() | ||
{ | ||
var points = BoundaryManager.Instance.TryGetBoundaryRectanglePoints(); | ||
if (points == null) | ||
{ | ||
return; | ||
} | ||
|
||
LineRenderer lr = gameObject.AddComponent<LineRenderer>(); | ||
lr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; | ||
lr.useWorldSpace = false; | ||
lr.loop = true; | ||
lr.sharedMaterial = boundsMaterial; | ||
lr.startWidth = 0.05f; | ||
lr.endWidth = 0.05f; | ||
lr.positionCount = points.Length; | ||
lr.SetPositions(points); | ||
} | ||
|
||
/// <summary> | ||
/// Displays the boundary as an array of spheres where spheres in the | ||
/// bounds are a different color. | ||
/// </summary> | ||
private void AddIndicators() | ||
{ | ||
const int indicatorCount = 15; | ||
const float indicatorDistance = 0.2f; | ||
const float dimension = indicatorCount * indicatorDistance; | ||
|
||
Vector3 center; | ||
float angle; | ||
float width; | ||
float height; | ||
if (!BoundaryManager.Instance.TryGetBoundaryRectangleParams(out center, out angle, out width, out height)) | ||
{ | ||
return; | ||
} | ||
|
||
Vector3 corner = center - (new Vector3(dimension, 0.0f, dimension) / 2.0f); | ||
corner.y += 0.05f; | ||
for (int xIndex = 0; xIndex < indicatorCount; ++xIndex) | ||
{ | ||
for (int yIndex = 0; yIndex < indicatorCount; ++yIndex) | ||
{ | ||
var offset = new Vector3(xIndex * indicatorDistance, 0.0f, yIndex * indicatorDistance); | ||
var position = corner + offset; | ||
var marker = GameObject.CreatePrimitive(PrimitiveType.Sphere); | ||
marker.transform.SetParent(transform); | ||
marker.transform.position = position; | ||
marker.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); | ||
|
||
var markerRenderer = marker.GetComponent<MeshRenderer>(); | ||
|
||
if (BoundaryManager.Instance.ContainsObject(position, UnityEngine.Experimental.XR.Boundary.Type.TrackedArea)) | ||
{ | ||
markerRenderer.sharedMaterial = trackedAreaBoundsMaterial; | ||
} | ||
|
||
if (BoundaryManager.Instance.ContainsObject(position, UnityEngine.Experimental.XR.Boundary.Type.PlayArea)) | ||
{ | ||
markerRenderer.sharedMaterial = boundsMaterial; | ||
} | ||
} | ||
} | ||
} | ||
#endif | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Assets/HoloToolkit-Examples/Boundary/Scripts/BoundaryVisualizer.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.