bpy.context.bone
为Blender中代表骨骼的上下文数据类型,可在Python脚本中使用。
OBJECT
,EDIT
,POSE
等。bpy.types.Object
,只读bpy.types.Bone
,只读bpy_prop_collection
,只读下面的示例演示了如何选择指定名称的骨骼,并旋转它的角度:
import bpy
# 获取场景中第一个selected的armature对象
armature = bpy.context.selected_objects[0]
# 获取armature的编辑模式
bpy.ops.object.mode_set(mode='EDIT')
# 获取名为“bone_name”的骨骼对象
bone = armature.data.edit_bones.get("bone_name")
# 将指定向量设为轴,将骨骼绕轴旋转60度
if bone:
axis = (1.0, 0, 0)
angle = 60.0
rot_mat = Matrix.Rotation(radians(angle), 4, axis)
bone.transform(rot_mat)
上面的示例创建了一个旋转矩阵rot_mat
,并使用骨骼的transform()
方法将其应用于该骨骼的变换矩阵中。注意,在编辑模式下,必须使用armature.data.edit_bones
获取骨骼对象。