Welcome to mirror list, hosted at ThFree Co, Russian Federation.

modifiers.py « python « tests - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 24f71c4066d858cf616038562ab9193ae9f7beea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

# <pep8 compliant>

import math
import os
import sys
from random import shuffle, seed

import bpy

sys.path.append(os.path.dirname(os.path.realpath(__file__)))
from modules.mesh_test import RunTest, ModifierSpec, MeshTest

seed(0)


def get_generate_modifiers_list(test_object_name, randomize=False):
    """
    Construct a list of 'Generate' modifiers with default parameters.
    :param test_object_name: str - name of test object. Some modifiers like boolean need an extra parameter beside
                                    the default one. E.g. boolean needs object, mask needs vertex group etc...
                                    The extra parameter name will be <test_object_name>_<modifier_type>
    :param randomize: bool - if True shuffle the list of modifiers.
    :return: list of 'Generate' modifiers with default parameters.
    """

    boolean_test_object = bpy.data.objects[test_object_name + "_boolean"]

    generate_modifiers = [
        ModifierSpec('array', 'ARRAY', {}),
        ModifierSpec('bevel', 'BEVEL', {'width': 0.1}),
        ModifierSpec('boolean', 'BOOLEAN', {'object': boolean_test_object, 'solver': 'FAST'}),
        ModifierSpec('build', 'BUILD', {'frame_start': 1, 'frame_duration': 1}, 2),
        ModifierSpec('decimate', 'DECIMATE', {}),
        ModifierSpec('edge split', 'EDGE_SPLIT', {}),

        # mask can effectively delete the mesh since the vertex group need to be updated after each
        # applied modifier. Needs to be tested separately.
        # ModifierSpec('mask', 'MASK', {'vertex_group': mask_vertex_group}, False),

        ModifierSpec('mirror', 'MIRROR', {}),
        ModifierSpec('multires', 'MULTIRES', {}),

        # remesh can also generate an empty mesh. Skip.
        # ModifierSpec('remesh', 'REMESH', {}),

        # ModifierSpec('screw', 'SCREW', {}), # screw can make the test very slow. Skipping for now.

        ModifierSpec('solidify', 'SOLIDIFY', {}),
        ModifierSpec('subsurf', 'SUBSURF', {}),
        ModifierSpec('triangulate', 'TRIANGULATE', {}),
        ModifierSpec('wireframe', 'WIREFRAME', {})

    ]

    if randomize:
        shuffle(generate_modifiers)

    return generate_modifiers


