【发布时间】:2019-01-19 04:36:26
【问题描述】:
我正在开发一个 ARKit 应用程序,我正在检测飞机,现在我想在飞机顶部放置一个物体。该对象确实被添加到平面上,但它在平面下方一点点。我可以添加盒子的高度/2,它会解决这个问题,但想知道是否有更简单的方法。
private func addBox(at position: SCNVector3) {
let box = SCNBox(width: 0.2, height: 0.2, length: 0.2, chamferRadius: 0)
let material = SCNMaterial()
material.diffuse.contents = UIColor.red
let boxNode = SCNNode(geometry: box)
boxNode.position = position
self.sceneView.scene.rootNode.addChildNode(boxNode)
}
@objc func tapped(recognizer :UITapGestureRecognizer) {
let touch = recognizer.location(in: self.sceneView)
if let nodeHitTest = self.sceneView.hitTest(touch, options: nil).first, nodeHitTest.node.name != "plane" {
print("node")
print(nodeHitTest.node)
} else if let planeHitTest = self.sceneView.hitTest(touch, types: .estimatedHorizontalPlane).first {
let position = SCNVector3(planeHitTest.worldTransform.columns.3.x, planeHitTest.worldTransform.columns.3.y, planeHitTest.worldTransform.columns.3.z)
addBox(at: position)
print("plane found")
}
}
【问题讨论】: