Created
November 30, 2015 22:15
-
-
Save fluidpixel/203794d688da0b947fff to your computer and use it in GitHub Desktop.
LoadGeometryWithScene
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment