我已经触摸开始发现,然后在用户点击屏幕时放置一个节点。
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touchLocation = touches.first?.location(in: sceneView)
{
let hitTestResults = sceneView.hitTest(touchLocation, types: .featurePoint)
if let hitResult = hitTestResults.first
{
addDot(at: hitResult)
}
}
}
func addDot(at hitResult : ARHitTestResult)
{
let imagePlane = SCNPlane(width: 0.1, height: 0.1)
imagePlane.firstMaterial?.diffuse.contents = UIImage(named: "helmet_R.png")
let planeNode = SCNNode(geometry: imagePlane)
planeNode.position = SCNVector3(hitResult.worldTransform.columns.3.x, hitResult.worldTransform.columns.3.y, hitResult.worldTransform.columns.3.z)
planeNode.constraints = [SCNBillboardConstraint()]
sceneView.scene.rootNode.addChildNode(planeNode)
我尝试了一个简单的
planeNode.removeFromParentNode()