func loadNodeWithGeometry(scene:String, nodeName:String?, bitMask:Int?, contactTestBitMask:Int?, visible:Bool) { let node: SCNNode if let scene = SCNScene(named: "art.scnassets/\(scene).dae") { if let nodeName = nodeName { if let namedNode = scene.rootNode.childNodeWithName(nodeName, recursively: true) { node = namedNode } else { node = SCNNode() } } else { if let firstNode = scene.rootNode.childNodes.first { node = firstNode } else { node = SCNNode() } } if let bitMask = bitMask { if let geometry = node.geometry { node.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.Static, shape: SCNPhysicsShape(geometry: geometry, options: [SCNPhysicsShapeTypeKey: SCNPhysicsShapeTypeConcavePolyhedron])) node.physicsBody?.categoryBitMask = bitMask node.physicsBody?.contactTestBitMask = contactTestBitMask! } else { if let splitContainer = node.childNodes.first { for childNode in splitContainer.childNodes { if let geometry = childNode.geometry { childNode.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.Static, shape: SCNPhysicsShape(geometry: geometry, options: [SCNPhysicsShapeTypeKey: SCNPhysicsShapeTypeConcavePolyhedron])) childNode.physicsBody?.categoryBitMask = bitMask node.physicsBody?.contactTestBitMask = contactTestBitMask! // childNode.opacity = visible ? 1.0: 0.0 // sceneView.scene?.rootNode.addChildNode(childNode) } } } } } node.opacity = visible ? 1.0: 0.0 sceneView.scene?.rootNode.addChildNode(node) } }