Load a Collada (Dae) File into Scnnode (Swift - Scenekit)

load a collada (dae) file into SCNNode (Swift - SceneKit)


// add a SCNScene as childNode to another SCNScene (in this case to scene)
func addSceneToScene() {
let geoScene = SCNScene(named: "art.scnassets/ball.dae")
scene.rootNode.addChildNode(geoScene.rootNode.childNodeWithName("Ball", recursively: true))
}
addSceneToScene()

How do you load a .dae file into an SCNNode in iOS SceneKit?

The usual pattern is to load your scene and retrieve the node you are interested in with its name using

[scene.rootNode childNodeWithName:aName recursively:YES];

Then you can reparent this node to your main scene.

Swift 3 load .dae file into SCNNode

A .dae file is always loaded as a SCNScene. You need to name the node containing the geometry you want to add.
Than you can load the scene, filter it for the node with the given name and add it to your scene.

func addNode(named nodeName, fromSceneNamed: sceneName, to scene: SCNScene) {
if let loadedScene = SCNScene(named: sceneName),
let node = loadedScene.rootNode.childNode(withName: nodeName, recursivly: true) {
scene.rootNode.addChildNode(node)
}
}

Loading Collada dae file into SceneKit for joint manipulation

In order to create the skeleton, I to build the skeleton as follows:

  1. Create an SCNView loading in the collada file
  2. Retrieve each of the SCNNode from the SCNView.scene.rootNode
  3. Add the child nodes to the SCNView's root node using addChildNode

Hope this helps!

Collada file not show clear in scenekit

Does your Collada file already have a camera in it, i.e. the one you're using to produce the first rendering?

If so, locate that camera/node (childNodeWithName). Assign it as your view's point of view. Don't create a new camera in your code.

Or, if you really need to create a new camera, put it at the same location as the point of view used for the first rendering.



Related Topics



Leave a reply



Submit