一,来源。它假定你的骨骼动画对象被称为“立方体”。
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']
我们检索动画的开始和结束帧;这两个值是显示在屏幕底部的值,默认为“Start:1”和“End: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)*将而不是正常工作。如果任何人有解释它,我请随时分享:-))。
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")