[Bf-extensions-cvs] [5b1b7b94] master: Rigify 0.5 general maintenance and bug fixing

Lucio Rossi noreply at git.blender.org
Thu Jun 1 15:24:43 CEST 2017


Commit: 5b1b7b94893a3a873b3d511d8859ab75301f31c6
Author: Lucio Rossi
Date:   Thu Jun 1 15:24:01 2017 +0200
Branches: master
https://developer.blender.org/rBA5b1b7b94893a3a873b3d511d8859ab75301f31c6

Rigify 0.5 general maintenance and bug fixing

===================================================================

M	rigify/generate.py
M	rigify/legacy/utils.py
M	rigify/metarigs/human.py
M	rigify/rigs/limbs/arm.py
M	rigify/rigs/limbs/leg.py
M	rigify/rigs/limbs/paw.py
M	rigify/rigs/limbs/rear_paw.py
M	rigify/rigs/limbs/super_limb.py
M	rigify/rigs/limbs/ui.py
M	rigify/rigs/spines/super_spine.py
M	rigify/rigs/widgets.py
M	rigify/ui.py
M	rigify/utils.py

===================================================================

diff --git a/rigify/generate.py b/rigify/generate.py
index f86d5eb9..66971a7e 100644
--- a/rigify/generate.py
+++ b/rigify/generate.py
@@ -39,6 +39,7 @@ ORG_LAYER = [n == 31 for n in range(0, 32)]  # Armature layer that original bone
 MCH_LAYER = [n == 30 for n in range(0, 32)]  # Armature layer that mechanism bones should be moved to.
 DEF_LAYER = [n == 29 for n in range(0, 32)]  # Armature layer that deformation bones should be moved to.
 ROOT_LAYER = [n == 28 for n in range(0, 32)]  # Armature layer that root bone should be moved to.
+WGT_LAYERS = [x == 19 for x in range(0, 20)]  # Widgets go on the last scene layer.
 
 
 class Timer:
@@ -252,8 +253,11 @@ def generate_rig(context, metarig):
     # Create the root bone.
     bpy.ops.object.mode_set(mode='EDIT')
     root_bone = new_bone(obj, ROOT_NAME)
+    spread = get_xy_spread(metarig.data.bones) or metarig.data.bones[0].length
+    spread = float('%.3g' % spread)
+    scale = spread/0.589
     obj.data.edit_bones[root_bone].head = (0, 0, 0)
-    obj.data.edit_bones[root_bone].tail = (0, 1, 0)
+    obj.data.edit_bones[root_bone].tail = (0, scale, 0)
     obj.data.edit_bones[root_bone].roll = 0
     bpy.ops.object.mode_set(mode='OBJECT')
     obj.data.bones[root_bone].layers = ROOT_LAYER
@@ -273,6 +277,7 @@ def generate_rig(context, metarig):
         mesh = bpy.data.meshes.new(wgts_group_name)
         wgts_obj = bpy.data.objects.new(wgts_group_name, mesh)
         scene.objects.link(wgts_obj)
+        wgts_obj.layers = WGT_LAYERS
         t.tick("Create main WGTS: ")
 
     #----------------------------------
@@ -443,6 +448,19 @@ def generate_rig(context, metarig):
     # Create Bone Groups
     create_bone_groups(obj, metarig)
 
+    # Add rig_ui to logic
+    skip = False
+    ctrls = obj.game.controllers
+    for c in ctrls:
+        if 'Python' in c.name and c.text.name == 'rig_ui.py':
+            skip = True
+            break
+    if not skip:
+        bpy.ops.logic.controller_add(type='PYTHON', object=obj.name)
+        ctrl = obj.game.controllers[-1]
+        ctrl.text = bpy.data.texts['rig_ui.py']
+
+
     t.tick("The rest: ")
     #----------------------------------
     # Deconfigure
@@ -549,6 +567,16 @@ def get_bone_rigs(obj, bone_name, halt_on_missing=False):
     return rigs
 
 
+def get_xy_spread(bones):
+    x_max = 0
+    y_max = 0
+    for b in bones:
+        x_max = max((x_max, abs(b.head[0]), abs(b.tail[0])))
+        y_max = max((y_max, abs(b.head[1]), abs(b.tail[1])))
+
+    return max((x_max, y_max))
+
+
 def param_matches_type(param_name, rig_type):
     """ Returns True if the parameter name is consistent with the rig type.
     """
