从 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")