【问题标题】:Identify the alignment of the plane by using the ARHitTestResult?使用 ARHitTestResult 识别平面的对齐方式?
【发布时间】:2023-03-27 02:32:01
【问题描述】:

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

ARKit 会话配置为:

    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 测试版

【问题讨论】:

    标签: ios iphone ipad arkit


    【解决方案1】:

    要检测平面的对齐情况,您可以执行以下操作:

        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
    

    【讨论】:

      猜你喜欢
      • 2023-01-30
      • 1970-01-01
      • 1970-01-01
      • 2014-10-18
      • 1970-01-01
      • 2019-10-15
      • 2012-03-01
      • 2015-10-13
      • 1970-01-01
      相关资源
      最近更新 更多