3

Ok, I have looked EVERYWHERE and am trying here to simply extract an animation from a .dae imported into Xcode (or a .scn, whatever) so that I can run it on the model throughout my scene kit game. the problem is every way to do this that is referenced (including here Scenekit: Add animation to SCNNode from external Collada)

seems to be deprecated in iOS 11. So I have no way to animate any 3D model I put in my scene.

Right now I am able to display the model just still with this - I get the model from my dae and put it into my blank scn :

if let d = modelScene.rootNode.childNodes.first
        {
            theDude.node = d
            theDude.setupNode() //this scales it down
        }
func setupNode()
    {
        node.scale = SCNVector3(x: modifier, y: modifier, z: modifier)
}

//Then add to scene on tap

let clone = theDude.node.clone()
            theDude.node = clone
            self.sceneView.scene.rootNode.addChildNode(theDude.node)
            theDude.node.position = hitPosition

This works. Trying to get it to run the animation that I added to it in Maya, however, does not. I added these extensions per Apple's example to my project: https://developer.apple.com/library/content/samplecode/Fox/Listings/Swift_Common_SceneKitExtensions_swift.html

And was trying to do this as it says to, just with a cube as a basic test (from the above question):

func addAnim()
    {
        let characterScene = SCNScene(named: "art.scnassets/cubeAnimatedSkeleton.dae")!
        let characterTopLevelNode = characterScene.rootNode.childNodes[0]
        sceneView.scene.rootNode.addChildNode(characterTopLevelNode)
        let idleAnimation = CAAnimation.animationWithSceneNamed("art.scnassets/cubeAnimatedSkeleton.dae")!

        idleAnimation.usesSceneTimeBase = false
        idleAnimation.repeatCount = Float.infinity
        characterTopLevelNode.addAnimation(idleAnimation, forKey: "idle")
    }

But with this CAAnimation.animationWithSceneNamed("art.scnassets/cubeAnimatedSkeleton.dae")! the whole thing does not work because this extension from APPLE:

extension CAAnimation {
    class func animationWithSceneNamed(_ name: String) -> CAAnimation? {
        var animation: CAAnimation?
        if let scene = SCNScene(named: name) {
            scene.rootNode.enumerateChildNodes({ (child, stop) in
                if child.animationKeys.count > 0 {
                    animation = child.animation(forKey: child.animationKeys.first!) //ERROR

                    stop.initialize(to: true)
                }
            })
        }
        return animation
    }
}

says that addAnimation for key was deprecated in iOS 11. Replacing that with animation = child.animationPlayer(forKey: child.animationKeys.first!) doesn't work, and I don't know what else to do.

What is wrong here?

blue
  • 7,175
  • 16
  • 81
  • 179

0 Answers0