Guest User

Untitled

a guest
Jan 16th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. func magic() {
  2. guard let hat = sceneView.scene.rootNode.childNode(withName: HAT_IDENTIFIER, recursively: true) else { return }
  3. let hatWorldPosition = hat.worldPosition
  4.  
  5. let (tubeMin, tubeMax): (SCNVector3, SCNVector3) = hat.boundingBox
  6.  
  7. let minX = hatWorldPosition.x + tubeMin.x
  8. let minY = hatWorldPosition.y + tubeMin.y
  9. let minZ = hatWorldPosition.z + tubeMin.z
  10.  
  11. let maxX = hatWorldPosition.x + tubeMax.x
  12. let maxY = hatWorldPosition.y + tubeMax.y
  13. let maxZ = hatWorldPosition.z + tubeMax.z
  14.  
  15. for ball in balls {
  16. let pos = ball.presentation.worldPosition
  17. let isInsideHat = ((pos.x >= minX && pos.y >= minY && pos.z >= minZ) && (pos.x <= maxX && pos.y <= maxY && pos.z <= maxZ))
  18. let isOutsideHat = (pos.z < -1.0)
  19. if isInsideHat && !isOutsideHat {
  20. ball.isHidden = !ball.isHidden
  21. }
  22. }
  23. }
Add Comment
Please, Sign In to add comment