[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26116] trunk/blender/release/scripts/ modules: Rigify:

Nathan Vegdahl cessen at cessen.com
Tue Jan 19 20:07:11 CET 2010


Revision: 26116
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26116
Author:   cessen
Date:     2010-01-19 20:07:09 +0100 (Tue, 19 Jan 2010)

Log Message:
-----------
Rigify:
- Added two driven-shape-key rig types that create and drive shape keys on a mesh/meshes based on the distance or rotation difference between two bones.
- Fixed bug in finger curl rig type where secondary finger controls were not created.  Finger type can also now (optionally) have a hinge switch (useful when using it for wings).
- Changed the blending system in rigify_utils to use copy_transforms constraints instead of copy_loc+copy_rot.
- Finished the quadruped leg type.  Now has both ik and fk control and ik/fk switching.  Also uses a rotating bone to control the knee direction instead of a pole target (seems to work more consistently for quadruped setups).  There's still one annoying bug regarding foot roll, but it's not blocking.  I'll track it down later.
- Mouth rig now creates corrective shape keys on the face mesh for dealing with mouth corners when they spread open.
- Biped arm and leg types now cause mesh to scale when you scale the fk controls.
- Misc improvements to the rig types.

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/rigify/arm_biped.py
    trunk/blender/release/scripts/modules/rigify/finger_curl.py
    trunk/blender/release/scripts/modules/rigify/leg_biped.py
    trunk/blender/release/scripts/modules/rigify/leg_quadruped.py
    trunk/blender/release/scripts/modules/rigify/mouth.py
    trunk/blender/release/scripts/modules/rigify/neck_flex.py
    trunk/blender/release/scripts/modules/rigify/palm_curl.py
    trunk/blender/release/scripts/modules/rigify/spine_pivot_flex.py
    trunk/blender/release/scripts/modules/rigify_utils.py

Added Paths:
-----------
    trunk/blender/release/scripts/modules/rigify/shape_key_distance.py
    trunk/blender/release/scripts/modules/rigify/shape_key_rotdiff.py

Modified: trunk/blender/release/scripts/modules/rigify/arm_biped.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/arm_biped.py	2010-01-19 18:52:45 UTC (rev 26115)
+++ trunk/blender/release/scripts/modules/rigify/arm_biped.py	2010-01-19 19:07:09 UTC (rev 26116)
@@ -223,6 +223,7 @@
     fk_chain.forearm_p.rotation_mode = 'XYZ'
     fk_chain.forearm_p.lock_rotation = (False, True, True)
     fk_chain.hand_p.rotation_mode = 'ZXY'
+    fk_chain.arm_p.lock_location = True, True, True
 
     con = fk_chain.arm_p.constraints.new('COPY_LOCATION')
     con.target = obj
@@ -276,8 +277,15 @@
     fk_chain.arm_b.layer     = layer
     fk_chain.forearm_b.layer = layer
     fk_chain.hand_b.layer    = layer
-
+    
+    # Forearm was getting wrong roll somehow.  Hack to fix that.
     bpy.ops.object.mode_set(mode='EDIT')
+    fk_chain.update()
+    mt.update()
+    fk_chain.forearm_e.roll = mt.forearm_e.roll
+    bpy.ops.object.mode_set(mode='OBJECT')
+    
+    bpy.ops.object.mode_set(mode='EDIT')
     return None, fk_chain.arm, fk_chain.forearm, fk_chain.hand
 
 
@@ -338,6 +346,11 @@
     con.target = obj
     con.subtarget = definitions[2]
     
+    con = uarm1.constraints.new('COPY_SCALE')
+    con.name = "trackto"
+    con.target = obj
+    con.subtarget = definitions[1]
+    
     con = uarm2.constraints.new('COPY_ROTATION')
     con.name = "copy_rot"
     con.target = obj
@@ -349,6 +362,11 @@
     con.target = obj
     con.subtarget = definitions[2]
     
+    con = farm1.constraints.new('COPY_SCALE')
+    con.name = "copy_rot"
+    con.target = obj
+    con.subtarget = definitions[2]
+    
     con = farm2.constraints.new('COPY_ROTATION')
     con.name = "copy_rot"
     con.target = obj

Modified: trunk/blender/release/scripts/modules/rigify/finger_curl.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/finger_curl.py	2010-01-19 18:52:45 UTC (rev 26115)
+++ trunk/blender/release/scripts/modules/rigify/finger_curl.py	2010-01-19 19:07:09 UTC (rev 26116)
@@ -150,103 +150,171 @@
 
 def main(obj, bone_definition, base_names, options):
     # *** EDITMODE
-
+    bpy.ops.object.mode_set(mode='EDIT')
+    
     # get assosiated data
     arm = obj.data
