0
votes

I made an animation in Blender and moved it to Xcode and it is converted from .dae file to .scn by Xcode.

I can play the animation in scene graph of Xcode as it is designed in the Blender.

I am loading geometry and animation and create node for animated object.

I use SCNAnimationPlayer() to load animation. The code is below.

let scene = SCNScene(named: "scene.scn")!
let geometry = scene.rootNode.childNode(withName: "animatedGeo",
                                              recursively:true).geometry!

let animationNode = SCNNode(geometry: geometry)


let armature = scene.rootNode.childNode(withName: "Armature", recursively: true)!
let animationPlayer = armature.animationPlayer(forKey: "action_container-Armature")!
animationNode.addAnimationPlayer(animationPlayer, forKey: "action_container-Armature")

rootNode.addChildNode(animationNode)

I did not set anything for animationPlayer programmatically because all the settings looks Ok in scene graph window of Xcode.

However when scene loaded I see a small movement on animated object on iPhone screen. Looks like only first (parent) bone animation is partly playing. I could not find the why all of animation was not playing as it is played in scene graph.

1

1 Answers

0
votes

Yes, I found how to do it when I was trying to manipulate my object designed and animated in Blender programmatically instead of animation I made in Blender.

What you have to do is to add "Armature" node to your scene node. This is all. You don't have to use SCNAnimationPlayer().

let scene = SCNScene(named: "scene.scn")!

let myObjectArmaturNode = scene.rootNode.childNode(withName: "Armature", recursively: true)!

rootNode.addChildNode(myObjectArmaturNode)

This is it. The animation runs like it is designed in Blender. The animation consists of 4 bones by the way.