在Blender Python中导出关键帧
我正在尝试从Blender导出动画,下面是我到目前为止所做的事情:
--- 这只是为了让你了解我在做什么,我省略了很多细节以保持简洁。
--- 如果这太让人困惑,或者需要更多信息,我可以把完整的源代码发出来。
# Get the armature
arm = ob.getData()
# Start at the root bone
for bone in bones:
if not bone.parent:
traceBone(bone)
def traceBone(bone):
# Get the channel for this bone
channel=action.getChannelIpo(bone.name);
# Get the loc x, y, z channels
c_locx=channel[Ipo.OB_LOCX].bezierPoints
frameCount=len(c_locx)
# Write each location frame
for frameIndex in range(frameCount):
frame_x=c_locx[frameIndex].pt
frameTime=int(frame_x[0]-1)
# Write the time of the frame
writeInt(frameTime)
# Write the x, y and z coordinates
writeFloats(frame_x[1], frame_z[1], frame_y[1])
# Iv'e done the same for rotation
c_quatx=channel[Ipo.PO_QUATX].bezierPoints
# Write the quaternion w, x, y and z values
writeFloats(frame_w[1], frame_x[1], frame_z[1], frame_y[1])
# Go through the children
for child in bone.children:
traceBone(child)
据我所知,这一切都运作得很好,问题在于这些值是偏移量,表示的是变化,但我需要的是绝对值,表示骨骼相对于其父级的位置和旋转值。
我该如何获取相对于父级的位置和旋转呢?
1 个回答
2
通道数据应该加在绑定姿势矩阵的基础上。
完整的公式如下:
Mr = Ms * B0*P0 * B1*P1 ... Bn*Pn
其中:
Mr = 骨骼 'n' 的结果矩阵
Ms = 骨架到世界的矩阵
Bi = 骨骼 'i' 的绑定姿势矩阵
Pi = 从存储的通道构建的实际姿势矩阵(你要导出的)
'n-1' 是 'n' 的父骨骼,'n-2' 是 'n-1' 的父骨骼,依此类推,'0' 是 '1' 的父骨骼。