Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
848 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...