def main():
    mask_first_list = get_generate_modifiers_list("testCubeMaskFirst", randomize=True)
    mask_vertex_group = "testCubeMaskFirst" + "_mask"
    mask_first_list.insert(0, ModifierSpec('mask', 'MASK', {'vertex_group': mask_vertex_group}))

    tests = [
        ###############################
        # List of 'Generate' modifiers on a cube
        ###############################
        # 0
        # MeshTest("testCube", "expectedCube", get_generate_modifiers_list("testCube")),
        MeshTest("CubeRandom", "testCubeRandom", "expectedCubeRandom",
                 get_generate_modifiers_list("testCubeRandom", randomize=True)),
        MeshTest("CubeMaskFirst", "testCubeMaskFirst", "expectedCubeMaskFirst", mask_first_list),

        MeshTest("CollapseDecimate", "testCollapseDecimate", "expectedCollapseDecimate",
                 [ModifierSpec("subdivision", 'SUBSURF', {"levels": 2}),
                  ModifierSpec('decimate', 'DECIMATE',
                               {'decimate_type': 'COLLAPSE', 'ratio': 0.25, 'use_collapse_triangulate': True})]),
        MeshTest("PlanarDecimate", "testPlanarDecimate", "expectedPlanarDecimate",
                 [ModifierSpec("subdivision", 'SUBSURF', {"levels": 2}),
                  ModifierSpec('decimate', 'DECIMATE',
                               {'decimate_type': 'DISSOLVE', 'angle_limit': math.radians(30)})]),
        MeshTest("UnsubdivideDecimate", "testUnsubdivideDecimate", "expectedUnsubdivideDecimate",
                 [ModifierSpec("subdivision", 'SUBSURF', {"levels": 2}),
                  ModifierSpec('decimate', 'DECIMATE', {'decimate_type': 'UNSUBDIV', 'iterations': 2})]),

        # 5
        MeshTest("RadialBisectMirror", "testRadialBisectMirror", "expectedRadialBisectMirror",
                 [ModifierSpec('mirror1', 'MIRROR', {'use_bisect_axis': (True, False, False)}),
                  ModifierSpec('mirror2', 'MIRROR', {'use_bisect_axis': (True, False, False),
                                                     'mirror_object': bpy.data.objects[
                                                         "testRadialBisectMirrorHelper"]}),
                  ModifierSpec('mirror3', 'MIRROR',
                               {'use_axis': (False, True, False), 'use_bisect_axis': (False, True, False),
                                'use_bisect_flip_axis': (False, True, False),
                                'mirror_object': bpy.data.objects["testRadialBisectMirrorHelper"]})]),
        MeshTest("T58411Mirror", "regressT58411Mirror", "expectedT58411Mirror",
                 [ModifierSpec('mirror', 'MIRROR', {}),
                  ModifierSpec('bevel', 'BEVEL', {'segments': 2, 'limit_method': 'WEIGHT'}),
                  ModifierSpec('subd', 'SUBSURF', {'levels': 1})]),

        MeshTest("BasicScrew", "testBasicScrew", "expectedBasicScrew",
                 [ModifierSpec('mirror', 'MIRROR', {'mirror_object': bpy.data.objects["testBasicScrewHelper"]}),
                  ModifierSpec("screw", 'SCREW',
                               {'angle': math.radians(400), 'steps': 20, 'iterations': 2, 'screw_offset': 2,
                                'use_normal_calculate': True})]),
        MeshTest("ObjectScrew", "testObjectScrew", "expectedObjectScrew",
                 [ModifierSpec('mirror', 'MIRROR', {'mirror_object': bpy.data.objects["testObjectScrewHelper2"]}),
                  ModifierSpec("screw", 'SCREW',
                               {"angle": math.radians(600), 'steps': 32, 'iterations': 1,
                                'use_object_screw_offset': True,
                                'use_normal_calculate': True, 'object': bpy.data.objects["testObjectScrewHelper1"]})]),

        # 9
        MeshTest("MergedScrewWeld", "testMergedScrewWeld", "expectedMergedScrewWeld",
                 [ModifierSpec("screw", 'SCREW',
                               {'angle': math.radians(360), 'steps': 12, 'iterations': 1, 'screw_offset': 1,
                                'use_normal_calculate': True, 'use_merge_vertices': True}),
                  ModifierSpec("weld", 'WELD', {"merge_threshold": 0.001})]),
        MeshTest("T72380Weld", "regressT72380Weld", "expectedT72380Weld",
                 [ModifierSpec('vedit', 'VERTEX_WEIGHT_EDIT',
                               {'vertex_group': 'Group', 'use_remove': True, 'remove_threshold': 1}),
                  ModifierSpec("weld", 'WELD', {"merge_threshold": 0.2, "vertex_group": "Group"})]),
        MeshTest("T72792Weld", "regressT72792Weld", "expectedT72792Weld",
                 [ModifierSpec('array', 'ARRAY', {'fit_type': 'FIXED_COUNT', 'count': 2}),
                  ModifierSpec("weld", 'WELD', {"merge_threshold": 0.1, "vertex_group": "Group"})]),

        ############################################
        # One 'Generate' modifier on primitive meshes
        #############################################
        # 12
        MeshTest("CubeArray", "testCubeArray", "expectedCubeArray",
                 [ModifierSpec('array', 'ARRAY', {})]),
        MeshTest("CapArray", "testCapArray", "expectedCapArray",
                 [ModifierSpec('array', 'ARRAY',
                               {'fit_type': 'FIT_LENGTH', 'fit_length': 2.0,
                                'start_cap': bpy.data.objects["testCapStart"],
                                'end_cap': bpy.data.objects["testCapEnd"]})]),
        MeshTest("CurveArray", "testCurveArray", "expectedCurveArray",
                 [ModifierSpec('array', 'ARRAY',
                               {'fit_type': 'FIT_CURVE', 'curve': bpy.data.objects["testCurveArrayHelper"],
                                'use_relative_offset': False, 'use_constant_offset': True,
                                'constant_offset_displace': (0.5, 0, 0)})]),
        MeshTest("RadialArray", "testRadialArray", "expectedRadialArray",
                 [ModifierSpec('array', 'ARRAY', {'fit_type': 'FIXED_COUNT', 'count': 3, 'use_merge_vertices': True,
                                                  'use_merge_vertices_cap': True, 'use_relative_offset': False,
                                                  'use_object_offset': True,
                                                  'offset_object': bpy.data.objects["testRadialArrayHelper"]})]),

        MeshTest("CylinderBuild", "testCylinderBuild", "expectedCylinderBuild",
                 [ModifierSpec('build', 'BUILD', {'frame_start': 1, 'frame_duration': 1}, 2)]),

        # 17
        MeshTest("ConeDecimate", "testConeDecimate", "expectedConeDecimate",
                 [ModifierSpec('decimate', 'DECIMATE', {'ratio': 0.5})]),
        MeshTest("CubeEdgeSplit", "testCubeEdgeSplit", "expectedCubeEdgeSplit",
                 [ModifierSpec('edge split', 'EDGE_SPLIT', {})]),

        MeshTest("SphereMirror", "testSphereMirror", "expectedSphereMirror",
                 [ModifierSpec('mirror', 'MIRROR', {})]),
        MeshTest("LocalMirror", "testLocalMirror", "expectedLocalMirror",
                 [ModifierSpec('mirror', 'MIRROR', {'use_clip': True})]),
        MeshTest("ObjectOffsetMirror", "testObjectOffsetMirror", "expectedObjectOffsetMirror",
                 [ModifierSpec('mirror', 'MIRROR',
                               {'mirror_object': bpy.data.objects["testObjectOffsetMirrorHelper"]})]),

        MeshTest("CylinderMask", "testCylinderMask", "expectedCylinderMask",
                 [ModifierSpec('mask', 'MASK', {'vertex_group': "mask_vertex_group"})]),
        MeshTest("ConeMultiRes", "testConeMultiRes", "expectedConeMultiRes",
                 [ModifierSpec('multires', 'MULTIRES', {})]),

        # 24
        MeshTest("CubeScrew", "testCubeScrew", "expectedCubeScrew",
                 [ModifierSpec('screw', 'SCREW', {})]),

        MeshTest("CubeSolidify", "testCubeSolidify", "expectedCubeSolidify",
                 [ModifierSpec('solidify', 'SOLIDIFY', {})]),
        MeshTest("ComplexSolidify", "testComplexSolidify", "expectedComplexSolidify",
                 [ModifierSpec('solidify', 'SOLIDIFY', {'solidify_mode': 'NON_MANIFOLD', 'thickness': 0.05, 'offset': 0,
                                                        'nonmanifold_thickness_mode': 'CONSTRAINTS'})]),
        MeshTest("T63063Solidify", "regressT63063Solidify", "expectedT63063Solidify",
                 [ModifierSpec('solid', 'SOLIDIFY', {'thickness': 0.1, 'offset': 0.7})]),
        MeshTest("T61979Solidify", "regressT61979Solidify", "expectedT61979Solidify",
                 [ModifierSpec('solid', 'SOLIDIFY',
                               {'thickness': -0.25, 'use_even_offset': True, 'use_quality_normals': True})]),

        MeshTest("MonkeySubsurf", "testMonkeySubsurf", "expectedMonkeySubsurf",
                 [ModifierSpec('subsurf', 'SUBSURF', {})]),
        MeshTest("CatmullClarkSubdivisionSurface", "testCatmullClarkSubdivisionSurface",
                 "expectedCatmullClarkSubdivisionSurface",
                 [ModifierSpec("subdivision", 'SUBSURF', {"levels": 2})]),
        MeshTest("SimpleSubdivisionSurface", "testSimpleSubdivisionSurface", "expectedSimpleSubdivisionSurface",
                 [ModifierSpec("subdivision", 'SUBSURF', {"levels": 2, 'subdivision_type': 'SIMPLE'})]),
        MeshTest("Crease2dSubdivisionSurface", "testCrease2dSubdivisionSurface", "expectedCrease2dSubdivisionSurface",
                 [ModifierSpec("subdivision", 'SUBSURF', {"levels": 2})]),
        MeshTest("Crease3dSubdivisionSurface", "testCrease3dSubdivisionSurface", "expectedCrease3dSubdivisionSurface",
                 [ModifierSpec("subdivision", 'SUBSURF', {"levels": 2})]),

        # 34

        MeshTest("SphereTriangulate", "testSphereTriangulate", "expectedSphereTriangulate",
                 [ModifierSpec('triangulate', 'TRIANGULATE', {})]),
        MeshTest("MonkeyWireframe", "testMonkeyWireframe", "expectedMonkeyWireframe",
                 [ModifierSpec('wireframe', 'WIREFRAME', {})]),

        # Duplicate the object, test object and expected object have same world coordinates.
        MeshTest("Skin", "testObjPlaneSkin", "expObjPlaneSkin",
                 [ModifierSpec('skin', 'SKIN', {})]),

        MeshTest("MergedWeld", "testMergedWeld", "expectedMergedWeld",
                 [ModifierSpec("weld", 'WELD', {"merge_threshold": 0.021})]),
        MeshTest("MergedAllWeld", "testMergedAllWeld", "expectedMergedAllWeld",
                 [ModifierSpec("weld", 'WELD', {"merge_threshold": 1.8})]),
        MeshTest("MergedNoneWeld", "testMergedNoneWeld", "expectedMergedNoneWeld",
                 [ModifierSpec("weld", 'WELD', {"merge_threshold": 0.019})]),


        #############################################
        # One 'Deform' modifier on primitive meshes
        #############################################
        # 39
        MeshTest("MonkeyArmature", "testMonkeyArmature", "expectedMonkeyArmature",
                 [ModifierSpec('armature', 'ARMATURE',
                               {'object': bpy.data.objects['testArmature'], 'use_vertex_groups': True})]),
        MeshTest("TorusCast", "testTorusCast", "expectedTorusCast",
                 [ModifierSpec('cast', 'CAST', {'factor': 2.64})]),
        MeshTest("CubeCurve", "testCubeCurve", "expectedCubeCurve",
                 [ModifierSpec('curve', 'CURVE', {'object': bpy.data.objects['testBezierCurve']})]),
        MeshTest("MonkeyDisplace", "testMonkeyDisplace", "expectedMonkeyDisplace",
                 [ModifierSpec('displace', "DISPLACE", {})]),

        # Hook modifier requires moving the hook object to get a mesh change
        # so can't test it with the current framework
        # MeshTest("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
        MeshTest("CubeLattice", "testCubeLattice", "expectedCubeLattice",
                 [ModifierSpec('lattice', 'LATTICE', {'object': bpy.data.objects["testLattice"]})]),

        MeshTest("PlaneShrinkWrap", "testPlaneShrinkWrap", "expectedPlaneShrinkWrap",
                 [ModifierSpec('shrinkwrap', 'SHRINKWRAP',
                               {'target': bpy.data.objects["testCubeWrap"], 'offset': 0.5})]),

        MeshTest("CylinderSimpleDeform", "testCylinderSimpleDeform", "expectedCylinderSimpleDeform",
                 [ModifierSpec('simple_deform', 'SIMPLE_DEFORM', {'angle': math.radians(180), 'deform_axis': 'Z'})]),

        MeshTest("PlaneSmooth", "testPlaneSmooth", "expectedPlaneSmooth",
                 [ModifierSpec('smooth', 'SMOOTH', {'iterations': 11})]),

        # Smooth corrective requires a complex mesh.

        MeshTest("BalloonLaplacianSmooth", "testBalloonLaplacianSmooth", "expectedBalloonLaplacianSmooth",
                 [ModifierSpec('laplaciansmooth', 'LAPLACIANSMOOTH', {'lambda_factor': 12, 'lambda_border': 12})]),

        # Gets updated often
        MeshTest("WavePlane", "testObjPlaneWave", "expObjPlaneWave",
                 [ModifierSpec('wave', 'WAVE', {})]),

        #############################################
        # CURVES Generate Modifiers
        #############################################
        # Caution: Make sure test object has no modifier in "added" state, the test may fail.
        MeshTest("BezCurveArray", "testObjBezierCurveArray", "expObjBezierCurveArray",
                 [ModifierSpec('array', 'ARRAY', {})]),

        MeshTest("CurveBevel", "testObjBezierCurveBevel", "expObjBezierCurveBevel",
                 [ModifierSpec('bevel', 'BEVEL', {})]),

        MeshTest("CurveBuild", "testObjBezierCurveBuild", "expObjBezierCurveBuild",
                 [ModifierSpec('build', 'BUILD', {'frame_start': 1, 'frame_duration': 1}, 2)]),

        MeshTest("CurveDecimate", "testObjBezierCurveDecimate", "expObjBezierCurveDecimate",
                 [ModifierSpec('decimate', 'DECIMATE', {'ratio': 0.5})]),

        MeshTest("CurveEdgeSplit", "testObjBezierCurveEdgeSplit", "expObjBezierCurveEdgeSplit",
                 [ModifierSpec('edgeSplit', 'EDGE_SPLIT', {})]),

        MeshTest("CurveMirror", "testObjBezierCurveMirror", "expObjBezierCurveMirror",
                 [ModifierSpec('mirror', 'MIRROR', {'use_axis': (True, True, False)})]),

        MeshTest("CurveScrew", "testObjBezierCurveScrew", "expObjBezierCurveScrew",
                 [ModifierSpec('screw', 'SCREW', {})]),

        MeshTest("CurveSolidify", "testObjBezierCurveSolidify", "expObjBezierCurveSolidify",
                 [ModifierSpec('solidify', 'SOLIDIFY', {'thickness': 1})]),

        MeshTest("CurveSubSurf", "testObjBezierCurveSubSurf", "expObjBezierCurveSubSurf",
                 [ModifierSpec('subSurf', 'SUBSURF', {})]),

        MeshTest("CurveTriangulate", "testObjBezierCurveTriangulate", "expObjBezierCurveTriangulate",
                 [ModifierSpec('triangulate', 'TRIANGULATE', {})]),

        # Test 60
        # Caution Weld: if the distance is increased beyond a limit, the object disappears
        MeshTest("CurveWeld", "testObjBezierCurveWeld", "expObjBezierCurveWeld",
                 [ModifierSpec('weld', 'WELD', {})]),

        MeshTest("CurveWeld2", "testObjBezierCurveWeld2", "expObjBezierCurveWeld2",
                 [ModifierSpec('weld', 'WELD', {})]),

        #############################################
        # Curves Deform Modifiers
        #############################################
        # Test 62
        MeshTest("CurveCast", "testObjBezierCurveCast", "expObjBezierCurveCast",
                 [ModifierSpec('Cast', 'CAST', {'cast_type': 'CYLINDER', 'factor': 10})]),

        MeshTest("CurveShrinkWrap", "testObjBezierCurveShrinkWrap", "expObjBezierCurveShrinkWrap",
                 [ModifierSpec('ShrinkWrap', 'SHRINKWRAP',
                               {'target': bpy.data.objects['testShrinkWrapHelperSuzanne']})]),

        MeshTest("CurveSimpleDeform", "testObjBezierCurveSimpleDeform", "expObjBezierCurveSimpleDeform",
                 [ModifierSpec('simple_deform', 'SIMPLE_DEFORM', {'angle': math.radians(90)})]),

        MeshTest("CurveSmooth", "testObjBezierCurveSmooth", "expObjBezierCurveSmooth",
                 [ModifierSpec('smooth', 'SMOOTH', {'factor': 10})]),

        MeshTest("CurveWave", "testObjBezierCurveWave", "expObjBezierCurveWave",
                 [ModifierSpec('curve_wave', 'WAVE', {'time_offset': -1.5})]),

        MeshTest("CurveCurve", "testObjBezierCurveCurve", "expObjBezierCurveCurve",
                 [ModifierSpec('curve_Curve', 'CURVE', {'object': bpy.data.objects['NurbsCurve']})]),

    ]

    modifiers_test = RunTest(tests)

    command = list(sys.argv)
    for i, cmd in enumerate(command):
        if cmd == "--run-all-tests":
            modifiers_test.apply_modifiers = True
            modifiers_test.do_compare = True
            modifiers_test.run_all_tests()
            break
        elif cmd == "--run-test":
            modifiers_test.apply_modifiers = False
            modifiers_test.do_compare = False
            name = command[i + 1]
            modifiers_test.run_test(name)
            break


if __name__ == "__main__":
    main()