Har*_*har 1 boolean ios scenekit swift arkit
我不确定如何真正使用此功能。我在互联网上进行了彻底搜索,但找不到所使用的此功能示例的实例。在SceneKit中,我非常熟悉按节点名称搜索的函数..但是,这很令人困惑,因为它返回对布尔值的引用,该布尔值指定了一个数组。
func childNodes(passingTest predicate: (SCNNode, UnsafeMutablePointer<ObjCBool>) -> Bool) -> [SCNNode]
Run Code Online (Sandbox Code Playgroud)
我到了这一点..这给了我所有我不知道为什么的节点。
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
}
)
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激!谢谢!
childNodes(passingTest:)Expect 的定义期望一个带有两个参数并返回Bool的闭包。闭包的参数为:
child=>要检查的节点(node由您调用)stop=>表示停止测试。ballYesOrNo像您那样进行调用本质上是令人困惑的,最好stop按照文档中的建议进行命名。因此,当且仅当您要停止算法时,才必须进行修改 stop。您永远都不想直接返回的值。stop
要说一个子节点匹配,必须返回trueelse 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
}
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
477 次 |
| 最近记录: |