diff --git a/rigify/legacy/utils.py b/rigify/legacy/utils.py
index 65838b7d..c718f146 100644
--- a/rigify/legacy/utils.py
+++ b/rigify/legacy/utils.py
@@ -151,7 +151,7 @@ def copy_bone_simple(obj, bone_name, assign_name=''):
         edit_bone_1 = obj.data.edit_bones[bone_name]
         edit_bone_2 = obj.data.edit_bones.new(assign_name)
         bone_name_1 = bone_name
-        bone_name_2 = edit_bone_2.name
+        bone_name_2 = edit_bone_2.name    
 
         # Copy edit bone attributes
         edit_bone_2.layers = list(edit_bone_1.layers)
diff --git a/rigify/metarigs/human.py b/rigify/metarigs/human.py
index 4c136441..c641fdbf 100644
--- a/rigify/metarigs/human.py
+++ b/rigify/metarigs/human.py
@@ -1191,10 +1191,7 @@ def create(obj):
     pbone.lock_scale = (False, False, False)
     pbone.rotation_mode = 'QUATERNION'
     pbone.bone.layers = [False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]
-    try:
-        pbone.rigify_parameters.chain_bone_controls = "1, 2, 3"
-    except AttributeError:
-        pass
+
     try:
         pbone.rigify_parameters.neck_pos = 5
     except AttributeError:
diff --git a/rigify/rigs/limbs/arm.py b/rigify/rigs/limbs/arm.py
index 1a560c46..e7e08c41 100644
--- a/rigify/rigs/limbs/arm.py
+++ b/rigify/rigs/limbs/arm.py
@@ -1,17 +1,17 @@
 import bpy, re
 from ..widgets import create_hand_widget, create_gear_widget
-from   .ui             import create_script
-from   .limb_utils     import *
-from   mathutils       import Vector
-from   ...utils       import copy_bone, flip_bone, put_bone, create_cube_widget
-from   ...utils       import strip_org, make_deformer_name, create_widget
-from   ...utils       import create_circle_widget, create_sphere_widget, create_line_widget
-from   ...utils       import MetarigError, make_mechanism_name, org
-from   ...utils       import create_limb_widget, connected_children_names
-from   ...utils       import align_bone_y_axis
-from   rna_prop_ui     import rna_idprop_ui_prop_get
-from   ..widgets import create_ikarrow_widget
-from   math            import trunc, pi
+from .ui             import create_script
+from .limb_utils     import *
+from mathutils       import Vector
+from ...utils       import copy_bone, flip_bone, put_bone, create_cube_widget
+from ...utils       import strip_org, make_deformer_name, create_widget
+from ...utils       import create_circle_widget, create_sphere_widget, create_line_widget
+from ...utils       import MetarigError, make_mechanism_name, org
+from ...utils       import create_limb_widget, connected_children_names
+from ...utils       import align_bone_y_axis, align_bone_x_axis, align_bone_z_axis
+from rna_prop_ui import rna_idprop_ui_prop_get
+from ..widgets import create_ikarrow_widget
+from math import trunc, pi
 
 extra_script = """
 controls = [%s]
@@ -19,13 +19,14 @@ ctrl    = '%s'
 
 if is_selected( controls ):
     layout.prop( pose_bones[ ctrl ], '["%s"]')
-    layout.prop( pose_bones[ ctrl ], '["%s"]')
+    if '%s' in pose_bones[ctrl].keys():
+        layout.prop( pose_bones[ ctrl ], '["%s"]', slider = True )
     if '%s' in pose_bones[ctrl].keys():
         layout.prop( pose_bones[ ctrl ], '["%s"]', slider = True )
 """
 
-IMPLEMENTATION = True    # Include and set True if Rig is just an implementation for a wrapper class
-                    # add_parameters and parameters_ui are unused for implementation classes
+IMPLEMENTATION = True   # Include and set True if Rig is just an implementation for a wrapper class
+                        # add_parameters and parameters_ui are unused for implementation classes
 
 
 class Rig:
@@ -43,6 +44,7 @@ class Rig:
         self.bbones = params.bbones
         self.limb_type = params.limb_type
         self.rot_axis = params.rotation_axis
+        self.auto_align_extremity = params.auto_align_extremity
 
         # Assign values to tweak/FK layers props if opted by user
         if params.tweak_extra_layers:
