使用 ARHitTestResult 识别平面的对齐方式?

Identify the alignment of the plane by using the ARHitTestResult?

我们正在使用 ARKit 来检测水平面和垂直面。当用户点击屏幕上的某处时,它会使用 hittest 函数获取世界坐标,并将 3D 对象放置在该特定位置。现在我想要的是检测飞机的类型天气最近检测到的飞机是垂直的还是水平的?

A​​RKit 会话配置为:

    let configuration = ARWorldTrackingConfiguration()
    configuration.planeDetection = [.vertical, .horizontal]
    sceneView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors])

这是我们放置 3D 对象的方式:

    let sceneView = tapGesture.view as! ARSCNView
    let location = tapGesture.location(in: sceneView)

    let result = sceneView.hitTest(location, types: .existingPlane).first

    guard let hitResult = result else {
        debugPrint("Unable to get hit result")
        return
    }

    let position = SCNVector3(hitResult.worldTransform.columns.3.x,
                              hitResult.worldTransform.columns.3.y,
                              hitResult.worldTransform.columns.3.z)
    addNode(position: position)

我们正在使用 Xcode: 9.3 beta

要检测平面的对齐方式,您可以这样做:

    let sceneView = gestureRecognizer.view as! ARSCNView
    let location = gestureRecognizer.location(in: sceneView)


    let likelyHitResult = sceneView.hitTest(location, types: .existingPlane).filter { (result) -> Bool in
        return (result.anchor as? ARPlaneAnchor)?.alignment == ARPlaneAnchor.Alignment.vertical
    }.first