Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-12-13 16:59:16 +0300
committerCampbell Barton <ideasman42@gmail.com>2009-12-13 16:59:16 +0300
commita1656300ba14f9a220961814ab0366ece6900441 (patch)
tree9bac019a4acecdbc81240a7b4d06284eeae4391d /release/scripts/modules/rigify
parentc1bfd014bd8fb4af1ee51ed0e2aaecb707c46ff2 (diff)
script for automating pep8 checks.
On ubuntu/debian install these tools... sudo apt-get install pylint pyflakes python-setuptools python-pip sudo pip install pep8 then run from blenders source dir... python release/test/pep8.py This searches for the comments "# <pep8 compliant>" and "# <pep8-80 compliant>", running the checking tools on these scripts only. * some minor pep8 corrections too.
Diffstat (limited to 'release/scripts/modules/rigify')
-rw-r--r--release/scripts/modules/rigify/__init__.py59
-rw-r--r--release/scripts/modules/rigify/arm_biped_generic.py38
-rw-r--r--release/scripts/modules/rigify/copy.py9
-rw-r--r--release/scripts/modules/rigify/delta.py1
-rw-r--r--release/scripts/modules/rigify/leg_biped_generic.py2
-rw-r--r--release/scripts/modules/rigify/neck_flex.py18
-rw-r--r--release/scripts/modules/rigify/palm_curl.py1
-rw-r--r--release/scripts/modules/rigify/spine_pivot_flex.py4
8 files changed, 69 insertions, 63 deletions
diff --git a/release/scripts/modules/rigify/__init__.py b/release/scripts/modules/rigify/__init__.py
index 3cef288f79e..519784e8507 100644
--- a/release/scripts/modules/rigify/__init__.py
+++ b/release/scripts/modules/rigify/__init__.py
@@ -25,14 +25,18 @@ from Mathutils import Vector
from rna_prop_ui import rna_idprop_ui_prop_get
SPECIAL_TYPES = "root",
+
class RigifyError(Exception):
"""Exception raised for errors in the metarig.
"""
+
def __init__(self, message):
self.message = message
+
def __str__(self):
return repr(self.message)
+
def submodule_func_from_type(bone_type):
type_pair = bone_type.split(".")
@@ -48,7 +52,7 @@ def submodule_func_from_type(bone_type):
submod = __import__(name="%s.%s" % (__package__, type_name), fromlist=[type_name])
except ImportError:
raise RigifyError("python module for type '%s' not found" % type_name)
-
+
reload(submod)
return type_name, submod, getattr(submod, func_name)
@@ -60,9 +64,10 @@ def get_submodule_types():
for f in files:
if not f.startswith("_") and f.endswith(".py"):
submodules.append(f[:-3])
-
+
return sorted(submodules)
+
def get_bone_type_options(pbone, type_name):
options = {}
bone_name = pbone.name
@@ -75,13 +80,14 @@ def get_bone_type_options(pbone, type_name):
return options
+
def validate_rig(context, obj):
'''
Makes no changes
only runs the metarig definitions and reports errors
'''
type_found = False
-
+
for pbone in obj.pose.bones:
bone_name = pbone.name
bone_type = pbone.get("type", "")
@@ -103,19 +109,19 @@ def validate_rig(context, obj):
get_bone_type_options(pbone, bone_type)
# missing, - check for duplicate root bone.
-
+
if not type_found:
raise RigifyError("This rig has no 'type' properties defined on any pose bones, nothing to do")
def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
'''
- Main function for generating
+ Main function for generating
'''
from collections import OrderedDict
import rigify_utils
reload(rigify_utils)
-
+
# Not needed but catches any errors before duplicating
validate_rig(context, obj_orig)
@@ -124,8 +130,8 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
mode_orig = context.mode
rest_backup = obj_orig.data.pose_position
obj_orig.data.pose_position = 'REST'
-
-
+
+
bpy.ops.object.mode_set(mode='OBJECT')
scene = context.scene
@@ -147,7 +153,7 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
# original name mapping
base_names = {}
-
+
# add all new parentless children to this bone
root_bone = None
@@ -168,7 +174,7 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
# value: [functions, ...]
# each function is from the module. eg leg.ik, arm.main
bone_typeinfos = {}
-
+
# key: bone name
# value: [new_bone_name, ...]
# where each bone with a 'type' stores a list of bones that it created
@@ -182,12 +188,12 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
bone_type = pbone.get("type", "")
if bone_type:
bone_type_list = [bt for bt in bone_type.replace(",", " ").split()]
-
+
# not essential but means running autorig again wont do anything
del pbone["type"]
else:
bone_type_list = []
-
+
if bone_type_list == ["root"]: # special case!
if root_bone:
raise Exception("cant have more then 1 root bone, found '%s' and '%s' to have type==root" % (root_bone, bone_name))
@@ -197,7 +203,7 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
for bone_type in bone_type_list:
type_name, submod, type_func = submodule_func_from_type(bone_type)
reload(submod)
-
+
bone_def_dict = bone_definitions.setdefault(bone_name, {})
# Only calculate bone definitions once
@@ -226,7 +232,7 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
# Only blend results from the same submodule, eg.
# leg.ik and arm.fk could not be blended.
results = OrderedDict()
-
+
bone_names_pre = set([bone.name for bone in arm.bones])
for type_name, type_func in bone_typeinfos[bone_name]:
@@ -255,21 +261,21 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
bone_names_post = set([bone.name for bone in arm.bones])
-
+
# Store which bones were created from this one
bone_genesis[bone_name] = list(bone_names_post - bone_names_pre)
-
+
# need a reverse lookup on bone_genesis so as to know immediately
# where a bone comes from
bone_genesis_reverse = {}
for bone_name, bone_children in bone_genesis.items():
for bone_child_name in bone_children:
bone_genesis_reverse[bone_child_name] = bone_name
-
+
if root_bone:
# assign all new parentless bones to this
-
+
bpy.ops.object.mode_set(mode='EDIT')
root_ebone = arm.edit_bones[root_bone]
for ebone in arm.edit_bones:
@@ -284,19 +290,19 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
root_ebone_tmp = arm.edit_bones[root_bone_override]
else:
root_ebone_tmp = root_ebone
-
+
ebone.connected = False
ebone.parent = root_ebone_tmp
bpy.ops.object.mode_set(mode='OBJECT')
-
+
if META_DEF:
# for pbone in obj_def.pose.bones:
for bone_name, bone_name_new in base_names.items():
#pbone_from = bone_name
pbone = obj_def.pose.bones[bone_name_new]
-
+
con = pbone.constraints.new('COPY_ROTATION')
con.target = obj
con.subtarget = bone_name
@@ -318,8 +324,7 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
obj_orig.data.pose_position = rest_backup
obj.data.pose_position = 'POSE'
context.user_preferences.edit.global_undo = global_undo
-
-
+
return obj
@@ -344,9 +349,9 @@ def generate_test(context, metarig_type="", GENERATE_FINAL=True):
continue
# XXX workaround!, problem with updating the pose matrix.
- if module_name=="delta":
+ if module_name == "delta":
continue
-
+
type_name, submodule, func = submodule_func_from_type(module_name)
metarig_template = getattr(submodule, "metarig_template", None)
@@ -356,7 +361,7 @@ def generate_test(context, metarig_type="", GENERATE_FINAL=True):
metarig_template()
obj = context.active_object
obj.location = scene.cursor_location
-
+
if GENERATE_FINAL:
obj_new = generate_rig(context, obj)
new_objects.append((obj, obj_new))
@@ -378,7 +383,7 @@ def generate_test_all(context, GRAPH=False):
reload(graphviz_export)
new_objects = rigify.generate_test(context)
-
+
if GRAPH:
base_name = os.path.splitext(bpy.data.filename)[0]
for obj, obj_new in new_objects:
diff --git a/release/scripts/modules/rigify/arm_biped_generic.py b/release/scripts/modules/rigify/arm_biped_generic.py
index 33fbb8577cf..22de14ade54 100644
--- a/release/scripts/modules/rigify/arm_biped_generic.py
+++ b/release/scripts/modules/rigify/arm_biped_generic.py
@@ -96,14 +96,14 @@ def metarig_definition(obj, orig_bone_name):
def ik(obj, definitions, base_names, options):
arm = obj.data
-
+
mt = bone_class_instance(obj, METARIG_NAMES)
mt.shoulder, mt.arm, mt.forearm, mt.hand = definitions
mt.update()
-
+
ik = bone_class_instance(obj, ["pole", "pole_vis", "hand_vis"])
ik_chain = mt.copy(to_fmt="MCH-%s_ik", base_names=base_names, exclude_attrs=["shoulder"])
-
+
# IK needs no parent_index
ik_chain.hand_e.connected = False
ik_chain.hand_e.parent = None
@@ -112,14 +112,14 @@ def ik(obj, definitions, base_names, options):
ik_chain.arm_e.connected = False
ik_chain.arm_e.parent = mt.shoulder_e
-
+
# Add the bone used for the arms poll target
#ik.pole = add_pole_target_bone(obj, mt.forearm, get_base_name(base_names[mt.forearm]) + "_target" + get_side_name(mt.forearm), mode='ZAVERAGE')
ik.pole = add_pole_target_bone(obj, mt.forearm, "elbow_target" + get_side_name(mt.forearm), mode='ZAVERAGE')
-
+
ik.update()
ik.pole_e.local_location = False
-
+
# option: elbow_parent
elbow_parent_name = options.get("elbow_parent", "")
@@ -130,17 +130,17 @@ def ik(obj, definitions, base_names, options):
# TODO, old/new parent mapping
raise RigifyError("parent bone from property 'arm_biped_generic.elbow_parent' not found '%s'" % elbow_parent_name)
ik.pole_e.parent = elbow_parent_e
-
+
# update bones after this!
ik.hand_vis = add_stretch_to(obj, mt.hand, ik_chain.hand, "VIS-%s_ik" % base_names[mt.hand])
ik.pole_vis = add_stretch_to(obj, mt.forearm, ik.pole, "VIS-%s_ik" % base_names[mt.forearm])
-
+
ik.update()
ik.hand_vis_e.restrict_select = True
ik.pole_vis_e.restrict_select = True
-
+
bpy.ops.object.mode_set(mode='OBJECT')
-
+
mt.update()
ik.update()
ik_chain.update()
@@ -171,15 +171,15 @@ def ik(obj, definitions, base_names, options):
prop["soft_max"] = 1.0
bpy.ops.object.mode_set(mode='EDIT')
-
+
# don't blend the shoulder
return [None] + ik_chain.names()
def fk(obj, definitions, base_names, options):
-
+
arm = obj.data
-
+
mt = bone_class_instance(obj, METARIG_NAMES)
mt.shoulder, mt.arm, mt.forearm, mt.hand = definitions
mt.update()
@@ -197,19 +197,19 @@ def fk(obj, definitions, base_names, options):
ex.socket_e.connected = False
ex.socket_e.parent = mt.shoulder_e
ex.socket_e.length *= 0.5
-
+
# insert the 'DLT-hand', between the forearm and the hand
# copies forarm rotation
ex.hand_delta_e = copy_bone_simple(arm, fk_chain.hand, "DLT-%s" % base_names[mt.hand], parent=True)
ex.hand_delta = ex.hand_delta_e.name
ex.hand_delta_e.length *= 0.5
ex.hand_delta_e.connected = False
-
+
fk_chain.hand_e.connected = False
fk_chain.hand_e.parent = ex.hand_delta_e
bpy.ops.object.mode_set(mode='OBJECT')
-
+
mt.update()
ex.update()
fk_chain.update()
@@ -222,7 +222,7 @@ def fk(obj, definitions, base_names, options):
con = fk_chain.arm_p.constraints.new('COPY_LOCATION')
con.target = obj
con.subtarget = ex.socket
-
+
fk_chain.hand_p.lock_location = True, True, True
con = ex.hand_delta_p.constraints.new('COPY_ROTATION')
con.target = obj
@@ -262,13 +262,13 @@ def fk(obj, definitions, base_names, options):
mod.coefficients[1] = -1.0
hinge_setup()
-
+
bpy.ops.object.mode_set(mode='EDIT')
return None, fk_chain.arm, fk_chain.forearm, fk_chain.hand
-def main(obj, bone_definition, base_names, options):
+def main(obj, bone_definition, base_names, options):
bones_ik = ik(obj, bone_definition, base_names, options)
bones_fk = fk(obj, bone_definition, base_names, options)
diff --git a/release/scripts/modules/rigify/copy.py b/release/scripts/modules/rigify/copy.py
index 70086b70907..6a3ecb7f639 100644
--- a/release/scripts/modules/rigify/copy.py
+++ b/release/scripts/modules/rigify/copy.py
@@ -24,7 +24,7 @@ from rna_prop_ui import rna_idprop_ui_prop_get
METARIG_NAMES = ("cpy",)
-# note, this example is just a bone with copy property.
+
def metarig_template():
# generated by rigify.write_meta_rig
bpy.ops.object.mode_set(mode='EDIT')
@@ -40,6 +40,7 @@ def metarig_template():
pbone = obj.pose.bones['Bone']
pbone['type'] = 'copy'
+
def metarig_definition(obj, orig_bone_name):
return [orig_bone_name]
@@ -51,14 +52,14 @@ def main(obj, bone_definition, base_names, options):
mt.update()
cp = mt.copy(to_fmt="%s_cpy")
bpy.ops.object.mode_set(mode='OBJECT')
-
+
cp.update()
mt.update()
-
+
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
diff --git a/release/scripts/modules/rigify/delta.py b/release/scripts/modules/rigify/delta.py
index 4e1d8ce4571..475c64ab317 100644
--- a/release/scripts/modules/rigify/delta.py
+++ b/release/scripts/modules/rigify/delta.py
@@ -118,7 +118,6 @@ def main(obj, bone_definition, base_names, options):
bpy.ops.object.mode_set(mode='OBJECT')
-
# Move the child bone to the deltas location
obj.animation_data_create()
delta_pbone = obj.pose.bones[delta_name]
diff --git a/release/scripts/modules/rigify/leg_biped_generic.py b/release/scripts/modules/rigify/leg_biped_generic.py
index 4ce7352539a..c48ff093a2f 100644
--- a/release/scripts/modules/rigify/leg_biped_generic.py
+++ b/release/scripts/modules/rigify/leg_biped_generic.py
@@ -106,7 +106,7 @@ def metarig_definition(obj, orig_bone_name):
children = bone.children
# Now there must be 2 children, only one connected
if len(children) != 2:
- raise RigifyError("expected the foot bone:'%s' to have 2 children" % bone.name )
+ raise RigifyError("expected the foot bone:'%s' to have 2 children" % bone.name)
if children[0].connected == children[1].connected:
raise RigifyError("expected one bone to be connected")
diff --git a/release/scripts/modules/rigify/neck_flex.py b/release/scripts/modules/rigify/neck_flex.py
index 15efc2a6985..377fd9c9bc8 100644
--- a/release/scripts/modules/rigify/neck_flex.py
+++ b/release/scripts/modules/rigify/neck_flex.py
@@ -154,8 +154,8 @@ def main(obj, bone_definition, base_names, options):
ex.neck_socket_e.head = mt.head_e.head
ex.neck_socket_e.tail = mt.head_e.head - Vector(0.0, neck_chain_segment_length / 2.0, 0.0)
ex.neck_socket_e.roll = 0.0
-
-
+
+
# copy of the head for controling
ex.head_ctrl_e = copy_bone_simple(arm, mt.head, base_names[mt.head])
ex.head_ctrl = ex.head_ctrl_e.name
@@ -229,7 +229,7 @@ def main(obj, bone_definition, base_names, options):
head_driver_path = ex.head_ctrl_p.path_to_id()
target_names = [("b%.2d" % (i + 1)) for i in range(len(neck_chain))]
-
+
ex.head_ctrl_p["bend_tot"] = 0.0
fcurve = ex.head_ctrl_p.driver_add('["bend_tot"]', 0)
driver = fcurve.driver
@@ -242,7 +242,7 @@ def main(obj, bone_definition, base_names, options):
tar.id_type = 'OBJECT'
tar.id = obj
tar.data_path = head_driver_path + ('["bend_%.2d"]' % (i + 1))
-
+
for i, attr in enumerate(ex_chain.attr_names):
neck_p = getattr(ex_chain, attr + "_p")
@@ -272,9 +272,9 @@ def main(obj, bone_definition, base_names, options):
driver = fcurve.driver
driver.type = 'SCRIPTED'
driver.expression = "bend/bend_tot"
-
+
fcurve.modifiers.remove(0) # grr dont need a modifier
-
+
# add target
tar = driver.targets.new()
@@ -282,14 +282,14 @@ def main(obj, bone_definition, base_names, options):
tar.id_type = 'OBJECT'
tar.id = obj
tar.data_path = head_driver_path + ('["bend_tot"]')
-
+
tar = driver.targets.new()
tar.name = "bend"
tar.id_type = 'OBJECT'
tar.id = obj
tar.data_path = head_driver_path + ('["%s"]' % prop_name)
-
-
+
+
# finally constrain the original bone to this one
orig_neck_p = getattr(mt_chain, attr + "_p")
con = orig_neck_p.constraints.new('COPY_ROTATION')
diff --git a/release/scripts/modules/rigify/palm_curl.py b/release/scripts/modules/rigify/palm_curl.py
index 5a06d2451ee..ee99ef6e82a 100644
--- a/release/scripts/modules/rigify/palm_curl.py
+++ b/release/scripts/modules/rigify/palm_curl.py
@@ -25,6 +25,7 @@ from rna_prop_ui import rna_idprop_ui_prop_get
# not used, defined for completeness
METARIG_NAMES = tuple()
+
def metarig_template():
# generated by rigify.write_meta_rig
bpy.ops.object.mode_set(mode='EDIT')
diff --git a/release/scripts/modules/rigify/spine_pivot_flex.py b/release/scripts/modules/rigify/spine_pivot_flex.py
index f2608732c37..4765f0591f7 100644
--- a/release/scripts/modules/rigify/spine_pivot_flex.py
+++ b/release/scripts/modules/rigify/spine_pivot_flex.py
@@ -177,7 +177,7 @@ def main(obj, bone_definition, base_names, options):
df.ribcage_e = copy_bone_simple(arm, child.name, "DEF-wgt_%s" % base_names[mt.ribcage])
df.ribcage = df.ribcage_e.name
df.ribcage_e.translate(Vector(spine_chain_segment_length * 2.0, - df.ribcage_e.length / 2.0, 0.0))
-
+
ex.ribcage_copy_e = copy_bone_simple(arm, mt.ribcage, base_names[mt.ribcage])
ex.ribcage_copy = ex.ribcage_copy_e.name
ex.ribcage_copy_e.connected = False
@@ -294,7 +294,7 @@ def main(obj, bone_definition, base_names, options):
# df.ribcage_p / DEF-wgt_rib_cage
df.ribcage_p.lock_location = True, True, True
-
+
con = df.ribcage_p.constraints.new('COPY_ROTATION')
con.target = obj
con.subtarget = ex.ribcage