I am making a homegrown 3d engine for my projects. So far, I am able to export:
- Node hierarchy
Each node in my engine has it own mesh(optional), material(optional) and a PARENT-RELATIVE-TRANSFORMATION-MATRIX
While rendering, each node passes its own matrix down to each children. This matrix get multiplied with the child node's transformation matrix and gets passed down further.
This is working fine for static meshes with node hierarchy. However it is not working for Blender bones(I have a plugin for 3ds max also, and my engine is able to render bones correctly. So I think the issue is not on renderer side.)
I am getting all weird matrices for bone animations. Here is my script where I save the animation data for bones.
for node in nodes: if node.pose_bone: (start_frame, end_frame) = (0, 100) animation = Animation(len(animations), int(start_frame), int(end_frame)) animations.append(animation) node.animationIndex = animation.index print("==>>") for f in range(int(start_frame), int(end_frame) + 1): bpy.context.scene.frame_set(f) bpy.context.scene.update() if node.pose_bone.parent is None: bone_matrix = node.pose_bone.matrix_basis else: parent_matrix = node.pose_bone.parent.matrix_basis bone_matrix = node.pose_bone.matrix_basis bone_matrix = parent_matrix.inverted() * bone_matrix m = bone_matrix animation.translates.append( m.to_translation() ) animation.rotates.append( m.to_quaternion() ) animation.scales.append( m.to_scale() )
Please help me to get correct pose matrices for bones. In my engine these need to be relative to their parent.