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:
- Create an
SCNView
loading in the collada file - Retrieve each of the
SCNNode
from theSCNView.scene.rootNode
- Add the child nodes to the
SCNView
's root node usingaddChildNode
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
Check for Nil with Guard Instead of If
How to Resume Audio After Interruption in Swift
Use a Function to Find Common Elements in Two Sequences in Swift
Background Animation with Depth in Spritekit
Swiftui .Rotationeffect() Framing and Offsetting
Open a Viewcontroller from Remote Notification
Wait Until an Asynchronous API Call Is Completed - Swift/Ios
How to Set a Specific Default Time for a Date Picker in Swift
Swift Protocol Generic as Function Return Type
How to Create Text File for Writing
Understanding Shorthand Closure Syntax for Map Function in Swift
"Cannot Inherit from Non-Open Class" Swift
Treat *Some* Warnings as Errors in Swift
Swift Why Strcmp of Backspace Returns -92
Able to Write/Read File But Unable to Delete File Swift
Why No Infinite Loop in Didset
Can't Parse JSON Array with JSONdecoder in Swift 4
Create Skscene Subclasses Programmatically, Without Size Info