How can I export DAE files for use in Scene Kit without seeing "untitled-animations"?

user160632 picture user160632 · Jul 2, 2014 · Viewed 15.9k times · Source

I am trying to load animations created in Cheetah 3D and Blender 3D into Scene Kit, but all I get is a bunch of "untitled-animations" with each one being the same animation.

Does anyone know how to properly export these from Blender or Cheetah 3D so that Scene Kit can use them?

Answer

FlippinFun picture FlippinFun · Jul 24, 2014

I dug into this because it was annoying me too. All of the "untitled animations" are individual animations for each bone. You can get the id from the attributes inspecter in the panel on the right side of xcode. Using swift like so, you can get your animation.

let urlOfScene = Bundle.main.url(forResources: "your url", withExtension: "dae")
let source = SCNSceneSource(url: urlOfScene, options: nil)
let armature = source.entryWithIdentifier("Armature", withClass: SCNNode.self) as SCNNode

let animation = armature.entryWithIdentifier("your bone id", withClass: CAAnimation.self) as CAAnimation

This must be done for All the bones in your armature. **Annoying!!!*

Apple used 3dmax for all their sample projects which only show one animation for each collada file. This is because 3dmax exports all the bones under one animation while blender seperates each bone.

Temp Work Around Use TextEdit or append a .xml extension on the end of your .dae file and open it with an xml editor (plenty are free online). xml editors are a little easier to work with. Scroll down to the animation start block. It will look like so...

<library_animations>
<animation id= "first_bone"> 
<source id= "first_bone-input"> 

Change it to...

<library_animations>
<animation>                      ---this is the only modified line
<source id="first_bone-input"> 

At the end of each animation will be an end block like so...

</animtion>                      ---delete this line as long as its not your last bone    
<animation id="second_bone">     ---delete this line too
<source id="second_bone-input">  

Of course at the end of your last bone leave the animation end block like so...

</animation>
</library_animations>

This will give you a single animation within your .dae file which has the same name as your file with a -1 appended to the end!

EDIT - Here is a link to an Automator service that will convert the above code for you!

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