Reputation: 571
I have an .dae file and want to use the model in SceneKit. The problem is that the .dae file has different Scene Graphs in it:
In my ViewController.swift I have this code:
let scene = SCNScene(named: "art.scnassets/Edward_Kenway.dae")!
self.baumNode = scene.rootNode.childNode(withName: "???", recursively: true)
What do I have to use in the childNode withName? If I select the first Scene graph (EdwardKenwayNecklace) and put the name of the Geometry (EdwardKenwayNecklaceMesh) in my code the application crashes.
Upvotes: 2
Views: 566
Reputation: 1142
You can loop through the child nodes of the scene and then add them all to a new node that you have made.
Something like this might work, assuming that this is what you are looking for.
func loadModel() {
let virtualObjectScene = SCNScene(named: path)
let wrapperNode = SCNNode()
for child: SCNNode in virtualObjectScene?.rootNode?.childNodes {
wrapperNode.addChildNode(child)
}
addChildNode(wrapperNode)
}
where the path is the name of your scene. This function is run after initializing an object of type SCNNode, and then calling loadModel on this object.
Upvotes: 1