[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26559] trunk/blender/release/scripts/ modules/rigify/mouth.py: Updates to mouth rig.

Nathan Vegdahl cessen at cessen.com
Tue Feb 2 18:57:12 CET 2010


Revision: 26559
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26559
Author:   cessen
Date:     2010-02-02 18:57:12 +0100 (Tue, 02 Feb 2010)

Log Message:
-----------
Updates to mouth rig.  Old method didn't work well in combination with shape keys.  This new method (effectively just weighting directly to the lip control bones) is much simpler, but also requires more manual weight painting to get it to look right.

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/rigify/mouth.py

Modified: trunk/blender/release/scripts/modules/rigify/mouth.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/mouth.py	2010-02-02 17:41:32 UTC (rev 26558)
+++ trunk/blender/release/scripts/modules/rigify/mouth.py	2010-02-02 17:57:12 UTC (rev 26559)
@@ -71,15 +71,17 @@
     driver_path = 'keys["' + name + '"].value'
     fcurve = None
     driver = None
+    new = False
     if obj.data.shape_keys.animation_data is not None:
         for driver_s in obj.data.shape_keys.animation_data.drivers:
             if driver_s.data_path == driver_path:
                 fcurve = driver_s
     if fcurve == None:
         fcurve = obj.data.shape_keys.keys[name].driver_add("value", 0)
-    fcurve.driver.type = 'AVERAGE'
+        fcurve.driver.type = 'AVERAGE'
+        new = True
 
-    return fcurve
+    return fcurve, new
 
 
 def metarig_template():
@@ -132,88 +134,42 @@
 
     meshes = options["mesh"].replace(" ", "").split(",")
 
-    # Upper lip MCH
-    lip1  = make_lip_stretch_bone(obj, "MCH-lip", definitions[3], definitions[2], 0.0)
-    lip2  = make_lip_stretch_bone(obj, "MCH-lip", definitions[4], definitions[3], 0.0)
-    lip22 = make_lip_stretch_bone(obj, "MCH-lip", definitions[5], definitions[4], 0.0)
-    lip33 = make_lip_stretch_bone(obj, "MCH-lip", definitions[3], definitions[4], 0.0)
-    lip3  = make_lip_stretch_bone(obj, "MCH-lip", definitions[4], definitions[5], 0.0)
-    lip4  = make_lip_stretch_bone(obj, "MCH-lip", definitions[5], definitions[6], 0.0)
+    # Lip DEF
+    lip1 = copy_bone_simple(obj.data, definitions[2], "DEF-" + base_names[definitions[2]]).name
+    lip2 = copy_bone_simple(obj.data, definitions[3], "DEF-" + base_names[definitions[3]]).name
+    lip3 = copy_bone_simple(obj.data, definitions[4], "DEF-" + base_names[definitions[4]]).name
+    lip4 = copy_bone_simple(obj.data, definitions[5], "DEF-" + base_names[definitions[5]]).name
+    lip5 = copy_bone_simple(obj.data, definitions[6], "DEF-" + base_names[definitions[6]]).name
+    lip6 = copy_bone_simple(obj.data, definitions[7], "DEF-" + base_names[definitions[7]]).name
+    lip7 = copy_bone_simple(obj.data, definitions[8], "DEF-" + base_names[definitions[8]]).name
+    lip8 = copy_bone_simple(obj.data, definitions[9], "DEF-" + base_names[definitions[9]]).name
 
-    eb[lip1].parent =  eb[definitions[3]]
-    eb[lip2].parent =  eb[definitions[4]]
-    eb[lip22].parent = eb[definitions[5]]
-    eb[lip33].parent = eb[definitions[3]]
-    eb[lip3].parent =  eb[definitions[4]]
-    eb[lip4].parent =  eb[definitions[5]]
+    # Mouth corner spread bones (for driving corrective shape keys)
+    spread_l_1 = copy_bone_simple(obj.data, definitions[6], "MCH-" + base_names[definitions[6]] + ".spread_1").name
+    spread_l_2 = copy_bone_simple(obj.data, definitions[6], "MCH-" + base_names[definitions[6]] + ".spread_2").name
+    eb[spread_l_1].tail = eb[definitions[5]].head
+    eb[spread_l_2].tail = eb[definitions[5]].head
+    eb[spread_l_1].roll = 0
+    eb[spread_l_2].roll = 0
+    eb[spread_l_1].connected = False
+    eb[spread_l_2].connected = False
+    eb[spread_l_1].parent = eb[definitions[6]]
+    eb[spread_l_2].parent = eb[definitions[6]]
 
