SceneKit – Animation with DAE file format

2019-02-15 08:46发布

I'm trying to animate my model on a SceneKit scene:

  1. create a simple cube model and export it to cube.dae
  2. create a simple skeleton for cube and make a simple rotation animation using bones and export it to animation.dae
  3. using Apple sample Fox demo (WWDC 2015), I tried to put model on scene and it works
  4. 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

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-02-15 09:10

It was my mistake, I need to save rig in initial model. Previously I saved rig only for animation. Now animation works fine.

查看更多
登录 后发表回答