Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- from math import degrees
- def get_local_orientation(pose_bone):
- local_orientation = pose_bone.matrix_channel.to_euler()
- if pose_bone.parent is None:
- return (local_orientation.x, local_orientation.y, local_orientation.z)
- else:
- my_orientation = pose_bone.matrix_channel.copy()
- parent_orientation = pose_bone.parent.matrix_channel.copy()
- my_orientation.invert()
- orientation = (my_orientation * parent_orientation).to_euler()
- return (orientation.x, orientation.y, orientation.z)
- def get_joint_angles(context):
- arm = context.scene.objects['Armature']
- pose = arm.pose
- bones = pose.bones
- joint_names = ['Base','Shoulder','Elbow','Wrist1','Wrist2','Wrist3']
- axis_index = {
- 'Base': 2,
- 'Shoulder': 1,
- 'Elbow': 1,
- 'Wrist1': 1,
- 'Wrist2': 2,
- 'Wrist3': 1,
- }
- axis_correction = {
- 'Base': (1, 0),
- 'Shoulder': (-1, -math.pi/2),
- 'Elbow': (-1, 0),
- 'Wrist1': (-1, -math.pi/2),
- 'Wrist2': (-1, 0),
- 'Wrist3': (-1, 0),
- }
- joint_angles_by_name = {}
- for bone in bones:
- joint_angles_by_name[bone.name] = get_local_orientation(bone)
- joint_angles = []
- for name in joint_names:
- bl_angle = joint_angles_by_name[name][axis_index[name]]
- direction, offset = axis_correction[name]
- joint_angle = direction * bl_angle + offset
- joint_angles.append(joint_angle)
- return joint_angles
- class SimpleBoneAnglesPanel(bpy.types.Panel):
- bl_label = "Joint Angles"
- bl_space_type = 'VIEW_3D'
- bl_region_type = 'UI'
- def draw(self, context):
- joint_names = ['Base','Shoulder','Elbow','Wrist1','Wrist2','Wrist3']
- joint_angles = joint_angles(context)
- row = self.layout.row()
- row.label(text='test')
- #for z in range(len(joint_angles)):
- #row = self.layout.row()
- #row.label(text = joint_names[z] + ': {:.3}'.format(degrees(joint_angles[z])))
- bpy.utils.register_class(SimpleBoneAnglesPanel)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement