def align_bone_z_axis(obj, bone, vec):
""" Rolls the bone to align its z-axis as closely as possible to
the given vector.
Must be in edit mode.
"""
bone_e = obj.data.edit_bones[bone]
vec = bone_e.y_axis.cross(vec)
vec.normalize()
dot = max(-1.0, min(1.0, bone_e.x_axis.dot(vec)))
angle = math.acos(dot)
bone_e.roll += angle
dot1 = bone_e.x_axis.dot(vec)
bone_e.roll -= angle * 2
dot2 = bone_e.x_axis.dot(vec)
if dot1 > dot2:
bone_e.roll += angle * 2
评论列表
文章目录