[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25366] trunk/blender/release: automatic layer placement, users can set the layers if they want.

Campbell Barton ideasman42 at gmail.com
Mon Dec 14 15:21:07 CET 2009


Revision: 25366
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25366
Author:   campbellbarton
Date:     2009-12-14 15:21:06 +0100 (Mon, 14 Dec 2009)

Log Message:
-----------
automatic layer placement, users can set the layers if they want.
predefined layer types 'main', 'extra', 'ik', 'fk'

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/rigify/__init__.py
    trunk/blender/release/scripts/modules/rigify/arm_biped_generic.py
    trunk/blender/release/scripts/modules/rigify/copy.py
    trunk/blender/release/scripts/modules/rigify/finger_curl.py
    trunk/blender/release/scripts/modules/rigify/leg_biped_generic.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/test/pep8.py

Modified: trunk/blender/release/scripts/modules/rigify/__init__.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/__init__.py	2009-12-14 14:16:39 UTC (rev 25365)
+++ trunk/blender/release/scripts/modules/rigify/__init__.py	2009-12-14 14:21:06 UTC (rev 25366)
@@ -24,6 +24,7 @@
 # TODO, have these in a more general module
 from rna_prop_ui import rna_idprop_ui_prop_get
 SPECIAL_TYPES = "root",
+LAYER_TYPES = "main", "extra", "ik", "fk"
 
 
 class RigifyError(Exception):
@@ -81,6 +82,22 @@
     return options
 
 
