Exemple #1
0
    /// <summary>
    /// Returns an array of 3d points (in clockwise order) that define the specified boundary type.
    /// All points are returned in local tracking space shared by tracked nodes and accessible through OVRCameraRig's trackingSpace anchor.
    /// </summary>
    public Vector3[] GetGeometry(OVRBoundary.BoundaryType boundaryType)
    {
        if (OVRManager.loadedXRDevice != OVRManager.XRDevice.Oculus)
        {
#if UNITY_2017_1_OR_NEWER
            if (Boundary.TryGetGeometry(cachedGeometryList, (boundaryType == BoundaryType.PlayArea) ? Boundary.Type.PlayArea : Boundary.Type.TrackedArea))
            {
                Vector3[] arr = cachedGeometryList.ToArray();
                return(arr);
            }
#endif
            Debug.LogError("This functionality is not supported in your current version of Unity.");
            return(null);
        }

        int pointsCount = 0;
        if (OVRPlugin.GetBoundaryGeometry2((OVRPlugin.BoundaryType)boundaryType, IntPtr.Zero, ref pointsCount))
        {
            if (pointsCount > 0)
            {
                int requiredNativeBufferCapacity = pointsCount * cachedVector3fSize;
                if (cachedGeometryNativeBuffer.GetCapacity() < requiredNativeBufferCapacity)
                {
                    cachedGeometryNativeBuffer.Reset(requiredNativeBufferCapacity);
                }

                int requiredManagedBufferCapacity = pointsCount * 3;
                if (cachedGeometryManagedBuffer.Length < requiredManagedBufferCapacity)
                {
                    cachedGeometryManagedBuffer = new float[requiredManagedBufferCapacity];
                }

                if (OVRPlugin.GetBoundaryGeometry2((OVRPlugin.BoundaryType)boundaryType, cachedGeometryNativeBuffer.GetPointer(), ref pointsCount))
                {
                    Marshal.Copy(cachedGeometryNativeBuffer.GetPointer(), cachedGeometryManagedBuffer, 0, requiredManagedBufferCapacity);

                    Vector3[] points = new Vector3[pointsCount];

                    for (int i = 0; i < pointsCount; i++)
                    {
                        points[i] = new OVRPlugin.Vector3f()
                        {
                            x = cachedGeometryManagedBuffer[3 * i + 0],
                            y = cachedGeometryManagedBuffer[3 * i + 1],
                            z = cachedGeometryManagedBuffer[3 * i + 2],
                        }.FromFlippedZVector3f();
                    }

                    return(points);
                }
            }
        }

        return(new Vector3[0]);
    }
Exemple #2
0
 public static bool TryGetGeometry(List <Vector3> geometry)
 {
     Boundary.Type boundaryType = Boundary.Type.PlayArea;
     return(Boundary.TryGetGeometry(geometry, boundaryType));
 }