[Bf-blender-cvs] [59c817bf8a7] soc-2020-testing-frameworks: Added Object operator class and DeformModifierSpec class, check for unique name for operators

calra123 noreply at git.blender.org
Thu Jul 9 19:39:13 CEST 2020


Commit: 59c817bf8a72e95f23c8262e3e436bee6bf4e828
Author: calra123
Date:   Sun Jun 28 22:12:55 2020 +0530
Branches: soc-2020-testing-frameworks
https://developer.blender.org/rB59c817bf8a72e95f23c8262e3e436bee6bf4e828

Added Object operator class and DeformModifierSpec class, check for
unique name for operators

===================================================================

A	tests/python/deform_modifiers.py
M	tests/python/modifiers.py
M	tests/python/modules/mesh_test.py
M	tests/python/modules/test_object_generator.py

===================================================================

diff --git a/tests/python/deform_modifiers.py b/tests/python/deform_modifiers.py
new file mode 100644
index 00000000000..d0277f4b498
--- /dev/null
+++ b/tests/python/deform_modifiers.py
@@ -0,0 +1,58 @@
+import os
+import sys
+import bpy
+
+sys.path.append(os.path.dirname(os.path.realpath(__file__)))
+from modules.mesh_test import MeshTest, ModifierSpec, ObjectOperatorSpec, DeformModifierSpec
+
+tests = [
+
+    # Surface Deform Test, finally can bind to the Target object.
+    # Actual deformation occurs by animating imitating user input.
+
+    MeshTest("SurfaceDeform", "testObjMonkeySurfaceDeform", "expObjMonkeySurfaceDeform",
+             [DeformModifierSpec(10, [ModifierSpec('surface_deform', 'SURFACE_DEFORM', {'target': bpy.data.objects["Cube"]})],
+              ObjectOperatorSpec('surfacedeform_bind', {'modifier': 'surface_deform'}))], True, True),
+
+    # Mesh Deform Test, finally can bind to the Target object.
+    # Actual deformation occurs by animating imitating user input.
+
+    MeshTest("MeshDeform", "testObjMonkeyMeshDeform", "expObjMonkeyMeshDeform",
+             [DeformModifierSpec(10, [ModifierSpec('mesh_deform', 'MESH_DEFORM', {'object': bpy.data.objects["MeshCube"],
+                                                                                 'precision': 2})],
+                                 ObjectOperatorSpec('meshdeform_bind', {'modifier': 'mesh_deform'}))], True, True),
+
+
+    # Surface Deform Test, finally can bind to the Target object.
+    # Actual deformation occurs by animating imitating user input.
+
+    MeshTest("Hook", "testObjHookPlane", "expObjHookPlane",
+             [DeformModifierSpec(10, [ModifierSpec('hook', 'HOOK',
+                                                  {'object': bpy.data.objects["Empty"], 'falloff_radius': 1,
+                                                   'vertex_group': 'Group'})])], True, True),
+
+
+    # Laplacian Deform Test, first a hook is attached.
+
+    MeshTest("Laplace", "testObjCubeLaplacian", "expObjCubeLaplacian",
+             [DeformModifierSpec(10,
+                                 [ModifierSpec('hook2', 'HOOK', {'object': bpy.data.objects["Empty.001"],
+                                                                'vertex_group': 'hook_vg'}),
+                                 ModifierSpec('laplace', 'LAPLACIANDEFORM', {'vertex_group': 'laplace_vg'})],
+                                 ObjectOperatorSpec('laplaciandeform_bind', {'modifier':'laplace'}))], True, True),
+
+
+    MeshTest("WarpPlane", "testObjPlaneWarp", "expObjPlaneWarp",
+             [DeformModifierSpec(10, [ModifierSpec('warp', 'WARP',
+                                                   {'object_from': bpy.data.objects["From"], 'object_to': bpy.data.objects["To"],
+                                                    })])], True, True),
+
+
+
+]
+command = list(sys.argv)
+for i, cmd in enumerate(command):
+    if cmd == "--run-all-tests":
+        for mesh_test in tests:
+            mesh_test.run_test()
+        break
diff --git a/tests/python/modifiers.py b/tests/python/modifiers.py
index ecd91259556..ee68b9d385e 100644
--- a/tests/python/modifiers.py
+++ b/tests/python/modifiers.py
@@ -241,8 +241,8 @@ def main():
 
         # Hook modifier requires moving the hook object to get a mesh change
         # so can't test it with the current framework
-        ["MonkeyHook", "testMonkeyHook", "expectedMonkeyHook",
-         [ModifierSpec('hook', 'HOOK', {'object': bpy.data.objects["EmptyHook"], 'vertex_group': "HookVertexGroup"})]],
+        # ["MonkeyHook", "testMonkeyHook", "expectedMonkeyHook",
+        #  [ModifierSpec('hook', 'HOOK', {'object': bpy.data.objects["EmptyHook"], 'vertex_group': "HookVertexGroup"})]],
 
         # 43
         # ModifierSpec('laplacian_deform', 'LAPLACIANDEFORM', {}) Laplacian requires a more complex mesh
diff --git a/tests/python/modules/mesh_test.py b/tests/python/modules/mesh_test.py
index 88610626ce8..b7686e78fe6 100644
--- a/tests/python/modules/mesh_test.py
+++ b/tests/python/modules/mesh_test.py
@@ -95,6 +95,7 @@ class PhysicsSpec:
         return "Physics Modifier: " + self.modifier_name + " of type " + self.modifier_type + \
                " with parameters: " + str(self.modifier_parameters) + " with frame end: " + str(self.frame_end)
 
