Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import 3D object with animation from scn

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];
like image 858
user623396 Avatar asked Sep 09 '16 09:09

user623396


1 Answers

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).

like image 141
FlippinFun Avatar answered Oct 11 '22 17:10

FlippinFun