-    orig_ebone = arm.edit_bones[bone_definition[0]]
+    bb = obj.data.bones
+    eb = obj.data.edit_bones
+    pb = obj.pose.bones
+    
+    org_f1 = bone_definition[0] # Original finger bone 01
+    org_f2 = bone_definition[1] # Original finger bone 02
+    org_f3 = bone_definition[2] # Original finger bone 03
+    
+    # Check options
+    if "bend_ratio" in options:
+        bend_ratio = options["bend_ratio"]
+    else:
+        bend_ratio = 0.4
+    
+    yes = [1, 1.0, True, "True", "true", "Yes", "yes"]
+    make_hinge = False
+    if ("hinge" in options) and (eb[org_f1].parent is not None):
+        if options["hinge"] in yes:
+            make_hinge = True
 
-    obj.animation_data_create() # needed if its a new armature with no keys
+    
+    # Needed if its a new armature with no keys
+    obj.animation_data_create() 
 
-    children = orig_ebone.children_recursive
-    tot_len = reduce(lambda f, ebone: f + ebone.length, children, orig_ebone.length)
-
-    # FIXME, the line below is far too arbitrary
-    base_name = base_names[bone_definition[0]].rsplit(".", 2)[0]
-
-    # first make a new bone at the location of the finger
-    #control_ebone = arm.edit_bones.new(base_name)
-    control_ebone = copy_bone_simple(arm, bone_definition[0], base_name + get_side_name(base_names[bone_definition[0]]), parent=True)
-    control_bone_name = control_ebone.name # we dont know if we get the name requested
-
-    control_ebone.connected = orig_ebone.connected
-    control_ebone.parent = orig_ebone.parent
-    control_ebone.length = tot_len
-
-    # now add bones inbetween this and its children recursively
-
-    # switching modes so store names only!
-    children = [ebone.name for ebone in children]
-
-    driver_bone_pairs = []
-
-    for child_bone_name in children:
-        child_ebone = arm.edit_bones[child_bone_name]
-
-        # finger.02 --> finger_driver.02
-        driver_bone_name = child_bone_name.split('.')
-        driver_bone_name = driver_bone_name[0] + "_driver." + ".".join(driver_bone_name[1:])
-
-        driver_ebone = copy_bone_simple(arm, child_ebone.name, driver_bone_name)
-        driver_ebone.length *= 0.5
-
-        # Insert driver_ebone in the chain without connected parents
-        driver_ebone.connected = False
-        driver_ebone.parent = child_ebone.parent
-
-        child_ebone.connected = False
-        child_ebone.parent = driver_ebone
-
-        # Add the drivers to these when in posemode.
-        driver_bone_pairs.append((child_bone_name, driver_bone_name))
-
-    del control_ebone
-
+    # Create the control bone
+    base_name = base_names[bone_definition[0]].split(".", 1)[0]
+    tot_len = eb[org_f1].length + eb[org_f2].length + eb[org_f3].length
+    control = copy_bone_simple(arm, bone_definition[0], base_name + get_side_name(base_names[bone_definition[0]]), parent=True).name
+    eb[control].connected = eb[org_f1].connected
+    eb[control].parent = eb[org_f1].parent
+    eb[control].length = tot_len
+    
+    # Create secondary control bones
+    f1 = copy_bone_simple(arm, bone_definition[0], base_names[bone_definition[0]]).name
+    f2 = copy_bone_simple(arm, bone_definition[1], base_names[bone_definition[1]]).name
+    f3 = copy_bone_simple(arm, bone_definition[2], base_names[bone_definition[2]]).name
+    
+    # Create driver bones
+    df1 = copy_bone_simple(arm, bone_definition[0], "MCH-" + base_names[bone_definition[0]]).name
+    eb[df1].length /= 2
+    df2 = copy_bone_simple(arm, bone_definition[1], "MCH-" + base_names[bone_definition[1]]).name
+    eb[df2].length /= 2
+    df3 = copy_bone_simple(arm, bone_definition[2], "MCH-" + base_names[bone_definition[2]]).name
+    eb[df3].length /= 2
+    
+    # Set parents of the bones, interleaving the driver bones with the secondary control bones
+    eb[f3].connected = False
+    eb[df3].connected = False
+    eb[f2].connected = False
+    eb[df2].connected = False
+    eb[f1].connected = False
+    eb[df1].connected = eb[org_f1].connected
+    
+    eb[f3].parent = eb[df3]
+    eb[df3].parent = eb[f2]
+    eb[f2].parent = eb[df2]
+    eb[df2].parent = eb[f1]
+    eb[f1].parent = eb[df1]
+    eb[df1].parent = eb[org_f1].parent
+    
+    # Set up bones for hinge
+    if make_hinge:
+        socket = copy_bone_simple(arm, org_f1, "MCH-socket_"+control, parent=True).name
+        hinge = copy_bone_simple(arm, eb[org_f1].parent.name, "MCH-hinge_"+control).name
+        
+        eb[control].connected = False
+        eb[control].parent = eb[hinge]
+    
+    # Create the deform rig while we're still in edit mode
     deform(obj, bone_definition, base_names, options)