@@ -55,6 +57,36 @@ class Rig:
         else:
             self.fk_layers = None
 
+    def orient_org_bones(self):
+
+        bpy.ops.object.mode_set(mode='EDIT')
+        eb = self.obj.data.edit_bones
+
+        thigh = self.org_bones[0]
+        org_bones = list(
+            [thigh] + connected_children_names(self.obj, thigh)
+        )  # All the provided orgs
+
+        org_uarm = eb[org_bones[0]]
+        org_farm = eb[org_bones[1]]
+        org_hand = eb[org_bones[2]]
+
+        if self.rot_axis != 'automatic':
+            if self.auto_align_extremity:
+                z_ground_projection = Vector((org_hand.z_axis[0], org_hand.z_axis[1], 0))
+                align_bone_z_axis(self.obj, org_hand.name, z_ground_projection.normalized())
+            return
+
+        # Orient uarm farm bones
+        chain_y_axis = org_uarm.y_axis + org_farm.y_axis
+        chain_rot_axis = org_uarm.y_axis.cross(chain_y_axis).normalized()  # ik-plane normal axis (rotation)
+
+        align_bone_x_axis(self.obj, org_uarm.name, chain_rot_axis)
+        align_bone_x_axis(self.obj, org_farm.name, chain_rot_axis)
+
+        # Orient hand
+        align_bone_x_axis(self.obj, org_hand.name, chain_rot_axis)
+
     def create_parent(self):
 
         org_bones = self.org_bones
@@ -350,9 +382,9 @@ class Rig:
         bpy.ops.object.mode_set(mode ='EDIT')
         eb = self.obj.data.edit_bones
 
-        ctrl       = get_bone_name( org_bones[0], 'ctrl', 'ik'        )
-        mch_ik     = get_bone_name( org_bones[0], 'mch',  'ik'        )
-        mch_target = get_bone_name( org_bones[0], 'mch',  'ik_target' )
+        ctrl = get_bone_name(org_bones[0], 'ctrl', 'ik')
+        mch_ik = get_bone_name(org_bones[0], 'mch', 'ik')
+        mch_target = get_bone_name(org_bones[0], 'mch', 'ik_target')
 
         for o, ik in zip( org_bones, [ ctrl, mch_ik, mch_target ] ):
             bone = copy_bone( self.obj, o, ik )
@@ -370,9 +402,9 @@ class Rig:
         eb[ mch_str ].tail = eb[ org_bones[-1] ].head
 
         # Parenting
-        eb[ ctrl    ].parent = eb[ parent ]
-        eb[ mch_str ].parent = eb[ parent ]
-        eb[ mch_ik  ].parent = eb[ ctrl   ]
+        eb[ctrl].parent = eb[parent]
+        eb[mch_str].parent = eb[parent]
+        eb[mch_ik].parent = eb[ctrl]
 
         # Make standard pole target bone
         pole_name = get_bone_name(org_bones[0], 'ctrl', 'ik_target')
@@ -381,17 +413,25 @@ class Rig:
         lo_vector = eb[org_bones[1]].tail - eb[org_bones[1]].head
         tot_vector = eb[org_bones[0]].head - eb[org_bones[1]].tail
         tot_vector.normalize()
-        elbow_vector = lo_vector.dot(tot_vector)*tot_vector - lo_vector    # elbow_vec as regression of lo on tot
+        elbow_vector = lo_vector.dot(tot_vector)*tot_vector - lo_vector    # elbow_vec as rejection of lo on tot
         elbow_vector.normalize()
         elbow_vector *= (eb[org_bones[1]].tail - eb[org_bones[0]].head).length
-        z_vector = eb[org_bones[0]].z_axis + eb[org_bones[1]].z_axis
-        alfa = elbow_vector.angle(z_vector)
+
+        if self.rot_axis == 'x' or self.rot_axis == 'automatic':
+            z_vector = eb[org_bones[0]].z_axis + eb[org_bones[1]].z_axis
+            alfa = elbow_vector.angle(z_vector)
+        elif self.rot_axis == 'z':
+            x_vector = eb[org_bones[0]].x_axis + eb[org_bones[1]].x_axis
+            alfa = elbow_vector.angle(x_vector)
 
         if alfa > pi/2:
             pole_angle = -pi/2
        

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list