I'm trying to animate my model on a SceneKit scene:
- create a simple cube model and export it to
cube.dae
- create a simple skeleton for cube and make a simple rotation animation using bones and export it to animation.dae
- using Apple sample Fox demo (WWDC 2015), I tried to put model on scene and it works
- animate box rotation – it is working but after applying animation, the cube changes its position to (0,0,0)
Maybe someone has succeeded with skeletal animation and SceneKit using another 3d tool (Maya, Blender, 3D Max)?
to convert .dae to .scn I select DAE file and then in Xcode "editor" --> "convert to scenekit scene format"
link to archive with models and animations.
code: init model node
let characterScene = SCNScene(named: "game.scnassets/cube.scn")!
let characterTopLevelNode = characterScene.rootNode.childNodes[0]
characterNode.addChildNode(characterTopLevelNode)
let idleAnimation = CAAnimation.animationWithSceneNamed("game.scnassets/cubeWithMeshSkeletonAnimation.scn")!
idleAnimation.usesSceneTimeBase = false
idleAnimation.repeatCount = Float.infinity
characterNode.addAnimation(idleAnimation, forKey: "idle")
add model on scene
let scene = SCNScene(named: "game.scnassets/Level1.scn")!
gameView.scene = scene
gameView.playing = true
gameView.loops = true
scene.rootNode.addChildNode(unrealCharacter.characterNode)
let startPosition = scene.rootNode.childNodeWithName("startingPoint", recursively: true)!
unrealCharacter.characterNode.transform = startPosition.transform
It was my mistake, I need to save rig in initial model. Previously I saved rig only for animation. Now animation works fine.