Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- target = bpy.data.objects['Target']
- source = bpy.data.objects['Source']
- for pb in source.pose.bones:
- pb.rotation_mode = 'YXZ'
- for pb in target.pose.bones:
- pb.rotation_mode = 'YXZ'
- sourceroll = {}
- bpy.ops.object.select_all(action='DESELECT')
- source.select = True
- bpy.context.scene.objects.active = source
- bpy.ops.object.mode_set(mode='EDIT')
- bpy.ops.armature.select_all(action='SELECT')
- for b in source.data.edit_bones:
- sourceroll.update({b.name:b.roll})
- bpy.ops.object.mode_set(mode='OBJECT')
- bpy.ops.object.select_all(action='DESELECT')
- target.select = True
- bpy.context.scene.objects.active = target
- bpy.ops.object.mode_set(mode='EDIT')
- bpy.ops.armature.select_all(action='SELECT')
- for b in target.data.edit_bones:
- b.roll = sourceroll[b.name]
- bpy.ops.object.mode_set(mode='OBJECT')
- import bpy
- import math
- def align_bone_x_axis(edit_bone, new_x_axis):
- """ new_x_axis is a 3D Vector the edit_bone's x-axis will point towards.
- """
- new_x_axis = new_x_axis.cross(edit_bone.y_axis)
- new_x_axis.normalize()
- dot = max(-1.0, min(1.0, edit_bone.z_axis.dot(new_x_axis)))
- angle = math.acos(dot)
- edit_bone.roll += angle
- dot1 = edit_bone.z_axis.dot(new_x_axis)
- edit_bone.roll -= angle * 2.0
- dot2 = edit_bone.z_axis.dot(new_x_axis)
- if dot1 > dot2:
- edit_bone.roll += angle * 2.0
- source = bpy.data.objects['Source']
- target = bpy.data.objects['Target']
- source_to_world_matrix = source.matrix_world.to_3x3()
- world_to_target_matrix = target.matrix_world.inverted().to_3x3()
- source_roll = {}
- source_x_axis = {}
- bpy.ops.object.select_all(action='DESELECT')
- source.select = True
- bpy.context.scene.objects.active = source
- bpy.ops.object.mode_set(mode='EDIT')
- bpy.ops.armature.select_all(action='SELECT')
- for b in source.data.edit_bones:
- source_roll[b.name] = b.roll
- source_x_axis[b.name] = source_to_world_matrix * b.x_axis
- bpy.ops.object.mode_set(mode='OBJECT')
- bpy.ops.object.select_all(action='DESELECT')
- target.select = True
- bpy.context.scene.objects.active = target
- bpy.ops.object.mode_set(mode='EDIT')
- bpy.ops.armature.select_all(action='SELECT')
- for b in target.data.edit_bones:
- b.roll = source_roll[b.name]
- align_bone_x_axis(b, world_to_target_matrix * source_x_axis[b.name])
- bpy.ops.object.mode_set(mode='OBJECT')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement