5

I want to play and pause an animation in FBX format. I couldn't find a way to make that work, so I first convert the fbx files to dae (COLLADA) format, which can be imported for use in SceneKit.

I am loading the dae file like this, and adding it to an ARAnchor that has been detected by ARKit (I don't think it's relevant that I am loading it in an AR app).

func createNode() -> SCNNode {
    let node = SCNNode()

    // Instantiate the file
    let scene = SCNScene(named: file)!

    // Steal all their children
    scene.rootNode.childNodes.forEach { node.addChildNode($0) }

    // Scale the node
    node.scale = SCNVector3(scale, scale, scale)

    return node
}

Now the animation that is contained in the original fbx file plays, which is nice. Now I want to pause it, and eventually play only selected frames of the animation (to show the animation in different steps, when the user clicks a button).

I have noticed that there are 3 animationKeys, which are contained in different childNodes of the node I instantiate:

  • BBCharacter01AA_BoneLPlatform-Matrix-animation-transform
  • BBCharacter01AA_BoneRPlatform-Matrix-animation-transform
  • unnamed animation #2

I think the unnamed one is the general one, so I tried deleting that one, by using this on the child node that has the animation:

node.removeAnimation(forKey: "unnamed animation #2", blendOutDuration: 0)

When that didn't work, I tried deleting all animations I could find with animationKeys, but the model still animates.

I have also tried instantiating the animation separately and adding it by using a CAAnimationGroup, which has a duration of 0. I read that adding an animation with the same key should overwrite it, but that didn't seem to stop the animation either.

I truly am at a loss here, I have no idea what to try next.

Edit: I have tried the removeAllAnimations method on the SCNNode I instantiate. But that doesn't work either.

I have tried sceneView.scene.isPaused = true, and that finally works! I'm trying to jerryrig a way that uses the time when the model was added and the duration it was paused to try to align the updates to isPaused on the animation.

vrwim
  • 9,459
  • 11
  • 57
  • 107
  • Hey, am trying out a similar kind of approach. Pause and play works fine for me as well, but mine is to play the animation from a specific time interval. Say, my animation has a total time interval of 45 seconds. I tap on the model and should be able to I play it from the 15th second. Coud you please help me out if you think by any means this is possible? @vrwim – The X-Coder Jul 06 '19 at 08:42

0 Answers0