Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func magic() {
- guard let hat = sceneView.scene.rootNode.childNode(withName: HAT_IDENTIFIER, recursively: true) else { return }
- let hatWorldPosition = hat.worldPosition
- let (tubeMin, tubeMax): (SCNVector3, SCNVector3) = hat.boundingBox
- let minX = hatWorldPosition.x + tubeMin.x
- let minY = hatWorldPosition.y + tubeMin.y
- let minZ = hatWorldPosition.z + tubeMin.z
- let maxX = hatWorldPosition.x + tubeMax.x
- let maxY = hatWorldPosition.y + tubeMax.y
- let maxZ = hatWorldPosition.z + tubeMax.z
- for ball in balls {
- let pos = ball.presentation.worldPosition
- let isInsideHat = ((pos.x >= minX && pos.y >= minY && pos.z >= minZ) && (pos.x <= maxX && pos.y <= maxY && pos.z <= maxZ))
- let isOutsideHat = (pos.z < -1.0)
- if isInsideHat && !isOutsideHat {
- ball.isHidden = !ball.isHidden
- }
- }
- }
Add Comment
Please, Sign In to add comment