How to use DAE file with different Scene Graphs in iOS SceneKit

569 views Asked by At

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: enter image description here

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.

1

There are 1 answers

0
Alan On

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.