我试图加载在Cheetah 3D和Blender 3D中创建的动画到场景工具包中,但我得到的都是一堆“未命名动画”,每个动画都是相同的动画。
有谁知道如何正确地从Blender或Cheetah 3D导出这些文件,以便Scene Kit可以使用它们?
发布于 2014-07-24 11:35:18
我深入研究了这一点,因为它也让我恼火。所有的“无标题动画”都是每个骨骼的单独动画。您可以从xcode右侧面板中的属性检查器中获取id。像这样使用swift,你可以得到你的动画。
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对于骨架中的所有骨骼,必须执行此操作。**烦人!*
苹果在他们的所有示例项目中都使用了3dmax,每个collada文件只显示一个动画。这是因为3dmax导出一个动画下的所有骨骼,而混合器分离每个骨骼。
xml解决问题,使用TextEdit或在.xml文件末尾附加一个xml扩展名,然后使用.dae编辑器打开它(很多都是在线免费的)。xml编辑器更易于使用。向下滚动到动画开始块。看起来是这样的..。
<library_animations>
<animation id= "first_bone">
<source id= "first_bone-input"> 将其更改为...
<library_animations>
<animation> ---this is the only modified line
<source id="first_bone-input"> 在每个动画的末尾将是一个结束块,如下所示...
</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"> 当然,在最后一块骨骼的末尾,让动画结束块像这样…
</animation>
</library_animations>这将在您的.dae文件中为您提供一个动画,该动画与您的文件具有相同的名称,并在末尾附加-1!
编辑-这里有一个指向自动化服务的链接,它将为您转换上面的代码!
Automater collada converter download
解压缩该文件并将其放入~/Library/services文件夹中。从那里你可以右击你的collada文件,然后向下滚动到ConvertToXcodeCollada和presto!完成后将弹出一个窗口(大约半秒)。
发布于 2017-10-09 00:48:29
这是因为.dae文件中的每个骨骼都有自己的<animation>标记。
FlippinFun正确地指出,删除除第一个和最后一个之外的所有开始和结束<animation>标记将把动画分组在一起,使其可以在Xcode中通过标识符FileName-1进行访问。
我碰巧使用了MayaLT > .FBX > .DAE工作流程,发现他链接的服务对我不起作用。这是因为我的.dae文件格式不佳,一些<source>标记与双重嵌套的<animation>标记位于同一行。结果,整行代码被删除,损坏了.dae文件。
对于使用此工作流的其他人,这里是我正在运行的sed命令来清理,希望它对某些人有帮助!
sed -i .bak -e 's/\(.*\)<animation id.*><animation>\(.*\)/\1\2/g; s/\(.*\)<\/animation><\/animation>\(.*\)/\1\2/g; s/\(.*\)<library_animations>\(.*\)/\1<library_animations><animation>\2/g; s/\(.*\)<\/library_animations>\(.*\)/\1<\/animation><\/library_animations>\2/g' Walk.dae发布于 2018-06-12 11:10:23
如果其他人觉得它有用,我写了一个python脚本,它就是这样做的。提供一个文件路径数组,脚本将把动画组合成一个动画,移除几何体,并移除材质。
这个新的、更纤细的dae可以用作scenekit动画,只要您要将动画应用到的模型的骨骼被命名并完全匹配(正如它们应该的那样)。
#!/usr/local/bin/python
# Jonathan Cardasis, 2018
#
# Cleans up a collada `dae` file removing all unnessasary data
# only leaving animations and bone structures behind.
# Combines multiple animation sequences into a single animation
# sequence for Xcode to use.
import sys
import os
import re
import subprocess
def print_usage(app_name):
print 'Usage:'
print ' {} [path(s) to collada file(s)...]'.format(app_name)
print ''
def xml_is_collada(xml_string):
return bool(re.search('(<COLLADA).*(>)', xml_string))
################
## MAIN ##
################
DAE_TAGS_TO_STRIP = ['library_geometries', 'library_materials', 'library_images']
if len(sys.argv) < 2:
app_name = os.path.basename(sys.argv[0])
print_usage(app_name)
sys.exit(1)
print 'Stripping collada files of non-animation essential features...'
failed_file_conversions = 0
for file_path in sys.argv[1:]:
try:
print 'Stripping {} ...'.format(file_path)
dae_filename = os.path.basename(file_path)
renamed_dae_path = file_path + '.old'
dae = open(file_path, 'r')
xml_string = dae.read().strip()
dae.close()
# Ensure is a collada file
if not xml_is_collada(xml_string):
raise Exception('Not a proper Collada file.')
# Strip tags
for tag in DAE_TAGS_TO_STRIP:
xml_string = re.sub('(?:<{tag}>)([\s\S]+?)(?:</{tag}>)'.format(tag=tag), '', xml_string)
# Combine animation keys into single key:
# 1. Remove all <animation> tags.
# 2. Add leading and trailing <library_animation> tags with single <animation> tag between.
xml_string = re.sub(r'\s*(<animation[^>]*>)\s*', '\n', xml_string)
xml_string = re.sub(r'\s*(<\/animation\s*>.*)\s*', '', xml_string)
xml_string = re.sub(r'\s*(<library_animations>)\s*', '<library_animations>\n<animation>\n', xml_string)
xml_string = re.sub(r'\s*(<\/library_animations>)\s*', '\n</animation>\n</library_animations>', xml_string)
# Rename original and dump xml to previous file location
os.rename(file_path, renamed_dae_path)
with open(file_path, 'w') as new_dae:
new_dae.write(xml_string)
print 'Finished processing {}. Old file can be found at {}.\n'.format(file_path, renamed_dae_path)
except Exception as e:
print '[!] Failed to correctly parse {}: {}'.format(file_path, e)
failed_file_conversions += 1
if failed_file_conversions > 0:
print '\nFailed {} conversion(s).'.format(failed_file_conversions)
sys.exit(1)用法:python cleanupForXcodeColladaAnimation.py dancing_anim.dae
https://gist.github.com/joncardasis/e815ec69f81ed767389aa7a878f3deb6
https://stackoverflow.com/questions/24539607
复制相似问题