1
votes

Image of the file hierarchy in xcode of my animation file

Issue:

xcode is recognizing multiple animations for a single Collada (.dae) file. But I can't find any documentation on how to access these animations directly. I tried using the fox game example, but it only loads one of the animations.

Here's my code:

let modelNode = self.addModel_DAE_return(x: 0, y: 0, z: 0, scaleFactor: 0.0005, fileName: "models.scnassets/export_014/export_014_model.dae")

// add the animation to the model

let modelAnim = self.loadAnim_DAE(fileName: "models.scnassets/export_014/export_014_anim.dae")
                modelNode.addAnimationPlayer(modelAnim, forKey: "headMove")

modelAnim.play()

// add the model to the scene
node.addChildNode(modelNode)

How can I access and load in the other animations?

Context:

I'm making an AR app. I'm using the Apple Image Recognition example as a base.

Here's a link to it: https://developer.apple.com/documentation/arkit/recognizing_images_in_an_ar_experience

I animated a skeleton in Maya and exported the animation to a COLLADA (.DAE) file using the OpenCollada extension for Maya.

I exported separate files for the model and the animation, because if I export them as a single file, none of my animations export and xcode crashes every time I try to access the file to check if it registers any animations.

I want to access the "Entities" of my animation file so I can just loop over, load and attach the animations, but I can't

also I have looked into GameKit kind of but, is there not a way to do this with SceneKit?

1

1 Answers

0
votes

Each joint in the rig has animation information Originally I was only getting the information the first joint that had animations on it and not its children that also had animations attached

i.e. lets say your rig hierarchy is hips > rightShoulder > arm > elbow > wrist

and your animations were on the shoulder, arm, elbow, and wrist joints

you do not have any animations on your hip joint

using enumerateChildNodes will only grab the information from the shoulder joint

using enumerateHierarchy will grab all the animation information from the shoulder, the elbow, AND the wrist joint

see below for my function that I used: note that I had separately loaded and saved my 3D model onto an SCNNode and that was passed in so I could attach the animations to it

func loadAttachAnim_DAE(fileName: String, modelNode: SCNNode){
        let scene = SCNScene(named: fileName)!

        //find top level animation
        var animationPlayer: SCNAnimationPlayer! = nil


        scene.rootNode.enumerateHierarchy{ (child, stop)  in
            if !child.animationKeys.isEmpty {
                print ("child = \(child) -----------------")
                animationPlayer = child.animationPlayer(forKey: child.animationKeys[0])

                modelNode.addAnimationPlayer(animationPlayer, forKey: "\(child)")
                animationPlayer.play()

            }
        }
    }