首先,来源。它假定您的骨骼动画对象称为“立方体”。
import bpy
o = bpy.data.objects['Cube']
frame_start = bpy.context.scene.frame_start
frame_end = bpy.context.scene.frame_end
for i in range(frame_start, frame_end):
bpy.context.scene.frame_set(i)
bpy.context.scene.update()
m = o.to_mesh(bpy.context.scene, True, 'PREVIEW')
print("Frame %d:" % i)
for v in m.vertices:
print(" (%f %f %f)" % (v.co.x, v.co.y, v.co.z))
print("\n")
然后我们将遍历每一行。我们首先导入 Blender Python 模块。
import bpy
我们检索要导出其顶点的对象。
o = bpy.data.objects['Cube']
我们检索动画的开始和结束帧;这两个值显示在屏幕底部,默认为“开始:1”和“结束:250”。
frame_start = bpy.context.scene.frame_start
frame_end = bpy.context.scene.frame_end
然后我们遍历第一帧和最后一帧之间的每一帧。
for i in range(frame_start, frame_end):
我们设置当前帧;请注意,看似等效的调用 (*bpy.ops.anim.change_frame(frame = i)* 将 not 正常工作。如果有人对此有解释,请随时分享:-)) .
bpy.context.scene.frame_set(i)
update 的调用似乎没有必要,但最好有它,因为它会强制所有更新依赖于帧位置(即动画)。
bpy.context.scene.update()
我们将对象转换为网格,根据其预览设置应用所有修改器(包括骨架)。
m = o.to_mesh(bpy.context.scene, True, 'PREVIEW')
我们打印当前帧号。
print("Frame %d:" % i)
我们打印该帧的所有顶点,每行一个。
for v in m.vertices:
print(" (%f %f %f)" % (v.co.x, v.co.y, v.co.z))
我们用换行符分隔不同帧的顶点。
print("\n")