scenekit

Animation

Load an animation from a collada or scn file

Swift

Function for loading an animation from a file:

func animationFromSceneNamed(path: String) -> CAAnimation? {
    let scene  = SCNScene(named: path)
    var animation:CAAnimation?
    scene?.rootNode.enumerateChildNodes({ child, stop in
        if let animKey = child.animationKeys.first {
            animation = child.animation(forKey: animKey)
            stop.pointee = true
        }
    })
    return animation
}

Apply animation to node:

let animation = animationFromSceneNamed("art.scnassets/animation.dae")
myNode.addAnimation(animation, forKey: "anim")

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow