[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43426] trunk/blender/source/tests/ bl_mesh_modifiers.py: update to modifier testing script

Campbell Barton ideasman42 at gmail.com
Mon Jan 16 17:16:56 CET 2012


Revision: 43426
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43426
Author:   campbellbarton
Date:     2012-01-16 16:16:55 +0000 (Mon, 16 Jan 2012)
Log Message:
-----------
update to modifier testing script

added presets for hook/decimate/build/mask

Modified Paths:
--------------
    trunk/blender/source/tests/bl_mesh_modifiers.py

Modified: trunk/blender/source/tests/bl_mesh_modifiers.py
===================================================================
--- trunk/blender/source/tests/bl_mesh_modifiers.py	2012-01-16 16:12:03 UTC (rev 43425)
+++ trunk/blender/source/tests/bl_mesh_modifiers.py	2012-01-16 16:16:55 UTC (rev 43426)
@@ -25,9 +25,14 @@
 # Later, we may have a way to check the results are valid.
 
 
-# ./blender.bin --factory-startup --python bl_mesh_modifiers.py
+# ./blender.bin --factory-startup --python source/tests/bl_mesh_modifiers.py
+#
 
+import math
 
+USE_QUICK_RENDER = False
+
+
 # -----------------------------------------------------------------------------
 # utility funcs
 
@@ -45,6 +50,7 @@
     render = scene.render
     render.filepath = filepath
     render.image_settings.file_format = 'PNG'
+    render.image_settings.color_mode = 'RGB'
     render.use_file_extension = True
     render.use_antialiasing = False
 
@@ -60,8 +66,8 @@
 
 
     # stop to inspect!
-    # if filepath == "test_cube_shell_solidify_subsurf_ob_textured":
-    #     assert(0)
+    #~ if filepath == "test_cube_like_subsurf_single_wp_wire":
+        #~ assert(0)
 
 
 def render_gl_all_modes(context, obj, filepath=""):
@@ -79,8 +85,12 @@
     scene.tool_settings.mesh_select_mode = False, True, False
 
     # render
+    render_gl(context, filepath + "_ob_solid", shade='SOLID')
+
+    if USE_QUICK_RENDER:
+        return
+
     render_gl(context, filepath + "_ob_wire", shade='WIREFRAME')
-    render_gl(context, filepath + "_ob_solid", shade='SOLID')
     render_gl(context, filepath + "_ob_textured", shade='TEXTURED')
 
     # -------------------------------------------------------------------------
@@ -195,6 +205,11 @@
             face.use_smooth = True
 
 
+def defaults_modifier(mod):
+    mod.show_in_editmode = True
+    mod.show_on_cage = True
+
+
 # -----------------------------------------------------------------------------
 # models (utils)
 
@@ -268,34 +283,33 @@
 # -----------------------------------------------------------------------------
 # modifiers
 
-def modifier_subsurf_add(obj, levels=2):
+def modifier_subsurf_add(scene, obj, levels=2):
     mod = obj.modifiers.new(name=whoami(), type='SUBSURF')
-    mod.show_in_editmode = True
+    defaults_modifier(mod)
 
     mod.levels = levels
     mod.render_levels = levels
     return mod
 
 
-def modifier_armature_add(obj):
+def modifier_armature_add(scene, obj):
     mod = obj.modifiers.new(name=whoami(), type='ARMATURE')
-    mod.show_in_editmode = True
+    defaults_modifier(mod)
 
     arm_data = bpy.data.armatures.new(whoami())
-    arm_ob = bpy.data.objects.new(whoami(), arm_data)
+    obj_arm = bpy.data.objects.new(whoami(), arm_data)
 
-    scene = bpy.context.scene
-    scene.objects.link(arm_ob)
+    scene.objects.link(obj_arm)
 
-    arm_ob.select = True
-    scene.objects.active = arm_ob
+    obj_arm.select = True
+    scene.objects.active = obj_arm
 
     bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
     bpy.ops.object.mode_set(mode='EDIT', toggle=False)
 
     # XXX, annoying, remove bone.
     while arm_data.edit_bones:
-        arm_ob.edit_bones.remove(arm_data.edit_bones[-1])
+        obj_arm.edit_bones.remove(arm_data.edit_bones[-1])
 
     bone_a = arm_data.edit_bones.new("Bone.A")
     bone_b = arm_data.edit_bones.new("Bone.B")
@@ -310,17 +324,17 @@
     bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
 
     # 45d armature
-    arm_ob.pose.bones["Bone.B"].rotation_quaternion = 1, -0.5, 0, 0
+    obj_arm.pose.bones["Bone.B"].rotation_quaternion = 1, -0.5, 0, 0
 
     # set back to the original
     scene.objects.active = obj
 
     # display options
-    arm_ob.show_x_ray = True
+    obj_arm.show_x_ray = True
     arm_data.draw_type = 'STICK'
 
     # apply to modifier
-    mod.object = arm_ob
+    mod.object = obj_arm
 
     mesh_vgroup_add(obj, name="Bone.A", axis=0, invert=True)
     mesh_vgroup_add(obj, name="Bone.B", axis=0, invert=False)
@@ -328,22 +342,86 @@
     return mod
 
 
