diff --git a/release/scripts/modules/rigify/__init__.py b/release/scripts/modules/rigify/__init__.py index 8c0643769c3..7ef5f7f5dc6 100644 --- a/release/scripts/modules/rigify/__init__.py +++ b/release/scripts/modules/rigify/__init__.py @@ -226,10 +226,13 @@ def generate_rig(context, ob): # context.scene.update() # Only for demo'ing - ob.restrict_view = True + + # ob.restrict_view = True ob_new.data.draw_axes = False context.user_preferences.edit.global_undo = global_undo + + return ob_new def write_meta_rig(obj, func_name="metarig_template"): @@ -291,5 +294,67 @@ def write_meta_rig(obj, func_name="metarig_template"): return "\n".join(code) +def generate_test(context): + import os + new_objects = [] + + scene = context.scene + def create_empty_armature(name): + ob_new = bpy.data.add_object('ARMATURE', name) + armature = bpy.data.add_armature(name) + ob_new.data = armature + scene.objects.link(ob_new) + scene.objects.active = ob_new + + print(os.path.basename(__file__)) + files = os.listdir(os.path.dirname(__file__)) + for f in files: + if f.startswith("_"): + continue + + if not f.endswith(".py"): + continue + + module_name = f[:-3] + submodule = __import__(name="%s.%s" % (__package__, module_name), fromlist=[module_name]) + + metarig_template = getattr(submodule, "metarig_template", None) + + if metarig_template: + create_empty_armature("meta_" + module_name) # sets active + metarig_template() + ob = context.object + ob_new = generate_rig(context, ob) + + new_objects.append((ob, ob_new)) + else: + print("note: rig type '%s' has no metarig_template(), can't test this", module_name) + + return new_objects + +def generate_test_all(context): + import rigify + import graphviz_export + import os + reload(rigify) + reload(graphviz_export) + + new_objects = rigify.generate_test(context) + + base_name = os.path.splitext(bpy.data.filename)[0] + for obj, obj_new in new_objects: + + for ob in (obj, obj_new): + fn = base_name + "-" + bpy.utils.clean_name(ob.name) + + path_dot = fn + ".dot" + 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 __name__ == "__main__": generate_rig(bpy.context, bpy.context.object) + diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c index 379cf75d450..70dab957fb9 100644 --- a/source/blender/makesrna/intern/rna_main_api.c +++ b/source/blender/makesrna/intern/rna_main_api.c @@ -33,21 +33,22 @@ #include "RNA_types.h" #include "RNA_enum_types.h" -#include "DNA_object_types.h" -#include "DNA_material_types.h" -#include "DNA_mesh_types.h" - #ifdef RNA_RUNTIME #include "BKE_main.h" #include "BKE_mesh.h" +#include "BKE_armature.h" #include "BKE_library.h" #include "BKE_object.h" #include "BKE_material.h" #include "BKE_image.h" #include "BKE_texture.h" +#include "DNA_armature_types.h" #include "DNA_lamp_types.h" +#include "DNA_material_types.h" +#include "DNA_mesh_types.h" +#include "DNA_object_types.h" static Mesh *rna_Main_add_mesh(Main *main, char *name) { @@ -66,6 +67,23 @@ static void rna_Main_remove_mesh(Main *main, ReportList *reports, Mesh *me) /* XXX python now has invalid pointer? */ } +static void rna_Main_remove_armature(Main *main, ReportList *reports, bArmature *arm) +{ + if(arm->id.us == 0) + free_libblock(&main->armature, arm); + else + BKE_report(reports, RPT_ERROR, "Armature must have zero users to be removed."); + + /* XXX python now has invalid pointer? */ +} + +static bArmature *rna_Main_add_armature(Main *main, char *name) +{ + bArmature *arm= add_armature(name); + arm->id.us--; + return arm; +} + static Lamp *rna_Main_add_lamp(Main *main, char *name) { Lamp *la= add_lamp(name); @@ -164,6 +182,19 @@ void RNA_api_main(StructRNA *srna) parm= RNA_def_pointer(func, "mesh", "Mesh", "", "Mesh to remove."); RNA_def_property_flag(parm, PROP_REQUIRED); + func= RNA_def_function(srna, "add_armature", "rna_Main_add_armature"); + RNA_def_function_ui_description(func, "Add a new armature."); + parm= RNA_def_string(func, "name", "Armature", 0, "", "New name for the datablock."); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_pointer(func, "armature", "Armature", "", "New armature."); + RNA_def_function_return(func, parm); + + func= RNA_def_function(srna, "remove_armature", "rna_Main_remove_armature"); + RNA_def_function_flag(func, FUNC_USE_REPORTS); + RNA_def_function_ui_description(func, "Remove an armature if it has zero users."); + parm= RNA_def_pointer(func, "armature", "Armature", "", "Armature to remove."); + RNA_def_property_flag(parm, PROP_REQUIRED); + func= RNA_def_function(srna, "add_lamp", "rna_Main_add_lamp"); RNA_def_function_ui_description(func, "Add a new lamp."); parm= RNA_def_string(func, "name", "Lamp", 0, "", "New name for the datablock.");