如何在不显示“untitled-animations”的情况下导出DAE文件以供在Scene Kit中使用?

16

我正在尝试将在Cheetah 3D和Blender 3D中创建的动画加载到Scene Kit中,但是我得到的只是一堆“未命名动画”,每个动画都是相同的。

有人知道如何正确地从Blender或Cheetah 3D导出这些动画,以便Scene Kit可以使用吗?


如果您重新表述问题,例如,“如何使Blender导出DAE以便在SceneKit中使用,使(功能X)执行(操作Y)?”则可能会获得更好的结果。 - rickster
谢谢Rick。还差3个字符。哈哈! - user160632
1
我重新修改了标题和正文,使其更加关注您的问题,因此我重新打开了它。 - Brad Larson
这个回答解决了你的问题吗?如何在SceneKit中使用普通的Mixamo角色动画? - Fattie
绝对完整的2023解决方案:https://dev59.com/78Xsa4cB1Zd3GeqPsbUh#75093081 - Fattie
11个回答

0

问题:DAE文件中有太多的<animation></animation>标签

当您将DAE文件作为XML或文本文件打开时,您应该会看到许多<animation id="..." name="..."></animation>对,但您只需要一个对来在Xcode中使用它。

解决方案:从DAE文件中删除除一对之外的所有标签

因此,您需要删除除一个之外的所有标签。虽然您可以手动完成,但使用Python脚本更容易。以下是我编写的解决方案。

import re

input_file = open("/file/path/to/input/.dae", "r")
output_file = open("/file/path/to/output/.dae", "w")

# Scan the file to count the number of <animation>

count = 0
lines = []

for line in input_file.readlines():
    if re.search("^\s+<animation.*?>", line):
        count += 1
    lines.append(line)

# Delete all <animation> tags except the first one, 
# and delete all </animation> tags except the last one.

count_start = 0
count_end = 0

for line in lines:
    result = re.findall("^\s+<animation.*?>", line)
    if len(result) > 0:
        count_start += 1
        # Check if the <animation> tag is the first one
        if count_start == 1:
            line = re.sub("^\s+<animation.*?>", "<animation>", line)
            output_file.write(line)
            continue
        line = re.sub("^\s+<animation.*?>", "", line)
    result = re.findall("</animation>", line)
    if len(result) > 0:
        count_end += 1
        # Check if the </animation> tag is the last one
        if count_end == count:
            output_file.write(line)
            continue
        line = re.sub("</animation>", "", line)
    output_file.write(line)  

您可以通过输入以下命令在终端中运行代码。当您运行脚本时,请确保更改脚本中的输入和输出文件路径。

python3 script.py

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接