我正在尝试将在Cheetah 3D和Blender 3D中创建的动画加载到Scene Kit中,但是我得到的只是一堆“未命名动画”,每个动画都是相同的。
有人知道如何正确地从Blender或Cheetah 3D导出这些动画,以便Scene Kit可以使用吗?
我正在尝试将在Cheetah 3D和Blender 3D中创建的动画加载到Scene Kit中,但是我得到的只是一堆“未命名动画”,每个动画都是相同的。
有人知道如何正确地从Blender或Cheetah 3D导出这些动画,以便Scene Kit可以使用吗?
问题: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