SceneKit - how to get animations for a .dae model?

2020-05-24 18:50发布

Ok, I am working with ARKit and scene kit here and I am having trouble looking at the other questions dealing with just scene kit trying to have a model in .dae format and load in various animations to have that model run - now that we're in iOS11 seems that some solutions don't work.

Here is how I get my model - from a base .dae scene where no animations are applied. I am importing these with Maya -

var modelScene = SCNScene(named: "art.scnassets/ryderFinal3.dae")!

if let d = modelScene.rootNode.childNodes.first {
    theDude.node = d
    theDude.setupNode()
}

Then in Dude class:

func setupNode() {
    node.scale = SCNVector3(x: modifier, y: modifier, z: modifier)
    center(node: node)
}

the scaling and centering of axes is needing because my model was just not at the origin. That worked. Then now with a different scene called "Idle.dae" I try to load in an animation to later run on the model:

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
}

I was going to do this for all my animations scenes that I import into Xcode and store all the animations in

var animations = [CAAnimation]()

First Xcode says animation(forKey: is deprecated and This does not work it seems to (from what I can tell) de-center and de-scale my model back to the huge size it was. It screws up its position because I expect making the model move in an animation, for example, would make the instantiated model in my game snap to that same position.

and other attempts cause crashes. I am very new to scene kit and trying to get a grip on how to properly animate a .dae model that I instantiate anywhere in the scene -

  1. How in iOS11 does one load in an array of animations to apply to their SCNNode?

  2. How do you make it so those animations are run on the model WHEREVER THE MODEL IS (not snapping it to some other position)?

0条回答
登录 后发表回答