1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
21 # Simple script to check mash validate code.
22 # XXX Should be extended with many more "wrong cases"!
69 "primitive_plane_add",
71 "primitive_circle_add",
72 "primitive_uv_sphere_add",
73 "primitive_ico_sphere_add",
74 "primitive_cylinder_add",
77 "primitive_monkey_add",
78 "primitive_torus_add",
81 BUILTINS_NBRCHANGES = 5
85 for m in MESHES["test1"]:
86 bpy.ops.object.add(type="MESH")
87 data = bpy.context.active_object.data
90 data.vertices.add(len(m[0]))
91 for idx, v in enumerate(m[0]):
92 data.vertices[idx].co = v
94 data.edges.add(len(m[1]))
95 for idx, e in enumerate(m[1]):
96 data.edges[idx].vertices = e
98 data.loops.add(len(m[2]))
99 for idx, v in enumerate(m[2]):
100 data.loops[idx].vertex_index = v
102 data.polygons.add(len(m[3]))
103 for idx, l in enumerate(m[3]):
104 data.polygons[idx].loop_start = l[0]
105 data.polygons[idx].loop_total = l[1]
107 while data.validate(verbose=True):
112 for x, func in enumerate(BUILTINS):
113 for y in range(BUILTINS_NBR):
114 getattr(bpy.ops.mesh, func)(location=(x * 2.5, y * 2.5, 0))
115 data = bpy.context.active_object.data
117 for n in range(BUILTINS_NBRCHANGES):
118 rnd = random.randint(1, 3)
120 # Make fun with some edge.
121 e = random.randrange(0, len(data.edges))
122 data.edges[e].vertices[random.randint(0, 1)] = \
123 random.randrange(0, len(data.vertices) * 2)
125 # Make fun with some loop.
126 l = random.randrange(0, len(data.loops))
127 if random.randint(0, 1):
128 data.loops[l].vertex_index = \
129 random.randrange(0, len(data.vertices) * 2)
131 data.loops[l].edge_index = \
132 random.randrange(0, len(data.edges) * 2)
134 # Make fun with some poly.
135 p = random.randrange(0, len(data.polygons))
136 if random.randint(0, 1):
137 data.polygons[p].loop_start = \
138 random.randrange(0, len(data.loops))
140 data.polygons[p].loop_total = \
141 random.randrange(0, 10)
145 while data.validate(verbose=True):
154 if __name__ == "__main__":
155 # So a python error exits(1)
160 traceback.print_exc()