Python API Docs: add non-invert Bone.convert_local_to_pose example.

This updates the example function to support assigning a subset of
bone matrices. The code was tested to work in real use by @gaiaclary.
This commit is contained in:
2022-01-18 11:42:58 +03:00
parent 542d15b1cd
commit d7822981b1

View File

@@ -8,27 +8,42 @@ def set_pose_matrices(obj, matrix_map):
"Assign pose space matrices of all bones at once, ignoring constraints." "Assign pose space matrices of all bones at once, ignoring constraints."
def rec(pbone, parent_matrix): def rec(pbone, parent_matrix):
matrix = matrix_map[pbone.name] if pbone.name in matrix_map:
matrix = matrix_map[pbone.name]
## Instead of: ## Instead of:
# pbone.matrix = matrix # pbone.matrix = matrix
# bpy.context.view_layer.update() # bpy.context.view_layer.update()
# Compute and assign local matrix, using the new parent matrix # Compute and assign local matrix, using the new parent matrix
if pbone.parent: if pbone.parent:
pbone.matrix_basis = pbone.bone.convert_local_to_pose( pbone.matrix_basis = pbone.bone.convert_local_to_pose(
matrix, matrix,
pbone.bone.matrix_local, pbone.bone.matrix_local,
parent_matrix=parent_matrix, parent_matrix=parent_matrix,
parent_matrix_local=pbone.parent.bone.matrix_local, parent_matrix_local=pbone.parent.bone.matrix_local,
invert=True invert=True
) )
else:
pbone.matrix_basis = pbone.bone.convert_local_to_pose(
matrix,
pbone.bone.matrix_local,
invert=True
)
else: else:
pbone.matrix_basis = pbone.bone.convert_local_to_pose( # Compute the updated pose matrix from local and new parent matrix
matrix, if pbone.parent:
pbone.bone.matrix_local, matrix = pbone.bone.convert_local_to_pose(
invert=True pbone.matrix_basis,
) pbone.bone.matrix_local,
parent_matrix=parent_matrix,
parent_matrix_local=pbone.parent.bone.matrix_local,
)
else:
matrix = pbone.bone.convert_local_to_pose(
pbone.matrix_basis,
pbone.bone.matrix_local,
)
# Recursively process children, passing the new matrix through # Recursively process children, passing the new matrix through
for child in pbone.children: for child in pbone.children: