Pose bone matrix?

I’m trying to import Blender animations to my own game engine.
Since I’m facing some troubles I decided to skin a mesh “manually” inside Blender through the python API as a test, but I can’t even get that to work.

What’s wrong here ?

for vertex in duplicate.data.vertices:
    new_position = mathutils.Vector((0,0,0))
    for group in vertex.groups:
        group_name = duplicate.vertex_groups[group.group].name
        bone = armature.pose.bones[group_name]
        new_position += (bone.matrix.copy() @ vertex.co.copy()) * group.weight
    vertex.co = new_position

The matrix used must contain the transformation from the rest pose to the deformed pose.

1 Like

I thought that PoseBone.matrix was already the delta.
The matrix I was looking for is

pose_bone.matrix.copy() @ pose_bone.bone.matrix_local.inverted()

Thank you for your help @brecht.