I've imported a DAE file in XCode and converted it into a SCN file. This file contains some 3D objects with animations.
I'm trying to import all the nodes with their animations and play them on the scene. The nodes are imported but I can't get the animations playing.
NSURL *idleURL = [[NSBundle mainBundle] URLForResource:model.model3D
withExtension:@"scn" subdirectory:@"3d.scnassets"];
SCNScene *idleScene = [SCNScene sceneWithURL:idleURL
options:@{
SCNSceneSourceAnimationImportPolicyKey:SCNSceneSourceAnimationImportPolicyPlayRepeatedly}
error:nil];
// Merge the loaded scene into our main scene in order to
// place the object in our own scene
for (SCNNode *child in idleScene.rootNode.childNodes){
[_sceneView.scene.rootNode addChildNode:child];
if (child.animationKeys.count > 0) {
CAAnimation *animation = [child animationForKey:child.animationKeys[0]];
animation.repeatCount = INFINITY;
child.paused = NO;
[_sceneView.scene.rootNode addAnimation:animation forKey:child.animationKeys[0]];
}
}
[_sceneView setPlaying:YES];