9

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];
user623396
  • 1,537
  • 1
  • 17
  • 39
  • 1
    Before you convert your DAE file, look under Entities -> Animations. If it shows more then one animation key[0] will only be a portion of the animation. You may even see your object twitch or slightly move in one spot if this is the case. I have a file for download that converts all of the animation keys into one. This must me done before converting to SCN file. – FlippinFun Oct 25 '16 at 15:24

1 Answers1

2

This is a file that will convert mulitple key animations into one for DAE file

Automater collada converter download

Unzip and drop the file in your ~/Library/services folder. From there you can just right click on your collada file and scroll down to ConvertToXcodeCollada and presto! A window will pop up when complete (about half a second).

FlippinFun
  • 1,124
  • 10
  • 9
  • 1
    The workflow dosen't work anymore. The generated file is corrupted everytime. Does anyone know how to fix it? – hablema Feb 05 '18 at 08:09