- deform types for copy, arm and leg, patch from Cessen (with slighy modifications)
- bone.center attribute
This commit is contained in:
@@ -96,6 +96,11 @@ class _GenericBone:
|
||||
|
||||
return parent_list
|
||||
|
||||
@property
|
||||
def center(self):
|
||||
"""The midpoint between the head and the tail."""
|
||||
return (self.head + self.tail) * 0.5
|
||||
|
||||
@property
|
||||
def length(self):
|
||||
"""The distance from head to tail, when set the head is moved to fit the length."""
|
||||
|
||||
@@ -283,9 +283,91 @@ def fk(obj, definitions, base_names, options):
|
||||
return None, fk_chain.arm, fk_chain.forearm, fk_chain.hand
|
||||
|
||||
|
||||
def deform(obj, definitions, base_names, options):
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
|
||||
# Create upper arm bones: two bones, each half of the upper arm.
|
||||
uarm1 = copy_bone_simple(obj.data, definitions[1], "DEF-%s.01" % base_names[definitions[1]], parent=True)
|
||||
uarm2 = copy_bone_simple(obj.data, definitions[1], "DEF-%s.02" % base_names[definitions[1]], parent=True)
|
||||
uarm1.connected = False
|
||||
uarm2.connected = False
|
||||
uarm2.parent = uarm1
|
||||
center = uarm1.center
|
||||
uarm1.tail = center
|
||||
uarm2.head = center
|
||||
|
||||
# Create forearm bones: two bones, each half of the forearm.
|
||||
farm1 = copy_bone_simple(obj.data, definitions[2], "DEF-%s.01" % base_names[definitions[2]], parent=True)
|
||||
farm2 = copy_bone_simple(obj.data, definitions[2], "DEF-%s.02" % base_names[definitions[2]], parent=True)
|
||||
farm1.connected = False
|
||||
farm2.connected = False
|
||||
farm2.parent = farm1
|
||||
center = farm1.center
|
||||
farm1.tail = center
|
||||
farm2.head = center
|
||||
|
||||
# Create hand bone
|
||||
hand = copy_bone_simple(obj.data, definitions[3], "DEF-%s" % base_names[definitions[3]], parent=True)
|
||||
|
||||
# Store names before leaving edit mode
|
||||
uarm1_name = uarm1.name
|
||||
uarm2_name = uarm2.name
|
||||
farm1_name = farm1.name
|
||||
farm2_name = farm2.name
|
||||
hand_name = hand.name
|
||||
|
||||
# Leave edit mode
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
|
||||
# Get the pose bones
|
||||
uarm1 = obj.pose.bones[uarm1_name]
|
||||
uarm2 = obj.pose.bones[uarm2_name]
|
||||
farm1 = obj.pose.bones[farm1_name]
|
||||
farm2 = obj.pose.bones[farm2_name]
|
||||
hand = obj.pose.bones[hand_name]
|
||||
|
||||
# Upper arm constraints
|
||||
con = uarm1.constraints.new('DAMPED_TRACK')
|
||||
con.name = "trackto"
|
||||
con.target = obj
|
||||
con.subtarget = definitions[2]
|
||||
|
||||
con = uarm2.constraints.new('COPY_ROTATION')
|
||||
con.name = "copy_rot"
|
||||
con.target = obj
|
||||
con.subtarget = definitions[1]
|
||||
|
||||
# Forearm constraints
|
||||
con = farm1.constraints.new('COPY_ROTATION')
|
||||
con.name = "copy_rot"
|
||||
con.target = obj
|
||||
con.subtarget = definitions[2]
|
||||
|
||||
con = farm2.constraints.new('COPY_ROTATION')
|
||||
con.name = "copy_rot"
|
||||
con.target = obj
|
||||
con.subtarget = definitions[3]
|
||||
|
||||
con = farm2.constraints.new('DAMPED_TRACK')
|
||||
con.name = "trackto"
|
||||
con.target = obj
|
||||
con.subtarget = definitions[3]
|
||||
|
||||
# Hand constraint
|
||||
con = hand.constraints.new('COPY_ROTATION')
|
||||
con.name = "copy_rot"
|
||||
con.target = obj
|
||||
con.subtarget = definitions[3]
|
||||
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
return (uarm1_name, uarm2_name, farm1_name, farm2_name, hand_name)
|
||||
|
||||
|
||||
def main(obj, bone_definition, base_names, options):
|
||||
bones_fk = fk(obj, bone_definition, base_names, options)
|
||||
bones_ik = ik(obj, bone_definition, base_names, options)
|
||||
bones_deform = deform(obj, bone_definition, base_names, options)
|
||||
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
blend_bone_list(obj, bone_definition, bones_fk, bones_ik, target_bone=bones_fk[1], blend_default=1.0)
|
||||
blend_bone_list(obj, bone_definition, bones_fk, bones_ik, target_bone=bones_ik[3], target_prop="ik", blend_default=0.0)
|
||||
|
||||
|
||||
@@ -42,7 +42,42 @@ def metarig_template():
|
||||
|
||||
|
||||
def metarig_definition(obj, orig_bone_name):
|
||||
return [orig_bone_name]
|
||||
return (orig_bone_name,)
|
||||
|
||||
|
||||
def deform(obj, definitions, base_names, options):
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
|
||||
# Create deform bone.
|
||||
bone = copy_bone_simple(obj.data, definitions[0], "DEF-%s" % base_names[definitions[0]], parent=True)
|
||||
|
||||
# Store name before leaving edit mode
|
||||
bone_name = bone.name
|
||||
|
||||
# Leave edit mode
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
|
||||
# Get the pose bone
|
||||
bone = obj.pose.bones[bone_name]
|
||||
|
||||
# Constrain to the original bone
|
||||
# XXX. Todo, is this needed if the bone is connected to its parent?
|
||||
con = bone.constraints.new('COPY_LOCATION')
|
||||
con.name = "copy_loc"
|
||||
con.target = obj
|
||||
con.subtarget = definitions[0]
|
||||
|
||||
con = bone.constraints.new('COPY_ROTATION')
|
||||
con.name = "copy_rot"
|
||||
con.target = obj
|
||||
con.subtarget = definitions[0]
|
||||
|
||||
con = bone.constraints.new('COPY_SCALE')
|
||||
con.name = "copy_scale"
|
||||
con.target = obj
|
||||
con.subtarget = definitions[0]
|
||||
|
||||
return (bone_name,)
|
||||
|
||||
|
||||
def main(obj, bone_definition, base_names, options):
|
||||
@@ -80,8 +115,12 @@ def main(obj, bone_definition, base_names, options):
|
||||
cp.cpy_p.lock_rotation_w = mt.cpy_p.lock_rotation_w
|
||||
cp.cpy_p.lock_scale = tuple(mt.cpy_p.lock_scale)
|
||||
|
||||
# Create deform bone
|
||||
deform_bone = deform(obj, bone_definition, base_names, options)[0]
|
||||
|
||||
# setup layers last
|
||||
layers = get_layer_dict(options)
|
||||
cp.cpy_b.layer = layers["main"]
|
||||
|
||||
return [mt.cpy]
|
||||
return (mt.cpy,)
|
||||
|
||||
|
||||
@@ -271,7 +271,8 @@ def ik(obj, bone_definition, base_names, options):
|
||||
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
|
||||
return None, ik_chain.thigh, ik_chain.shin, ik_chain.foot, ik_chain.toe, None
|
||||
#return ((None, ik_chain.thigh, ik_chain.shin, ik_chain.foot, ik_chain.toe, None), (ik.foot, ik.knee_target)) # Cessen ???
|
||||
return (None, ik_chain.thigh, ik_chain.shin, ik_chain.foot, ik_chain.toe, None)
|
||||
|
||||
|
||||
def fk(obj, bone_definition, base_names, options):
|
||||
@@ -366,9 +367,109 @@ def fk(obj, bone_definition, base_names, options):
|
||||
return None, fk_chain.thigh, fk_chain.shin, fk_chain.foot, fk_chain.toe, None
|
||||
|
||||
|
||||
def deform(obj, definitions, base_names, options):
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
|
||||
# Create upper leg bones: two bones, each half of the upper leg.
|
||||
uleg1 = copy_bone_simple(obj.data, definitions[1], "DEF-%s.01" % base_names[definitions[1]], parent=True)
|
||||
uleg2 = copy_bone_simple(obj.data, definitions[1], "DEF-%s.02" % base_names[definitions[1]], parent=True)
|
||||
uleg1.connected = False
|
||||
uleg2.connected = False
|
||||
uleg2.parent = uleg1
|
||||
center = uleg1.center
|
||||
uleg1.tail = center
|
||||
uleg2.head = center
|
||||
|
||||
# Create lower leg bones: two bones, each half of the lower leg.
|
||||
lleg1 = copy_bone_simple(obj.data, definitions[2], "DEF-%s.01" % base_names[definitions[2]], parent=True)
|
||||
lleg2 = copy_bone_simple(obj.data, definitions[2], "DEF-%s.02" % base_names[definitions[2]], parent=True)
|
||||
lleg1.connected = False
|
||||
lleg2.connected = False
|
||||
lleg2.parent = lleg1
|
||||
center = lleg1.center
|
||||
lleg1.tail = center
|
||||
lleg2.head = center
|
||||
|
||||
# Create a bone for the second lower leg deform bone to twist with
|
||||
twist = copy_bone_simple(obj.data, lleg2.name, "MCH-leg_twist")
|
||||
twist.length /= 4
|
||||
twist.connected = False
|
||||
twist.parent = obj.data.edit_bones[definitions[3]]
|
||||
|
||||
# Create foot bone
|
||||
foot = copy_bone_simple(obj.data, definitions[3], "DEF-%s" % base_names[definitions[3]], parent=True)
|
||||
|
||||
# Create toe bone
|
||||
toe = copy_bone_simple(obj.data, definitions[4], "DEF-%s" % base_names[definitions[4]], parent=True)
|
||||
|
||||
# Store names before leaving edit mode
|
||||
uleg1_name = uleg1.name
|
||||
uleg2_name = uleg2.name
|
||||
lleg1_name = lleg1.name
|
||||
lleg2_name = lleg2.name
|
||||
twist_name = twist.name
|
||||
foot_name = foot.name
|
||||
toe_name = toe.name
|
||||
|
||||
# Leave edit mode
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
|
||||
# Get the pose bones
|
||||
uleg1 = obj.pose.bones[uleg1_name]
|
||||
uleg2 = obj.pose.bones[uleg2_name]
|
||||
lleg1 = obj.pose.bones[lleg1_name]
|
||||
lleg2 = obj.pose.bones[lleg2_name]
|
||||
foot = obj.pose.bones[foot_name]
|
||||
toe = obj.pose.bones[toe_name]
|
||||
|
||||
# Upper leg constraints
|
||||
con = uleg1.constraints.new('DAMPED_TRACK')
|
||||
con.name = "trackto"
|
||||
con.target = obj
|
||||
con.subtarget = definitions[2]
|
||||
|
||||
con = uleg2.constraints.new('COPY_ROTATION')
|
||||
con.name = "copy_rot"
|
||||
con.target = obj
|
||||
con.subtarget = definitions[1]
|
||||
|
||||
# Lower leg constraints
|
||||
con = lleg1.constraints.new('COPY_ROTATION')
|
||||
con.name = "copy_rot"
|
||||
con.target = obj
|
||||
con.subtarget = definitions[2]
|
||||
|
||||
con = lleg2.constraints.new('COPY_ROTATION')
|
||||
con.name = "copy_rot"
|
||||
con.target = obj
|
||||
con.subtarget = twist_name
|
||||
|
||||
con = lleg2.constraints.new('DAMPED_TRACK')
|
||||
con.name = "trackto"
|
||||
con.target = obj
|
||||
con.subtarget = definitions[3]
|
||||
|
||||
# Foot constraint
|
||||
con = foot.constraints.new('COPY_ROTATION')
|
||||
con.name = "copy_rot"
|
||||
con.target = obj
|
||||
con.subtarget = definitions[3]
|
||||
|
||||
# Toe constraint
|
||||
con = toe.constraints.new('COPY_ROTATION')
|
||||
con.name = "copy_rot"
|
||||
con.target = obj
|
||||
con.subtarget = definitions[4]
|
||||
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
return (uleg1_name, uleg2_name, lleg1_name, lleg2_name, foot_name, toe_name)
|
||||
|
||||
|
||||
def main(obj, bone_definition, base_names, options):
|
||||
bones_fk = fk(obj, bone_definition, base_names, options)
|
||||
bones_ik = ik(obj, bone_definition, base_names, options)
|
||||
deform(obj, bone_definition, base_names, options)
|
||||
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
blend_bone_list(obj, bone_definition, bones_fk, bones_ik, target_bone=bones_ik[1], blend_default=0.0)
|
||||
#blend_bone_list(obj, bone_definition, bones_fk, bones_ik[0], target_bone=bones_ik[1][0], target_prop="ik", blend_default=0.0) # Cessen ???
|
||||
blend_bone_list(obj, bone_definition, bones_fk, bones_ik, target_prop="ik", blend_default=0.0)
|
||||
|
||||
Reference in New Issue
Block a user