【发布时间】:2019-03-06 04:06:04
【问题描述】:
当用户点击飞机时,我可以添加新的 scnplane。但是现在,点击同一个 scnplane,它会再次添加新的 scnplane,而不是删除。
最初检测到参考图像时,它会在菜单卡的一侧列出蛋糕的图像、名称和评分。用户点击评分,它将列出用户评分。
这是我尝试过的代码:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
//1. Get The Current Touch Location & Perform An ARSCNHitTest To Check For Any Hit SCNNode's
guard let currentTouchLocation = touches.first?.location(in: self.sceneView),
let hitTestNode = self.sceneView.hitTest(currentTouchLocation, options: nil).first?.node else { return }
if let lableName = hitTestNode.name {
print("touch working")
if lableName == "lableNode"{
makeCakeOnNode(hitTestNode)
} else if lableName == "AllLabelNode" {
makeCakeOnNode1(hitTestNode)
} else if lableName == "fruitNode" {
makeCakeOnNode2(hitTestNode)
}
}
}
func makeCakeOnNode(_ node: SCNNode){
let planeGeometry = SCNPlane(width: 0.18 , height: 0.15)
planeGeometry.firstMaterial?.diffuse.contents = UIColor.black.withAlphaComponent(0)
planeNode0 = SCNNode(geometry: planeGeometry)
planeNode0?.runAction(SCNAction.moveBy(x: -0.2, y: -0.15, z: 0, duration: 0))
let overlayNode = self.getNode(withImageName: "menu")
print("overlay::\(overlayNode)")
let newPlane = SCNPlane(width: 0.15, height: 0.10)
newPlane.firstMaterial?.diffuse.contents = UIImage(named: "cake_detail")
let newPlaneNode = SCNNode(geometry: newPlane)
newPlaneNode.eulerAngles.x = -.pi / 2
newPlaneNode.runAction(SCNAction.moveBy(x: -0.2, y: -0.15, z: 0, duration: 0))
node.addChildNode(planeNode0!)
planeNode0?.addChildNode(overlayNode)
planeNode0?.addChildNode(newPlaneNode)
if planeBool == true {
planeNode1?.isHidden = true
planeNode2?.isHidden = true
planeNode0?.isHidden = false
planeBool = false
} else {
print("plane removed")
planeNode0?.isHidden = true
planeNode1?.isHidden = true
planeNode2?.isHidden = true
planeBool = true
}
}
【问题讨论】: