How to create an animation in Maya that works in SceneKit or ARKit
Please note that the following methodology is for iOS 11.4 and Swift 4.1.
Download an AR camera starter project here.
Part One: Make an animated model in Maya.
I would recommend following this tutorial to learn how to make animations.
However, when exporting the file — make sure to export it as a .dae.
Part Two: Add the animated model to your SceneKit/ARkit project
Add the .dae to your art.scnassets as follows:
Add this code to the ViewController. This code will open your scene, grab the model, add it to the scene and grab the animation and add it to the model.
let scn:SCNScene? = SCNScene(named: "art.scnassets/YOUR_EXPORTED_DAE.dae");print("SCENE : ", scn!);let sceneNode:SCNNode = scn!.rootNode.childNode(withName: IDENTITY_OF_YOUR_MODEL_IN_THE_INSPECTOR, recursively: false)!;scn?.rootNode.enumerateHierarchy({ (child, _) infor key in child.animationKeys {let animation = child.animationPlayer(forKey: key)?.animation;animation?.repeatCount = CGFloat(HUGE);animation?.isRemovedOnCompletion = false;sceneNode.addAnimation(animation!, forKey: key);print(animation!)}})
Please note that the IDENTITY_OF_YOUR_MODEL_IN_THE_INSPECTOR can be found in the .dae file in the Utilities Inspector as shown below:
Please note that in this example, the identity is pCube1
Cheers,
Oscar