在SceneKit中检测对象的子节点上的触摸



这个问题基本上是针对SceneKit的。

我有一个父节点,里面有几个较小的节点,稍后点的父节点变为透明的(父节点的漫反射材质不透明度设置为0(,之后我想获得在对象内部点击的节点,我应该如何做到这一点?默认的命中测试返回父节点,由于对象中有一些较小的节点,所以我需要被点击的精确节点。

要解决这个问题,我建议阅读Apple的下一个主题:

https://developer.apple.com/documentation/scenekit/scnhittestoption

总体思路:

func registerGestureRecognizer() {
let tap = UITapGestureRecognizer(target: self, action: #selector(search))
self.sceneView.addGestureRecognizer(tap)
}
@objc func search(sender: UITapGestureRecognizer) {
let sceneView = sender.view as! ARSCNView
let location = sender.location(in: sceneView)
let results = sceneView.hitTest(location, options: [SCNHitTestOption.searchMode : 1])
guard sender.state == .ended else { return }
for result in results.filter( { $0.node.name == "Your node name" }) {
// do manipulations
}
}

希望它能有所帮助!顺致敬意,

最新更新