我们正在使用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 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