-    eb[lip22].bbone_segments = 8
-    eb[lip33].bbone_segments = 8
+    spread_r_1 = copy_bone_simple(obj.data, definitions[2], "MCH-" + base_names[definitions[2]] + ".spread_1").name
+    spread_r_2 = copy_bone_simple(obj.data, definitions[2], "MCH-" + base_names[definitions[2]] + ".spread_2").name
+    eb[spread_r_1].tail = eb[definitions[3]].head
+    eb[spread_r_2].tail = eb[definitions[3]].head
+    eb[spread_r_1].roll = 0
+    eb[spread_r_2].roll = 0
+    eb[spread_r_1].connected = False
+    eb[spread_r_2].connected = False
+    eb[spread_r_1].parent = eb[definitions[2]]
+    eb[spread_r_2].parent = eb[definitions[2]]
 
-    # Lower lip MCH
-    lip5 =  make_lip_stretch_bone(obj, "MCH-lip", definitions[7], definitions[6], 0.0)
-    lip6 =  make_lip_stretch_bone(obj, "MCH-lip", definitions[8], definitions[7], 0.0)
-    lip66 = make_lip_stretch_bone(obj, "MCH-lip", definitions[9], definitions[8], 0.0)
-    lip77 = make_lip_stretch_bone(obj, "MCH-lip", definitions[7], definitions[8], 0.0)
-    lip7 =  make_lip_stretch_bone(obj, "MCH-lip", definitions[8], definitions[9], 0.0)
-    lip8 =  make_lip_stretch_bone(obj, "MCH-lip", definitions[9], definitions[2], 0.0)
 
-    eb[lip5].parent = eb[definitions[7]]
-    eb[lip6].parent = eb[definitions[8]]
-    eb[lip66].parent = eb[definitions[9]]
-    eb[lip77].parent = eb[definitions[7]]
-    eb[lip7].parent = eb[definitions[8]]
-    eb[lip8].parent = eb[definitions[9]]
 
-    eb[lip66].bbone_segments = 8
-    eb[lip77].bbone_segments = 8
-
-    # Upper lip DEF
-    dlip1 = copy_bone_simple(obj.data, lip1, "DEF-" + base_names[definitions[4]] + ".01.R", parent=True).name
-    dlip2 = copy_bone_simple(obj.data, lip2, "DEF-" + base_names[definitions[4]] + ".02.R", parent=True).name
-    dlip3 = copy_bone_simple(obj.data, lip3, "DEF-" + base_names[definitions[4]] + ".02.L", parent=True).name
-    dlip4 = copy_bone_simple(obj.data, lip4, "DEF-" + base_names[definitions[4]] + ".01.L", parent=True).name
-
-    eb[dlip1].parent  = eb[dlip2]
-    eb[dlip2].parent = eb[lip22]
-
-    eb[dlip4].parent  = eb[dlip3]
-    eb[dlip3].parent = eb[lip33]
-
-    eb[dlip1].connected  = True
-    eb[dlip2].connected = True
-    eb[dlip4].connected  = True
-    eb[dlip3].connected = True
-
-    eb[dlip1].bbone_segments = 8
-    eb[dlip2].bbone_segments = 8
-    eb[dlip3].bbone_segments = 8
-    eb[dlip4].bbone_segments = 8
-
-    # Lower lip DEF
-    dlip8 = copy_bone_simple(obj.data, lip8, "DEF-" + base_names[definitions[8]] + ".01.R", parent=True).name
-    dlip7 = copy_bone_simple(obj.data, lip7, "DEF-" + base_names[definitions[8]] + ".02.R", parent=True).name
-    dlip6 = copy_bone_simple(obj.data, lip6, "DEF-" + base_names[definitions[8]] + ".02.L", parent=True).name
-    dlip5 = copy_bone_simple(obj.data, lip5, "DEF-" + base_names[definitions[8]] + ".01.L", parent=True).name
-
-
-    eb[dlip5].parent = eb[dlip6]
-    eb[dlip6].parent = eb[lip66]
-
-    eb[dlip8].parent = eb[dlip7]
-    eb[dlip7].parent = eb[lip77]
-
-    eb[dlip5].connected = True
-    eb[dlip6].connected = True
-    eb[dlip8].connected = True
-    eb[dlip7].connected = True
-
-    eb[dlip5].bbone_segments = 8
-    eb[dlip6].bbone_segments = 8
-    eb[dlip7].bbone_segments = 8
-    eb[dlip8].bbone_segments = 8
-
-    # Jaw open bones
+    # Jaw open bones (for driving corrective shape keys)
     jopen1 = copy_bone_simple(obj.data, jaw, "MCH-"+base_names[jaw]+".track1", parent=True).name
     eb[jopen1].connected = False
     eb[jopen1].head = eb[jaw].tail
