Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy, math
- from mathutils import Vector
- identifiers = ['L', 'R']
- armature = bpy.context.active_object
- new_constraints = []
- bpy.ops.object.mode_set(mode='EDIT')
- for b in armature.data.edit_bones:
- if b.name[0] in identifiers and '.' not in b.name:
- b.name = b.name[1:] + '.' + b.name[0]
- if 'Foot.' in b.name:
- # prep parent with slight bend
- b.parent.tail -= Vector((0, 0, 3))
- # create new IK bone
- ikb = armature.data.edit_bones.new('Foot_IK.' + b.name[-1])
- ikb.head = b.head
- ikb.tail = ikb.head - Vector((0, 18, 0))
- # and target
- ikt = armature.data.edit_bones.new('Foot_IK_Target.' + b.name[-1])
- ikt.head = b.parent.head + Vector((0, 0, 20))
- ikt.tail = ikt.head + Vector((0, 0, 10))
- # setup constraint
- ikc = armature.pose.bones[b.parent.name].constraints.new('IK')
- ikc.target = armature
- ikc.subtarget = ikb.name
- ikc.pole_target = armature
- ikc.pole_subtarget = ikt.name
- ikc.pole_angle = -math.pi / 2
- ikc.chain_count = 2
- new_constraints.append(ikc)
- elif 'Hand.' in b.name:
- # prep parent with slight bend
- b.parent.head -= Vector((0, 0, 2))
- # create new IK bone
- ikb = armature.data.edit_bones.new('Hand_IK.' + b.name[-1])
- ikb.head = b.head
- ikb.tail = ikb.head - Vector((0, 18, 0))
- # and target
- ikt = armature.data.edit_bones.new('Hand_IK_Target.' + b.name[-1])
- ikt.head = b.parent.head - Vector((0, 0, 20))
- ikt.tail = ikt.head - Vector((0, 0, 10))
- # setup constraint
- ikc = armature.pose.bones[b.parent.name].constraints.new('IK')
- ikc.target = armature
- ikc.subtarget = ikb.name
- ikc.pole_target = armature
- ikc.pole_subtarget = ikt.name
- ikc.pole_angle = -math.pi / 2
- ikc.chain_count = 2
- new_constraints.append(ikc)
- bpy.ops.object.mode_set(mode='POSE')
- # hack to force constraint data to refresh
- for nc in new_constraints:
- nc.iterations = nc.iterations
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement