What space is this matrix in?

The Blender 2.6 API uses PoseBone to animate bones. PoseBone.matrix is ​​one way to do this. The API says that PoseBone.matrix is ​​in the "object space".

http://www.blender.org/documentation/blender_python_api_2_63_5/bpy.types.PoseBone.html#bpy.types.PoseBone.matrix

PoseBone.matrix did not see anything. I still can't get my importer to work. What is the deal with PoseBone.matrix? There were two matrices in the Blender 2.4 API: one in local space, one in anchor space.

But the new PoseBone.matrix is ​​neither one nor the other! This is not a local matrix:

enter image description here

The position is not local, it is global.

But the rotation enter image description here

<Euler (x=1.5708, y=-0.7854, z=-0.0000), order='XYZ'> 

there is.

So, what is this “object space” that the API says PoseBone.matrix is ​​in?

- , .

, , , , "PoseBone.matrix". .

oldmatrix = myMatrix
loc, rot, scale = oldmatrix.decompose()

#rot = rot * pose.bones[bonename].parent.rotation_quaternion.conjugated()
for i in pose.bones[bonename].parent_recursive:
   rot = rot * i.conjugated()

newmatrix = rot.to_matrix().to_4x4()

newmatrix[0][3] = loc.x
newmatrix[1][3] = loc.y
newmatrix[2][3] = loc.z

pose.bones[bonename].matrix = newmatrix 
+5
2

: , Object Space Bone Local Space.

- , :

    poseBone = C.object.pose.bones[2]  # <----- set your bone here

    # poseBone.matrix is in object space - we need to convert it to local space 
    if poseBone.parent is not None:
        parentRefPoseMtx = poseBone.parent.bone.matrix_local
        boneRefPoseMtx = poseBone.bone.matrix_local
        parentPoseMtx = poseBone.parent.matrix
        bonePoseMtx = poseBone.matrix

        boneLocMtx = ( parentRefPoseMtx.inverted() * boneRefPoseMtx ).inverted() * ( parentPoseMtx.inverted() * bonePoseMtx )

    else:
        boneRefPoseMtx = poseBone.bone.matrix_local
        bonePoseMtx = poseBone.matrix

        boneLocMtx = boneRefPoseMtx.inverted() * bonePoseMtx

    loc, rot, scale = boneLocMtx.decompose()

:

? .

, , :

boneOS = parentOS * boneLS

, , . . , , , -, , , , , , , .

( , 1 , 0 , 0 ):

boneOS = C.object.pose.bones[2].matrix
parentBoneOS = C.object.pose.bones[2].parent.matrix

boneRP = C.object.pose.bones[2].bone.matrix_local  # rest pose matrix in bone local space
parentBoneRP = C.object.pose.bones[1].bone.matrix_local  # parent bone rest pose matrix in bone local space

boneLS = ( parentBoneRP * boneRP ).inverted() * parentOS.inverted() * boneOS
+1

, . , , .

bpy.context.scene.update()
0

All Articles