+def get_layer_dict(options):
+    '''
+    Extracts layer info from a bone options dict
+    defaulting to the layer index if not set.
+    '''
+    layer_default = [False] * 32
+    result = {}
+    for i, layer_type in enumerate(LAYER_TYPES):
+        # no matter if its not defined
+        layer_index = options.get("layer_" + layer_type, i + 2)
+        layer = layer_default[:]
+        layer[layer_index-1] = True
+        result[layer_type] = layer
+    return result
+
+
 def validate_rig(context, obj):
     '''
     Makes no changes

Modified: trunk/blender/release/scripts/modules/rigify/arm_biped_generic.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/arm_biped_generic.py	2009-12-14 14:16:39 UTC (rev 25365)
+++ trunk/blender/release/scripts/modules/rigify/arm_biped_generic.py	2009-12-14 14:21:06 UTC (rev 25366)
@@ -19,7 +19,7 @@
 # <pep8 compliant>
 
 import bpy
-from rigify import RigifyError
+from rigify import RigifyError, get_layer_dict
 from rigify_utils import bone_class_instance, copy_bone_simple, add_pole_target_bone, add_stretch_to, blend_bone_list, get_side_name, get_base_name
 from rna_prop_ui import rna_idprop_ui_prop_get
 from Mathutils import Vector
@@ -170,8 +170,17 @@
     prop["soft_min"] = 0.0
     prop["soft_max"] = 1.0
 
+
+    # last step setup layers
+    layers = get_layer_dict(options)
+    lay = layers["ik"]
+    for attr in ik_chain.attr_names:
+        getattr(ik_chain, attr + "_b").layer = lay
+    for attr in ik.attr_names:
+        getattr(ik, attr + "_b").layer = lay
+
+
     bpy.ops.object.mode_set(mode='EDIT')
-
     # don't blend the shoulder
     return [None] + ik_chain.names()
 
@@ -184,7 +193,7 @@
     mt.shoulder, mt.arm, mt.forearm, mt.hand = definitions
     mt.update()
 
-    ex = bone_class_instance(obj, ["socket", "arm_hinge", "hand_delta"])
+    ex = bone_class_instance(obj, ["socket", "hand_delta"])
     fk_chain = mt.copy(base_names=base_names)
 
     # shoulder is used as a hinge
@@ -263,8 +272,19 @@
 
     hinge_setup()
 
+
+    # last step setup layers
+    layers = get_layer_dict(options)
+    lay = layers["fk"]
+    for attr in fk_chain.attr_names:
+        getattr(fk_chain, attr + "_b").layer = lay
+
+    lay = layers["extra"]
+    for attr in ex.attr_names:
+        getattr(ex, attr + "_b").layer = lay
+
+
     bpy.ops.object.mode_set(mode='EDIT')
-
     return None, fk_chain.arm, fk_chain.forearm, fk_chain.hand
 
 

Modified: trunk/blender/release/scripts/modules/rigify/copy.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/copy.py	2009-12-14 14:16:39 UTC (rev 25365)
+++ trunk/blender/release/scripts/modules/rigify/copy.py	2009-12-14 14:21:06 UTC (rev 25366)
@@ -19,6 +19,7 @@
 # <pep8 compliant>
 
 import bpy
+from rigify import get_layer_dict
 from rigify_utils import bone_class_instance
 
 METARIG_NAMES = ("cpy",)
@@ -55,12 +56,17 @@
     cp.update()
     mt.update()
 
+    if not cp.cpy_b.connected:
+        con = cp.cpy_p.constraints.new('COPY_LOCATION')
+        con.target = obj
+        con.subtarget = mt.cpy
+
     con = cp.cpy_p.constraints.new('COPY_ROTATION')
     con.target = obj
     con.subtarget = mt.cpy
 
-    con = cp.cpy_p.constraints.new('COPY_LOCATION')
-    con.target = obj
-    con.subtarget = mt.cpy
+    # setup layers last
+    layers = get_layer_dict(options)
+    cp.cpy_b.layer = layers["main"]
 
     return [mt.cpy]

Modified: trunk/blender/release/scripts/modules/rigify/finger_curl.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/finger_curl.py	2009-12-14 14:16:39 UTC (rev 25365)
+++ trunk/blender/release/scripts/modules/rigify/finger_curl.py	2009-12-14 14:21:06 UTC (rev 25366)
@@ -19,7 +19,7 @@
 # <pep8 compliant>
 
 import bpy
-from rigify import RigifyError
+from rigify import RigifyError, get_layer_dict
 from rigify_utils import copy_bone_simple, get_side_name
 from rna_prop_ui import rna_idprop_ui_prop_get
 from functools import reduce
@@ -213,5 +213,15 @@
 
         i += 1
 
+
+    # last step setup layers
+    layers = get_layer_dict(options)
+    lay = layers["extra"]
+    for child_bone_name, driver_bone_name in driver_bone_pairs:
+        arm.bones[driver_bone_name].layer = lay
+
+    lay = layers["main"]
+    arm.bones[control_bone_name].layer = lay
+
     # no blending the result of this
     return None

Modified: trunk/blender/release/scripts/modules/rigify/leg_biped_generic.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/leg_biped_generic.py	2009-12-14 14:16:39 UTC (rev 25365)
+++ trunk/blender/release/scripts/modules/rigify/leg_biped_generic.py	2009-12-14 14:21:06 UTC (rev 25366)
@@ -19,7 +19,7 @@
 # <pep8 compliant>
 
 import bpy
-from rigify import RigifyError
+from rigify import RigifyError, get_layer_dict
 from rigify_utils import bone_class_instance, copy_bone_simple, blend_bone_list, get_side_name, get_base_name
 from rna_prop_ui import rna_idprop_ui_prop_get
 
@@ -131,8 +131,6 @@
     # setup the existing bones
     mt_chain = bone_class_instance(obj, ["thigh", "shin", "foot", "toe"])
     mt = bone_class_instance(obj, ["hips", "heel"])
-    #ex = bone_class_instance(obj, [""])
-    ex = bone_class_instance(obj, ["thigh_socket", "thigh_hinge", "foot_roll_1", "foot_roll_2", "foot_roll_3"])
     # children of ik_foot
     ik = bone_class_instance(obj, ["foot", "foot_roll", "foot_roll_01", "foot_roll_02", "knee_target"])
 
@@ -215,7 +213,6 @@
     bpy.ops.object.mode_set(mode='OBJECT')
 
     ik.update()
-    ex.update()
     mt_chain.update()
     ik_chain.update()
 
@@ -269,6 +266,15 @@
             con.minimum_x = -180.0 # XXX -deg
             con.maximum_x = 0.0
 
+
+    # last step setup layers
+    layers = get_layer_dict(options)
+    lay = layers["ik"]
+    for attr in ik_chain.attr_names:
+        getattr(ik_chain, attr + "_b").layer = lay
+    for attr in ik.attr_names:
+        getattr(ik, attr + "_b").layer = lay
+
     bpy.ops.object.mode_set(mode='EDIT')
 
     return None, ik_chain.thigh, ik_chain.shin, ik_chain.foot, ik_chain.toe, None
@@ -348,6 +354,19 @@
     mod.coefficients[0] = 1.0
     mod.coefficients[1] = -1.0
 
+
+
+    # last step setup layers
+    layers = get_layer_dict(options)
+    lay = layers["fk"]
+    for attr in fk_chain.attr_names:
+        getattr(fk_chain, attr + "_b").layer = lay
+
+    lay = layers["extra"]
+    for attr in ex.attr_names:
+        getattr(ex, attr + "_b").layer = lay
+
+
     bpy.ops.object.mode_set(mode='EDIT')
 
     # dont blend the hips or heel

Modified: trunk/blender/release/scripts/modules/rigify/neck_flex.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/neck_flex.py	2009-12-14 14:16:39 UTC (rev 25365)
+++ trunk/blender/release/scripts/modules/rigify/neck_flex.py	2009-12-14 14:21:06 UTC (rev 25366)
@@ -19,7 +19,7 @@
 # <pep8 compliant>
 
 import bpy
-from rigify import RigifyError
+from rigify import RigifyError, get_layer_dict
 from rigify_utils import bone_class_instance, copy_bone_simple
 from rna_prop_ui import rna_idprop_ui_prop_get
 
@@ -121,7 +121,7 @@
     neck_chain_basename = base_names[mt_chain.neck_01_e.name].split(".")[0]
     neck_chain_segment_length = mt_chain.neck_01_e.length
 
-    ex = bone_class_instance(obj, ["body", "head", "head_hinge", "neck_socket", "head_ctrl"]) # hinge & extras
+    ex = bone_class_instance(obj, ["head", "head_hinge", "neck_socket", "head_ctrl"]) # hinge & extras
 
     # Add the head hinge at the bodys location, becomes the parent of the original head
 
@@ -296,5 +296,15 @@
         con.target = obj
         con.subtarget = neck_p.name
 
+
+    # last step setup layers
+    layers = get_layer_dict(options)
+    lay = layers["extra"]
+    for attr in ex_chain.attr_names:
+        getattr(ex_chain, attr + "_b").layer = lay
+    for attr in ex.attr_names:
+        getattr(ex, attr + "_b").layer = lay
+
+
     # no blending the result of this
     return None

Modified: trunk/blender/release/scripts/modules/rigify/palm_curl.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/palm_curl.py	2009-12-14 14:16:39 UTC (rev 25365)
+++ trunk/blender/release/scripts/modules/rigify/palm_curl.py	2009-12-14 14:21:06 UTC (rev 25366)
@@ -19,6 +19,7 @@
 # <pep8 compliant>
 
 import bpy
+from rigify import get_layer_dict
 from rigify_utils import copy_bone_simple, get_side_name
 from rna_prop_ui import rna_idprop_ui_prop_get
 
@@ -232,5 +233,11 @@
     if x_direction(): # flip
         driver.expression = "-(%s)" % driver.expression
 
+
+    # last step setup layers
+    layers = get_layer_dict(options)
+    arm.bones[control_name].layer = layers["extra"]
+
+
     # no blending the result of this
     return None

Modified: trunk/blender/release/scripts/modules/rigify/spine_pivot_flex.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/spine_pivot_flex.py	2009-12-14 14:16:39 UTC (rev 25365)
+++ trunk/blender/release/scripts/modules/rigify/spine_pivot_flex.py	2009-12-14 14:21:06 UTC (rev 25366)
@@ -19,6 +19,7 @@
 # <pep8 compliant>
 
 import bpy
+from rigify import get_layer_dict
 from rigify_utils import bone_class_instance, copy_bone_simple
 from rna_prop_ui import rna_idprop_ui_prop_get
 
@@ -495,5 +496,20 @@
         mod.coefficients[0] = - (i - 1)
         mod.coefficients[1] = spine_chain_len
 
+
+    # last step setup layers
+    layers = get_layer_dict(options)
+    lay = layers["extra"]
+    for attr in ex.attr_names:
+        getattr(ex, attr + "_b").layer = lay
+    for attr in ex_chain.attr_names:
+        getattr(ex_chain, attr + "_b").layer = lay
+
+    lay = layers["main"]

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list