diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-12-02 22:13:54 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-12-02 22:13:54 +0300 |
commit | 7706261e79d6103b21b7569dab71bc702be56ac0 (patch) | |
tree | 94e11b3498f111751f623ef89624b525d2bc3187 /release | |
parent | 2a6d535d23e80b649ba1f3bc048f1e368d7a63c7 (diff) |
change bone storage class so __slots__ can be used for looping over attributes without getting functions
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/modules/rigify/__init__.py | 71 |
1 files changed, 35 insertions, 36 deletions
diff --git a/release/scripts/modules/rigify/__init__.py b/release/scripts/modules/rigify/__init__.py index 7ef5f7f5dc6..78ace98ff89 100644 --- a/release/scripts/modules/rigify/__init__.py +++ b/release/scripts/modules/rigify/__init__.py @@ -24,11 +24,36 @@ from rna_prop_ui import rna_idprop_ui_get, rna_idprop_ui_prop_get empty_layer = [False] * 32 -def auto_class(slots, name="ContainerClass"): - return type(name, (object,), {"__slots__":tuple(slots)}) +def auto_class(slots, name="ContainerClass", class_dict=None): -def auto_class_instance(slots, name="ContainerClass"): - return auto_class(slots, name)() + if class_dict: + class_dict = class_dict.copy() + else: + class_dict = {} + + class_dict["__slots__"] = tuple(slots) + + return type(name, (object,), class_dict) + +def auto_class_instance(slots, name="ContainerClass", class_dict=None): + return auto_class(slots, name, class_dict)() + + +def _bone_class_instance_update(self): + ''' Re-Assigns bones from the blender data + ''' + arm = self.obj.data + bbones = arm.bones + pbones = self.obj.pose.bones + ebones = arm.edit_bones + + for member in self.__slots__: + if not member[-2] == "_": + name = getattr(self, member, None) + if name is not None: + setattr(self, member + "_b", bbones.get(name, None)) + setattr(self, member + "_p", pbones.get(name, None)) + setattr(self, member + "_e", ebones.get(name, None)) def bone_class_instance(obj, slots, name="BoneContainer"): slots = slots[:] # dont modify the original @@ -37,35 +62,9 @@ def bone_class_instance(obj, slots, name="BoneContainer"): slots.append(member + "_b") # bone bone slots.append(member + "_p") # pose bone slots.append(member + "_e") # edit bone - - slots.extend(["obj", "update"]) - - instance = auto_class_instance(slots, name) - - def update(): - ''' - Re-Assigns bones from the blender data - ''' - arm = obj.data - - bbones = arm.bones - pbones = obj.pose.bones - ebones = arm.edit_bones - - for member in slots: - - if member in ("update", "obj"): - continue - - if not member[-2] == "_": - name = getattr(instance, member, None) - if name is not None: - setattr(instance, member + "_b", bbones.get(name, None)) - setattr(instance, member + "_p", pbones.get(name, None)) - setattr(instance, member + "_e", ebones.get(name, None)) - - instance.update = update - + + class_dict = {"obj":obj, "update":_bone_class_instance_update} + instance = auto_class_instance(slots, name, class_dict) return instance def gen_none(obj, orig_bone_name): @@ -241,7 +240,7 @@ def write_meta_rig(obj, func_name="metarig_template"): code = [] code.append("def %s():" % func_name) - + code.append(" # generated by rigify.write_meta_rig") bpy.ops.object.mode_set(mode='EDIT') code.append(" bpy.ops.object.mode_set(mode='EDIT')") @@ -351,8 +350,8 @@ def generate_test_all(context): path_png = fn + ".png" saved = graphviz_export.graph_armature(ob, path_dot, CONSTRAINTS=True, DRIVERS=True) - if saved: - os.system("dot -Tpng %s > %s; eog %s" % (path_dot, path_png, path_png)) + #if saved: + # os.system("dot -Tpng %s > %s; eog %s" % (path_dot, path_png, path_png)) if __name__ == "__main__": |