我不太确定如何真正使用此功能。我彻底搜索了互联网,但找不到使用此功能的示例实例。在 SceneKit 中,我非常熟悉按节点名称搜索的函数。但是这个函数令人困惑,因为它返回对指定数组的 bool 的引用。定义如下
func childNodes(passingTest predicate: (SCNNode, UnsafeMutablePointer<ObjCBool>) -> Bool) -> [SCNNode]
我到了这一步..这给了我所有我不知道为什么的节点..
let ballToDisappear = sceneView?.scene.rootNode.childNodes(passingTest: { (node, ballYesOrNo) -> Bool in
if (node.position.x < (maxVector?.x)! && node.position.x > (minVector?.x)!){
if (node.position.y < (maxVector?.y)! && node.position.y > (minVector?.y)!){
if (node.position.z < (maxVector?.z)! && node.position.z > (minVector?.z)!){
return ballYesOrNo.pointee.boolValue
}
}
}
return !ballYesOrNo.pointee.boolValue
}
)
任何帮助将不胜感激!谢谢!
最佳答案
childNodes(passingTest:)
的定义期望一个带有两个参数并返回 Bool 的闭包。闭包的参数是:
child
=> 要检查的节点(你称之为node
)stop
=> 表示停止测试。像您那样调用此ballYesOrNo
本质上是令人困惑的,最好按照文档的建议将其命名为stop
。
因此,当且仅当您想要停止算法时,您才必须修改 停止
。您绝对不想返回 stop
的值直接。
要说一个子节点匹配,你必须返回true
,否则返回false
。
因此:
let ballToDisappear = sceneView?.scene.rootNode.childNodes(passingTest: { (node, stop) -> Bool in
if (node.position.x < (maxVector?.x)! && node.position.x > (minVector?.x)!){
if (node.position.y < (maxVector?.y)! && node.position.y > (minVector?.y)!){
if (node.position.z < (maxVector?.z)! && node.position.z > (minVector?.z)!){
return false // or false here and true below??
}
}
}
return true // or true here, see above, depends on your logic
}
)
关于ios - 实现返回节点子树中满足测试的所有节点的 passingTest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47217307/