-def modifier_mirror_add(obj):
+def modifier_mirror_add(scene, obj):
     mod = obj.modifiers.new(name=whoami(), type='MIRROR')
-    mod.show_in_editmode = True
+    defaults_modifier(mod)
 
     return mod
 
 
-def modifier_solidify_add(obj, thickness=0.25):
+def modifier_solidify_add(scene, obj, thickness=0.25):
     mod = obj.modifiers.new(name=whoami(), type='SOLIDIFY')
-    mod.show_in_editmode = True
+    defaults_modifier(mod)
 
     mod.thickness = thickness
 
     return mod
 
 
+def modifier_hook_add(scene, obj, use_vgroup=True):
+    scene.objects.active = obj
+
+    # no nice way to add hooks from py api yet
+    # assume object mode, hook first face!
+    mesh = obj.data
+    
+    if use_vgroup:
+        for v in mesh.vertices:
+            v.select = True
+    else:
+        for v in mesh.vertices:
+            v.select = False
+        for i in mesh.faces[0].vertices:
+            mesh.vertices[i].select = True
+
+    bpy.ops.object.mode_set(mode='EDIT', toggle=False)
+    bpy.ops.object.hook_add_newob()
+    bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
+
+    # mod = obj.modifiers.new(name=whoami(), type='HOOK')
+    mod = obj.modifiers[-1]
+    defaults_modifier(mod)
+
+    obj_hook = mod.object
+    obj_hook.rotation_euler = 0, math.radians(45), 0
+    obj_hook.show_x_ray = True
+
+    if use_vgroup:
+        mod.vertex_group = obj.vertex_groups[0].name
+
+    return mod
+
+
+def modifier_decimate_add(scene, obj):
+    mod = obj.modifiers.new(name=whoami(), type='DECIMATE')
+    defaults_modifier(mod)
+
+    mod.ratio = 1 / 3
+
+    return mod
+
+
+def modifier_build_add(scene, obj):
+    mod = obj.modifiers.new(name=whoami(), type='BUILD')
+    defaults_modifier(mod)
+
+    # ensure we display some faces
+    totface = len(obj.data.faces)
+    mod.frame_start = totface // 2
+    mod.frame_duration = totface
+
+    return mod
+
+
+def modifier_mask_add(scene, obj):
+    mod = obj.modifiers.new(name=whoami(), type='MASK')
+    defaults_modifier(mod)
+
+    mod.vertex_group = obj.vertex_groups[0].name
+
+    return mod
+
+
 # -----------------------------------------------------------------------------
 # models
 
@@ -578,7 +656,23 @@
     ((modifier_mirror_add, dict()), ),
     ))
 
+global_tests.append(("hook_single",
+    ((modifier_hook_add, dict()), ),
+    ))
 
+global_tests.append(("decimate_single",
+    ((modifier_decimate_add, dict()), ),
+    ))
+
+global_tests.append(("build_single",
+    ((modifier_build_add, dict()), ),
+    ))
+
+global_tests.append(("mask_single",
+    ((modifier_mask_add, dict()), ),
+    ))
+
+
 # combinations
 global_tests.append(("mirror_subsurf",
     ((modifier_mirror_add, dict()),
@@ -591,7 +685,7 @@
     ))
 
 
-def apply_test(test, obj,
+def apply_test(test, scene, obj,
                render_func=None,
                render_args=None,
                render_kwargs=None,
@@ -600,7 +694,7 @@
     test_name, test_funcs = test
 
     for cb, kwargs in test_funcs:
-        cb(obj, **kwargs)
+        cb(scene, obj, **kwargs)
 
     render_kwargs_copy = render_kwargs.copy()
 
@@ -612,14 +706,16 @@
 
 # -----------------------------------------------------------------------------
 # tests themselves!
+# having the 'test_' prefix automatically means these functions are called
+# for testing
 
 
 def test_cube(context, test):
     scene = context.scene
     obj = make_cube_extra(scene)
-    ctx_camera_setup(context, location=(4, 4, 4))
+    ctx_camera_setup(context, location=(3, 3, 3))
 
-    apply_test(test, obj,
+    apply_test(test, scene, obj,
                render_func=render_gl_all_modes,
                render_args=(context, obj),
                render_kwargs=dict(filepath=whoami()))
@@ -630,7 +726,7 @@
     obj = make_cube_like_extra(scene)
     ctx_camera_setup(context, location=(5, 5, 5))
 
-    apply_test(test, obj,
+    apply_test(test, scene, obj,
                render_func=render_gl_all_modes,
                render_args=(context, obj),
                render_kwargs=dict(filepath=whoami()))
@@ -641,7 +737,7 @@
     obj = make_cube_shell_extra(scene)
     ctx_camera_setup(context, location=(4, 4, 4))
 
-    apply_test(test, obj,
+    apply_test(test, scene, obj,
                render_func=render_gl_all_modes,
                render_args=(context, obj),
                render_kwargs=dict(filepath=whoami()))
@@ -682,7 +778,6 @@
             bpy.app.handlers.scene_update_post.remove(load_handler)
             try:
                 main()
-
                 import sys
                 sys.exit(0)
             except:
@@ -691,6 +786,7 @@
 
                 import sys
                 # sys.exit(1)  # comment to debug
+
         else:
             load_handler.first = False
 



More information about the Bf-blender-cvs mailing list