gpt4 book ai didi

ios - 使用 ARHitTestResult 识别平面的对齐情况?

转载 作者:行者123 更新时间:2023-11-29 00:03:24 24 4
gpt4 key购买 nike

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

ARKit session 配置为:

    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

关于ios - 使用 ARHitTestResult 识别平面的对齐情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48763169/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com