-
+    
+    
     # *** POSEMODE
     bpy.ops.object.mode_set(mode='OBJECT')
-
-
-    orig_pbone = obj.pose.bones[bone_definition[0]]
-    control_pbone = obj.pose.bones[control_bone_name]
-    control_bbone = arm.bones[control_bone_name]
-    control_pbone.rotation_mode = obj.pose.bones[bone_definition[0]].rotation_mode
-
-
-    # only allow Y scale
-    control_pbone.lock_scale = (True, False, True)
-
-    control_pbone["bend_ratio"] = 0.4
-    prop = rna_idprop_ui_prop_get(control_pbone, "bend_ratio", create=True)
+    
+    # Set rotation modes and axis locks
+    pb[control].rotation_mode = obj.pose.bones[bone_definition[0]].rotation_mode
+    pb[control].lock_location = True, True, True
+    pb[control].lock_scale = True, False, True
+    pb[f1].rotation_mode = 'YZX'
+    pb[f2].rotation_mode = 'YZX'
+    pb[f3].rotation_mode = 'YZX'
+    pb[f1].lock_location = True, True, True
+    pb[f2].lock_location = True, True, True
+    pb[f3].lock_location = True, True, True
+    pb[df2].rotation_mode = 'YZX'
+    pb[df3].rotation_mode = 'YZX'
+    
+    # Add the bend_ratio property to the control bone
+    pb[control]["bend_ratio"] = bend_ratio
+    prop = rna_idprop_ui_prop_get(pb[control], "bend_ratio", create=True)
     prop["soft_min"] = 0.0
     prop["soft_max"] = 1.0
-
-    con = orig_pbone.constraints.new('COPY_LOCATION')
+    
+    # Add hinge property to the control bone
+    if make_hinge:
+        pb[control]["hinge"] = 0.0
+        prop = rna_idprop_ui_prop_get(pb[control], "hinge", create=True)
+        prop["soft_min"] = 0.0
+        prop["soft_max"] = 1.0
+    
+    # Constraints
+    con = pb[df1].constraints.new('COPY_LOCATION')
     con.target = obj
-    con.subtarget = control_bone_name
+    con.subtarget = control
 
-    con = orig_pbone.constraints.new('COPY_ROTATION')
+    con = pb[df1].constraints.new('COPY_ROTATION')
     con.target = obj
-    con.subtarget = control_bone_name
+    con.subtarget = control
+    
+    con = pb[org_f1].constraints.new('COPY_TRANSFORMS')
+    con.target = obj
+    con.subtarget = f1
+    
+    con = pb[org_f2].constraints.new('COPY_TRANSFORMS')
+    con.target = obj
+    con.subtarget = f2
+    
+    con = pb[org_f3].constraints.new('COPY_TRANSFORMS')
+    con.target = obj
+    con.subtarget = f3
+    
+    if make_hinge:
+        con = pb[hinge].constraints.new('COPY_TRANSFORMS')
+        con.target = obj
+        con.subtarget = bb[org_f1].parent.name
+        
+        hinge_driver_path = pb[control].path_to_id() + '["hinge"]'
 
+        fcurve = con.driver_add("influence", 0)
+        driver = fcurve.driver
+        var = driver.variables.new()
+        driver.type = 'AVERAGE'
+        var.name = "var"
+        var.targets[0].id_type = 'OBJECT'
+        var.targets[0].id = obj
+        var.targets[0].data_path = hinge_driver_path
 
+        mod = fcurve.modifiers[0]
+        mod.poly_order = 1
+        mod.coefficients[0] = 1.0
+        mod.coefficients[1] = -1.0
+    
+        con = pb[control].constraints.new('COPY_LOCATION')
+        con.target = obj
+        con.subtarget = socket
+    
+    # Create the drivers for the driver bones (control bone scale rotates driver bones)
+    controller_path = pb[control].path_to_id() # 'pose.bones["%s"]' % control_bone_name
 
-    # setup child drivers on each new smaller bone added. assume 2 for now.
-
-    # drives the bones
-    controller_path = control_pbone.path_to_id() # 'pose.bones["%s"]' % control_bone_name
-
     i = 0
-    for child_bone_name, driver_bone_name in driver_bone_pairs:

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list