從 collada 或 scn 檔案載入動畫

迅速

從檔案載入動畫的功能:

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
}

將動畫應用於節點:

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