+
 class OperatorSpec:
     """
     Holds one operator and its parameters.
@@ -120,6 +121,43 @@ class OperatorSpec:
                " in selection mode: " + self.select_mode + ", selecting " + str(self.selection)
 
 
+class ObjectOperatorSpec:
+    """
+    Holds an object operator and its parameters.
+    """
+
+    def __init__(self, operator_name: str, operator_parameters: dict):
+        """
+        Constructs an Object Operator spec
+        :param operator_name: str - name of the object operator from bpy.ops.object, e.g. "shade_smooth" or "shape_keys"
+        :param operator_parameters: dict - contains operator parameters.
+        """
+        self.operator_name = operator_name
+        self.operator_parameters = operator_parameters
+
+    def __str__(self):
+        return "Operator: " + self.operator_name + " with parameters: " + str(self.operator_parameters)
+
+
+class DeformModifierSpec:
+    """
+    Holds a modifier and object operator.
+    """
+    def __init__(self, frame_number: int, modifier_list: list, obj_operator_spec: ObjectOperatorSpec = None):
+        """
+        Constructs a Deform Modifier spec (for user input)
+        :param frame_number: int - the frame at which animated keyframe is inserted
+        :param modifier_spec: ModifierSpec - contains modifiers
+        :param obj_operator_spec: ObjectOperatorSpec - contains object operators
+        """
+        self.frame_number = frame_number
+        self.modifier_list = modifier_list
+        self.obj_operator_spec = obj_operator_spec
+
+    def __str__(self):
+        return "Modifier: " + str(self.modifier_list) + " with object operator " + str(self.obj_operator_spec)
+
+
 class MeshTest:
     """
     A mesh testing class targeted at testing modifiers and operators on a single object.
@@ -127,7 +165,7 @@ class MeshTest:
     the public method run_test().
     """
 
-    def __init__(self, test_name: str, test_object_name: str, expected_object_name: str, operations_stack=None, apply_modifiers=False, threshold=None):
+    def __init__(self, test_name: str, test_object_name: str, expected_object_name: str, operations_stack=None, apply_modifiers=False, apply_object_operator=False, threshold=None):
         """
         Constructs a MeshTest object. Raises a KeyError if objects with names expected_object_name
         or test_object_name don't exist.
@@ -142,12 +180,15 @@ class MeshTest:
         if operations_stack is None:
             operations_stack = []
         for operation in operations_stack:
-            if not (isinstance(operation, ModifierSpec) or isinstance(operation, OperatorSpec)):
+            if not (isinstance(operation, ModifierSpec) or isinstance(operation, OperatorSpec) or isinstance(operation, PhysicsSpec)
+                    or isinstance(operation, ObjectOperatorSpec) or isinstance(operation, DeformModifierSpec)):
                 raise ValueError("Expected operation of type {} or {}. Got {}".
-                                 format(type(ModifierSpec), type(OperatorSpec),
+                                 format(type(ModifierSpec), type(OperatorSpec), type(PhysicsSpec),
+                                        type(ObjectOperatorSpec), type(DeformModifierSpec),
                                         type(operation)))
         self.operations_stack = operations_stack
         self.apply_modifier = apply_modifiers
+        self.apply_object_operator = apply_object_operator
         self.threshold = threshold
         self.test_name = test_name
 
@@ -233,7 +274,7 @@ class MeshTest:
         """
         return self._test_updated
 
-    def _apply_modifier(self, test_object, modifier_spec: ModifierSpec):
+    def _add_modifier(self, test_object, modifier_spec: ModifierSpec):
         """
         Add modifier to object and apply (if modifier_spec.apply_modifier is True)
         :param test_object: bpy.types.Object - Blender object to apply modifier on.
@@ -258,7 +299,11 @@ class MeshTest:
                                      format(modifier_spec.modifier_type, param_name))
 
         if self.apply_modifier:
-            bpy.ops.object.modifier_apply(modifier=modifier_spec.modifier_name)
+            if not self.apply_object_operator:
+                self._apply_modifier(modifier_spec.modifier_name)
+
+    def _apply_modifier(self, modifier_name):
+        bpy.ops.object.modifier_apply(modifier=modifier_name)
 
     def _bake_current_simulation(self, obj, test_mod_type, test_mod_name, frame_end):
         for scene in bpy.data.scenes:
@@ -339,6 +384,50 @@ class MeshTest:
 
         bpy.ops.object.mode_set(mode='OBJECT')
 
+    def _apply_object_operator(self, operator: ObjectOperatorSpec):
+        """
+        Applies the operator of the modifier.
+        """
+        bpy.ops.object.mode_set(mode='OBJECT')
+        object_operator = getattr(bpy.ops.object, operator.operator_name)
+        retval = object_operator(**operator.operator_parameters)
+        print(retval)
+        if not object_operator:
+            raise AttributeError("No object operator {} found!".format(operator.operator_name))
+
+        # # Modifier name should be passed to the "modifier_apply" function,
+        # # since this is an operator of the modifier itself, the parameters are the same.
+        # if self.apply_object_operator:
+        #     bpy.ops.object.modifier_apply(**operator.operator_parameters)
+
+        if retval != {'FINISHED'}:
+            raise RuntimeError("Unexpected operator return value: {}".format(retval))
+        if self.verbose:
+            print("Applied operator {}".format(operator))
+
+    def _apply_modifier_operator(self, test_object, operation):
+
+        scene = bpy.context.scene
+        scene.frame_set(1)
+        bpy.ops.object.mode_set(mode='OBJECT')
+        mod_ops_list = operation.modifier_list
+        modifier_names = []
+        ops_ops = operation.obj_operator_spec
+        for mod_ops 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list