/// <summary> /// Retrieves the boundary geometry and creates the boundary and inscribed play space volumes. /// </summary> private void CalculateBoundaryBounds() { // Reset the bounds Bounds = new Edge[0]; FloorHeight = null; rectangularBounds = null; // Boundaries are supported for Room Scale experiences only. if (XRDevice.GetTrackingSpaceType() != TrackingSpaceType.RoomScale) { return; } // Get the boundary geometry. var boundaryGeometry = new List <Vector3>(0); var boundaryEdges = new List <Edge>(0); if (UnityBoundary.TryGetGeometry(boundaryGeometry, UnityBoundary.Type.TrackedArea) && boundaryGeometry.Count > 0) { // FloorHeight starts out as null. Use a suitably high value for the floor to ensure // that we do not accidentally set it too low. float floorHeight = float.MaxValue; for (int i = 0; i < boundaryGeometry.Count; i++) { Vector3 pointA = boundaryGeometry[i]; Vector3 pointB = boundaryGeometry[(i + 1) % boundaryGeometry.Count]; boundaryEdges.Add(new Edge(pointA, pointB)); floorHeight = Mathf.Min(floorHeight, boundaryGeometry[i].y); } FloorHeight = floorHeight; Bounds = boundaryEdges.ToArray(); CreateInscribedBounds(); } else { Debug.LogWarning("Failed to calculate boundary bounds."); } }
/// <summary> /// Retrieves the boundary geometry and creates the boundary and inscribed play space volumes. /// </summary> private void CalculateBoundaryBounds() { // Reset the bounds Bounds = System.Array.Empty <Edge>(); FloorHeight = null; RectangularBounds = null; // Get the boundary geometry. var boundaryGeometry = GetBoundaryGeometry(); if (boundaryGeometry != null && boundaryGeometry.Count > 0) { // Get the boundary geometry. var boundaryEdges = new List <Edge>(0); // FloorHeight starts out as null. Use a suitably high value for the floor to ensure // that we do not accidentally set it too low. float floorHeight = float.MaxValue; for (int i = 0; i < boundaryGeometry.Count; i++) { Vector3 pointA = boundaryGeometry[i]; Vector3 pointB = boundaryGeometry[(i + 1) % boundaryGeometry.Count]; boundaryEdges.Add(new Edge(pointA, pointB)); floorHeight = Mathf.Min(floorHeight, boundaryGeometry[i].y); } FloorHeight = floorHeight; Bounds = boundaryEdges.ToArray(); CreateInscribedBounds(); } else { Debug.LogWarning("Failed to calculate boundary bounds."); } }
/// <summary> /// Creates the two dimensional volume described by the largest rectangle that /// is contained withing the play space geometry and the configured height. /// </summary> private void CreateInscribedBounds() { // We always use the same seed so that from run to run, the inscribed bounds are consistent. rectangularBounds = new InscribedRectangle(Bounds, Mathf.Abs("Mixed Reality Toolkit".GetHashCode())); }