diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-02-23 02:32:58 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-02-23 02:32:58 +0300 |
commit | 97bdfe6f1bbd4413693654362876de6395642da9 (patch) | |
tree | af90a9730d66c54de01d8add4366eac11fbafbfe /release/scripts/modules | |
parent | a8d364ce4accb900c690229925356ba2ffabdc74 (diff) |
pep8 cleanup + correction for external player operator return value.
Diffstat (limited to 'release/scripts/modules')
-rw-r--r-- | release/scripts/modules/bpy/ops.py | 1 | ||||
-rw-r--r-- | release/scripts/modules/bpy/utils.py | 39 | ||||
-rw-r--r-- | release/scripts/modules/rigify/leg_quadruped.py | 2 | ||||
-rw-r--r-- | release/scripts/modules/rigify/mouth.py | 14 | ||||
-rw-r--r-- | release/scripts/modules/rigify/shape_key_control.py | 54 | ||||
-rw-r--r-- | release/scripts/modules/rigify/tail_control.py | 34 |
6 files changed, 74 insertions, 70 deletions
diff --git a/release/scripts/modules/bpy/ops.py b/release/scripts/modules/bpy/ops.py index 045401b54f7..f8f01730a49 100644 --- a/release/scripts/modules/bpy/ops.py +++ b/release/scripts/modules/bpy/ops.py @@ -27,6 +27,7 @@ op_call = ops_module.call op_as_string = ops_module.as_string op_get_rna = ops_module.get_rna + class bpy_ops(object): ''' Fake module like class. diff --git a/release/scripts/modules/bpy/utils.py b/release/scripts/modules/bpy/utils.py index 5ddf2def5f2..29d9c42ae57 100644 --- a/release/scripts/modules/bpy/utils.py +++ b/release/scripts/modules/bpy/utils.py @@ -48,10 +48,11 @@ def _test_import(module_name, loaded_modules): if _bpy.app.debug: print("time %s %.4f" % (module_name, time.time() - t)) - + loaded_modules.add(mod.__name__) # should match mod.__name__ too return mod + def modules_from_path(path, loaded_modules): """ Load all modules in a path and return them as a list. @@ -65,9 +66,9 @@ def modules_from_path(path, loaded_modules): """ import traceback import time - + modules = [] - + for f in sorted(_os.listdir(path)): if f.endswith(".py"): # python module @@ -77,10 +78,10 @@ def modules_from_path(path, loaded_modules): mod = _test_import(f, loaded_modules) else: mod = None - + if mod: modules.append(mod) - + return modules _loaded = [] # store loaded modules for reloading. @@ -90,7 +91,7 @@ _bpy_types = __import__("bpy_types") # keep for comparisons, never ever reload t def load_scripts(reload_scripts=False, refresh_scripts=False): """ Load scripts and run each modules register function. - + :arg reload_scripts: Causes all scripts to have their unregister method called before loading. :type reload_scripts: bool :arg refresh_scripts: only load scripts which are not already loaded as modules. @@ -102,7 +103,7 @@ def load_scripts(reload_scripts=False, refresh_scripts=False): t_main = time.time() loaded_modules = set() - + if refresh_scripts: original_modules = _sys.modules.values() @@ -121,7 +122,7 @@ def load_scripts(reload_scripts=False, refresh_scripts=False): return reload(mod) except: traceback.print_exc() - + def test_register(mod): if refresh_scripts and mod in original_modules: @@ -141,7 +142,7 @@ def load_scripts(reload_scripts=False, refresh_scripts=False): else: print("\nWarning! '%s' has no register function, this is now a requirement for registerable scripts." % mod.__file__) _loaded.append(mod) - + if reload_scripts: # reload modules that may not be directly included for type_class_name in dir(_bpy.types): @@ -155,7 +156,7 @@ def load_scripts(reload_scripts=False, refresh_scripts=False): for module_name in sorted(loaded_modules): print("Reloading:", module_name) test_reload(_sys.modules[module_name]) - + # loop over and unload all scripts _loaded.reverse() for mod in _loaded: @@ -167,7 +168,7 @@ def load_scripts(reload_scripts=False, refresh_scripts=False): traceback.print_exc() _loaded[:] = [] - for base_path in script_paths(user = False): + for base_path in script_paths(user=False): for path_subdir in ("ui", "op", "io", "cfg"): path = _os.path.join(base_path, path_subdir) if _os.path.isdir(path): @@ -182,20 +183,20 @@ def load_scripts(reload_scripts=False, refresh_scripts=False): path = _os.path.join(user_path, path_subdir) if _os.path.isdir(path): sys_path_ensure(path) - + for mod in modules_from_path(path, loaded_modules): test_register(mod) # load extensions - used_ext = {ext.module for ext in _bpy.context.user_preferences.extensions} + used_ext = {ext.module for ext in _bpy.context.user_preferences.extensions} paths = script_paths("extensions") for path in paths: sys_path_ensure(path) - + for module_name in sorted(used_ext): mod = _test_import(module_name, loaded_modules) test_register(mod) - + if reload_scripts: import gc print("gc.collect() -> %d" % gc.collect()) @@ -262,16 +263,18 @@ def display_name(name): _scripts = _os.path.join(_os.path.dirname(__file__), _os.path.pardir, _os.path.pardir) _scripts = (_os.path.normpath(_scripts), ) + def user_script_path(): path = _bpy.context.user_preferences.filepaths.python_scripts_directory - + if path: path = _os.path.normpath(path) return path else: return None -def script_paths(subdir = None, user = True): + +def script_paths(subdir=None, user=True): """ Returns a list of valid script paths from the home directory and user preferences. @@ -284,7 +287,7 @@ def script_paths(subdir = None, user = True): user_script_path = _bpy.context.user_preferences.filepaths.python_scripts_directory else: user_script_path = None - + for path in home_paths("scripts") + (user_script_path, ): if path: path = _os.path.normpath(path) diff --git a/release/scripts/modules/rigify/leg_quadruped.py b/release/scripts/modules/rigify/leg_quadruped.py index f2f0c4d883e..c21680740bd 100644 --- a/release/scripts/modules/rigify/leg_quadruped.py +++ b/release/scripts/modules/rigify/leg_quadruped.py @@ -129,7 +129,7 @@ def ik(obj, bone_definition, base_names, options): # keep the foot_ik as the parent ik_chain.toe_e.connected = False - + # Foot uses pose space, not local space, for translation ik_chain.foot_e.local_location = False diff --git a/release/scripts/modules/rigify/mouth.py b/release/scripts/modules/rigify/mouth.py index a30a8757d70..31d7c5a1ce9 100644 --- a/release/scripts/modules/rigify/mouth.py +++ b/release/scripts/modules/rigify/mouth.py @@ -197,23 +197,23 @@ def deform(obj, definitions, base_names, options): 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 @@ -234,12 +234,12 @@ def deform(obj, definitions, base_names, options): 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') diff --git a/release/scripts/modules/rigify/shape_key_control.py b/release/scripts/modules/rigify/shape_key_control.py index 40290035597..fd0e900a7b5 100644 --- a/release/scripts/modules/rigify/shape_key_control.py +++ b/release/scripts/modules/rigify/shape_key_control.py @@ -92,7 +92,7 @@ def main(obj, definitions, base_names, options): properties of a single bone. A different shape can be driven by the negative value of a transform as well by giving a comma-separated list of two shapes. - + Required options: mesh: name of mesh object(s) to add/get shapekeys to/from (if multiple objects, make a comma-separated list) @@ -105,15 +105,15 @@ def main(obj, definitions, base_names, options): scale_<x/y/z>_fac: default multiplier of the bone influence on the shape key shape_key_sliders: comma-separated list of custom properties to create sliders out of for driving shape keys <custom_prop>: for each property listed in shape_key_sliders, specify a shape key for it to drive - + """ - + bpy.ops.object.mode_set(mode='EDIT') eb = obj.data.edit_bones pb = obj.pose.bones org_bone = definitions[0] - + # Options req_options = ["mesh"] for option in req_options: @@ -121,11 +121,11 @@ def main(obj, definitions, base_names, options): raise RigifyError("'%s' rig type requires a '%s' option (bone: %s)" % (RIG_TYPE, option, base_names[definitions[0]])) meshes = options["mesh"].replace(" ", "").split(",") - + bone = copy_bone_simple(obj.data, org_bone, base_names[org_bone], parent=True).name - + bpy.ops.object.mode_set(mode='OBJECT') - + # Set rotation mode and axis locks pb[bone].rotation_mode = pb[org_bone].rotation_mode pb[bone].lock_location = tuple(pb[org_bone].lock_location) @@ -133,7 +133,7 @@ def main(obj, definitions, base_names, options): pb[bone].lock_rotation_w = pb[org_bone].lock_rotation_w pb[bone].lock_rotations_4d = pb[org_bone].lock_rotations_4d pb[bone].lock_scale = tuple(pb[org_bone].lock_scale) - + # List of rig options for specifying shape keys # Append '_fac' to the end for the name of the corresponding 'factor # default' option for that shape @@ -146,7 +146,7 @@ def main(obj, definitions, base_names, options): "scale_x", "scale_y", "scale_z"] - + driver_paths = {"loc_x":".location[0]", "loc_y":".location[1]", "loc_z":".location[2]", @@ -159,13 +159,13 @@ def main(obj, definitions, base_names, options): "scale_x":".scale[0]", "scale_y":".scale[1]", "scale_z":".scale[2]"} - + # Create the shape keys and drivers for transforms shape_info = [] for option in shape_key_options: if option in options: shape_names = options[option].replace(" ", "").split(",") - + var_name = bone.replace(".","").replace("-","_") + "_" + option # Different RNA paths for euler vs quat if option in (shape_key_options[3:6]+shape_key_options[12:15]) \ @@ -173,12 +173,12 @@ def main(obj, definitions, base_names, options): var_path = driver_paths['q' + option] else: var_path = driver_paths[option] - + if (option+"_fac") in options: fac = options[option+"_fac"] else: fac = 1.0 - + # Positive if shape_names[0] != "": # Different expressions for loc/rot/scale and positive/negative @@ -197,7 +197,7 @@ def main(obj, definitions, base_names, options): expression = "(1.0 - " + var_name + ") * " + str(fac) + " * -2" shape_name = shape_names[0] create_shape_and_driver(obj, bone, meshes, shape_name, var_name, var_path, expression) - + # Negative if shape_names[0] != "" and len(shape_names) > 1: # Different expressions for loc/rot/scale and positive/negative @@ -216,7 +216,7 @@ def main(obj, definitions, base_names, options): expression = "(1.0 - " + var_name + ") * " + str(fac) + " * 2" shape_name = shape_names[1] create_shape_and_driver(obj, bone, meshes, shape_name, var_name, var_path, expression) - + # Create the shape keys and drivers for custom-property sliders if "shape_key_sliders" in options: # Get the slider names @@ -227,7 +227,7 @@ def main(obj, definitions, base_names, options): for slider_name in slider_names: if slider_name in options: shape_names = options[slider_name].replace(" ", "").split(",") - + # Set up the custom property on the bone prop = rna_idprop_ui_prop_get(pb[bone], slider_name, create=True) pb[bone][slider_name] = 0.0 @@ -238,7 +238,7 @@ def main(obj, definitions, base_names, options): if len(shape_names) > 1: prop["min"] = -1.0 prop["soft_min"] = -1.0 - + # Add the shape drivers # Positive if shape_names[0] != "": @@ -266,19 +266,19 @@ def main(obj, definitions, base_names, options): expression = var_name + " * " + str(fac) + " * -1" # Create the shape key driver create_shape_and_driver(obj, bone, meshes, shape_name, var_name, var_path, expression) - - + + # Org bone copy transforms of control bone con = pb[org_bone].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = bone - + return (None,) def create_shape_and_driver(obj, bone, meshes, shape_name, var_name, var_path, expression): """ Creates/gets a shape key and sets up a driver for it. - + obj = armature object bone = driving bone name meshes = list of meshes to create the shapekey/driver on @@ -289,16 +289,16 @@ def create_shape_and_driver(obj, bone, meshes, shape_name, var_name, var_path, e """ pb = obj.pose.bones bpy.ops.object.mode_set(mode='OBJECT') - + for mesh_name in meshes: mesh_obj = bpy.data.objects[mesh_name] - + # Add/get the shape key shape = addget_shape_key(mesh_obj, name=shape_name) - + # Add/get the shape key driver fcurve, a = addget_shape_key_driver(mesh_obj, name=shape_name) - + # Set up the driver driver = fcurve.driver driver.type = 'SCRIPTED' @@ -316,5 +316,5 @@ def create_shape_and_driver(obj, bone, meshes, shape_name, var_name, var_path, e var.targets[0].id_type = 'OBJECT' var.targets[0].id = obj var.targets[0].data_path = 'pose.bones["' + bone + '"]' + var_path - - + + diff --git a/release/scripts/modules/rigify/tail_control.py b/release/scripts/modules/rigify/tail_control.py index f33b51e9690..56305b5e07e 100644 --- a/release/scripts/modules/rigify/tail_control.py +++ b/release/scripts/modules/rigify/tail_control.py @@ -41,7 +41,7 @@ def metarig_template(): #bone.tail[:] = 0.0000, -0.0306, -0.0159 #bone.roll = 0.0000 #bone.connected = False - + #bpy.ops.object.mode_set(mode='OBJECT') #pbone = obj.pose.bones['tail.01'] #pbone['type'] = 'tail_spline_ik' @@ -72,13 +72,13 @@ def main(obj, bone_definitions, base_names, options): bb = obj.data.bones eb = obj.data.edit_bones pb = obj.pose.bones - + # Create bones for hinge/free # hinge 1 sticks with the parent # hinge 2 is the parent of the tail controls hinge1 = copy_bone_simple(arm, bone_definitions[0], "MCH-%s.hinge1" % base_names[bone_definitions[0]], parent=True).name hinge2 = copy_bone_simple(arm, bone_definitions[0], "MCH-%s.hinge2" % base_names[bone_definitions[0]], parent=False).name - + # Create tail control bones bones = [] i = 0 @@ -90,10 +90,10 @@ def main(obj, bone_definitions, base_names, options): eb[bone].local_location = False i = 1 bones += [bone] - - + + bpy.ops.object.mode_set(mode='OBJECT') - + # Rotation mode and axis locks for bone, org_bone in zip(bones, bone_definitions): pb[bone].rotation_mode = pb[org_bone].rotation_mode @@ -102,7 +102,7 @@ def main(obj, bone_definitions, base_names, options): pb[bone].lock_rotation = tuple(pb[org_bone].lock_rotation) pb[bone].lock_rotation_w = pb[org_bone].lock_rotation_w pb[bone].lock_scale = tuple(pb[org_bone].lock_scale) - + # Add custom properties pb[bones[0]]["hinge"] = 0.0 prop = rna_idprop_ui_prop_get(pb[bones[0]], "hinge", create=True) @@ -110,31 +110,31 @@ def main(obj, bone_definitions, base_names, options): prop["max"] = 1.0 prop["soft_min"] = 0.0 prop["soft_max"] = 1.0 - + pb[bones[0]]["free"] = 0.0 prop = rna_idprop_ui_prop_get(pb[bones[0]], "free", create=True) prop["min"] = 0.0 prop["max"] = 1.0 prop["soft_min"] = 0.0 prop["soft_max"] = 1.0 - + # Add constraints for bone, org_bone in zip(bones, bone_definitions): con = pb[org_bone].constraints.new('COPY_TRANSFORMS') con.target = obj con.subtarget = bone - + con_f = pb[hinge2].constraints.new('COPY_LOCATION') con_f.target = obj con_f.subtarget = hinge1 - + con_h = pb[hinge2].constraints.new('COPY_TRANSFORMS') con_h.target = obj con_h.subtarget = hinge1 - + # Add drivers bone_path = pb[bones[0]].path_to_id() - + driver_fcurve = con_f.driver_add("influence", 0) driver = driver_fcurve.driver driver.type = 'AVERAGE' @@ -147,7 +147,7 @@ def main(obj, bone_definitions, base_names, options): mod.poly_order = 1 mod.coefficients[0] = 1.0 mod.coefficients[1] = -1.0 - + driver_fcurve = con_h.driver_add("influence", 0) driver = driver_fcurve.driver driver.type = 'AVERAGE' @@ -160,7 +160,7 @@ def main(obj, bone_definitions, base_names, options): mod.poly_order = 1 mod.coefficients[0] = 1.0 mod.coefficients[1] = -1.0 - - + + return None - + |