NokiMo
cebstudios
cebstudios

patreon


DEV - Transfer angles from objects to bones

After days researching it, we've found a way to copy the angles from an object to bones.


Here is the code and the blend file is attached to this post

#This code was created to copy the angle between 2 points

#And transfer it to a Bone


import bpy,math
e1 = bpy.data.objects['Empty1'].location
e2 = bpy.data.objects['Empty2'].location
e3 = bpy.data.objects['Empty3'].location
#Euler Rotation Transfer
arm = bpy.context.scene.objects['Armature_Euler']
bone = arm.pose.bones['Bone']
rot_euler = e1.rotation_difference(e2-e1).to_euler()
bone.rotation_euler = rot_euler
print("X: %.2f, Y: %.2f, Z: %.2f" % tuple(math.degrees(a) for a in rot_euler))
#Quaternion Rotation Transfer
arm = bpy.context.scene.objects['Armature_Quaternion']
bone = arm.pose.bones['Bone']
rot_quaternion = e3.rotation_difference(e2-e3)
bone.rotation_quaternion = rot_quaternion
print("W: %.2f, X: %.2f, Y: %.2f, Z: %.2f" % tuple(math.degrees(a) for a in rot_quaternion))

DEV - Transfer angles from objects to bones

Related Creators