Files
VIVE-OpenXR-Unity/com.htc.upm.vive.openxr/Runtime/Features/PlaneDetection/Documentation/OpenXRExtensions.md
2024-12-06 15:44:37 +08:00

2.6 KiB

XR_EXT_plane_detection

Name String

XR_EXT_plane_detection

Revision

1

Overview

The PlaneDetectionManager class provides functionalities for managing plane detection using the VIVE XR SDK. It includes methods to check feature support, create and destroy plane detectors, and helper functions for interacting with the plane detection extension.

Plane Detection Workflow

  1. Check Feature Support:

    bool isSupported = PlaneDetectionManager.IsSupported();
    

    Ensure the plane detection feature is supported before attempting to create a plane detector.

  2. Create Plane Detector:

    PlaneDetector planeDetector = PlaneDetectionManager.CreatePlaneDetector();
    

    Create a plane detector instance to begin detecting planes.

  3. Begin Plane Detection:

    XrResult result = planeDetector.BeginPlaneDetection();
    

    Start the plane detection process.

  4. Get Plane Detection State:

    XrPlaneDetectionStateEXT state = planeDetector.GetPlaneDetectionState();
    

    Check the current state of the plane detection process.

  5. Retrieve Plane Detections:

    List<PlaneDetectorLocation> locations;
    XrResult result = planeDetector.GetPlaneDetections(out locations);
    

    Retrieve the detected planes.

  6. Get Plane Vertices:

    Plane plane = planeDetector.GetPlane(planeId);
    

    Retrieve the vertices of a specific plane.

  7. Destroy Plane Detector:

    PlaneDetectionManager.DestroyPlaneDetector(planeDetector);
    

    Destroy the plane detector to release resources.

Example Usage

Here's a basic example of how to use the PlaneDetectionManager to detect planes:


if (PlaneDetectionManager.IsSupported())
{
    var planeDetector = PlaneDetectionManager.CreatePlaneDetector();
    if (planeDetector != null)
    {
        planeDetector.BeginPlaneDetection();
        
        XrPlaneDetectionStateEXT state = planeDetector.GetPlaneDetectionState();
        if (state == XrPlaneDetectionStateEXT.DONE_EXT)
        {
            List<PlaneDetectorLocation> locations;
            if (planeDetector.GetPlaneDetections(out locations) == XrResult.XR_SUCCESS)
            {
                foreach (var location in locations)
                {
                    // Process detected planes
                }
            }
        }
        
        PlaneDetectionManager.DestroyPlaneDetector(planeDetector);
    }
}

This example checks if the plane detection feature is supported, creates a plane detector, begins the plane detection process, retrieves the detected planes, and finally destroys the plane detector to release resources.