How to detect vertical planes in ARKit?

前端 未结 7 2005
闹比i
闹比i 2020-12-12 19:30

How is it possible to implement a vertical plane detection (i.e. for walls)?

let configuration = ARWorldTrackingSessionConfiguration()
configuration.planeDet         


        
7条回答
  •  无人及你
    2020-12-12 19:35

    In ARKit 1.0 there was just .horizontal enum's case for detecting horizontal surfaces like a table or a floor. In ARKit 1.5 and higher there are .horizontal and .vertical type properties of a PlaneDetection struct that conforms to OptionSet protocol.

    To implement a vertical plane detection in ARKit 2.0 use the following code:

    configuration.planeDetection = ARWorldTrackingConfiguration.PlaneDetection.vertical
    

    Or you can use detection for both types of planes:

    private func configureSceneView(_ sceneView: ARSCNView) {
    
        let configuration = ARWorldTrackingConfiguration()
        configuration.planeDetection = [.horizontal, .vertical]    //BOTH TYPES
        configuration.isLightEstimationEnabled = true
        sceneView.session.run(configuration)
    }
    

    Also you can add an extension to ARSceneManager to handle the delegate calls:

    extension ARSceneManager: ARSCNViewDelegate {
    
        func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
            guard let planeAnchor = anchor as? ARPlaneAnchor else { 
                return 
            }
            print("Found plane: \(planeAnchor)")
        }
    }
    

提交回复
热议问题