@@ -225,45 +181,71 @@
 
     bpy.ops.object.mode_set(mode='OBJECT')
 
-    # Constraints
-    con = pb[dlip1].constraints.new('COPY_TRANSFORMS')
+    # Constrain DEF bones to ORG bones
+    con = pb[lip1].constraints.new('COPY_TRANSFORMS')
     con.target = obj
-    con.subtarget = lip1
+    con.subtarget = definitions[2]
 
-    con = pb[dlip2].constraints.new('COPY_TRANSFORMS')
+    con = pb[lip2].constraints.new('COPY_TRANSFORMS')
     con.target = obj
-    con.subtarget = lip2
+    con.subtarget = definitions[3]
 
-    con = pb[dlip3].constraints.new('COPY_TRANSFORMS')
+    con = pb[lip3].constraints.new('COPY_TRANSFORMS')
     con.target = obj
-    con.subtarget = lip3
+    con.subtarget = definitions[4]
 
-    con = pb[dlip4].constraints.new('COPY_TRANSFORMS')
+    con = pb[lip4].constraints.new('COPY_TRANSFORMS')
     con.target = obj
+    con.subtarget = definitions[5]
+    
+    con = pb[lip5].constraints.new('COPY_TRANSFORMS')
+    con.target = obj
+    con.subtarget = definitions[6]
+    
+    con = pb[lip6].constraints.new('COPY_TRANSFORMS')
+    con.target = obj
+    con.subtarget = definitions[7]
+    
+    con = pb[lip7].constraints.new('COPY_TRANSFORMS')
+    con.target = obj
+    con.subtarget = definitions[8]
+    
+    con = pb[lip8].constraints.new('COPY_TRANSFORMS')
+    con.target = obj
+    con.subtarget = definitions[9]
+    
+    # Constraint mouth corner spread bones
+    con = pb[spread_l_1].constraints.new('DAMPED_TRACK')
+    con.target = obj
     con.subtarget = lip4
 
-    con = pb[dlip5].constraints.new('COPY_TRANSFORMS')
+    con = pb[spread_l_2].constraints.new('COPY_TRANSFORMS')
     con.target = obj
-    con.subtarget = lip5
+    con.subtarget = spread_l_1
 
-    con = pb[dlip6].constraints.new('COPY_TRANSFORMS')
+    con = pb[spread_l_2].constraints.new('DAMPED_TRACK')
     con.target = obj
     con.subtarget = lip6
 
-    con = pb[dlip7].constraints.new('COPY_TRANSFORMS')
+    con = pb[spread_r_1].constraints.new('DAMPED_TRACK')
     con.target = obj
-    con.subtarget = lip7
+    con.subtarget = lip2
 
-    con = pb[dlip8].constraints.new('COPY_TRANSFORMS')
+    con = pb[spread_r_2].constraints.new('COPY_TRANSFORMS')
     con.target = obj
+    con.subtarget = spread_r_1
+    
+    con = pb[spread_r_2].constraints.new('DAMPED_TRACK')
+    con.target = obj
     con.subtarget = lip8
 
+    
     # Corrective shape keys for the corners of the mouth.
     bpy.ops.object.mode_set(mode='EDIT')
 
     # Calculate the rotation difference between the bones
-    rotdiff_r = acos(eb[lip1].matrix.to_quat() * eb[lip8].matrix.to_quat()) * 2
-    rotdiff_l = acos(eb[lip4].matrix.to_quat() * eb[lip5].matrix.to_quat()) * 2
+    rotdiff_l = acos((eb[lip5].head - eb[lip4].head).normalize().dot((eb[lip5].head - eb[lip6].head).normalize()))
+    rotdiff_r = acos((eb[lip1].head - eb[lip2].head).normalize().dot((eb[lip1].head - eb[lip8].head).normalize()))
 
     bpy.ops.object.mode_set(mode='OBJECT')
 
@@ -271,13 +253,13 @@
     # Left side shape key
     for mesh_name in meshes:
         mesh_obj = bpy.data.objects[mesh_name]
-        shape_key_name = "COR-" + base_names[definitions[4]] + ".L.spread"
+        shape_key_name = "COR-" + base_names[definitions[6]] + ".spread"
 
         # Add/get the shape key
         shape_key = addget_shape_key(mesh_obj, name=shape_key_name)
 
         # Add/get the shape key driver
-        fcurve = addget_shape_key_driver(mesh_obj, name=shape_key_name)
+        fcurve, is_new_driver = addget_shape_key_driver(mesh_obj, name=shape_key_name)
         driver = fcurve.driver
 
         # Get the variable, or create it if it doesn't already exist
@@ -291,26 +273,27 @@
         # Set up the variable

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list