mesh validation remove duplicate faces didn't always work, now it _should_ all work...
[blender-staging.git] / release / scripts / ui / properties_data_mesh.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
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.
7 #
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.
12 #
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.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from rna_prop_ui import PropertyPanel
22
23
24 class MESH_MT_vertex_group_specials(bpy.types.Menu):
25     bl_label = "Vertex Group Specials"
26     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
27
28     def draw(self, context):
29         layout = self.layout
30
31         layout.operator("object.vertex_group_sort", icon='SORTALPHA')
32         layout.operator("object.vertex_group_copy", icon='COPY_ID')
33         layout.operator("object.vertex_group_copy_to_linked", icon='LINK_AREA')
34         layout.operator("object.vertex_group_copy_to_selected", icon='LINK_AREA')
35         layout.operator("object.vertex_group_mirror", icon='ARROW_LEFTRIGHT')
36         layout.operator("object.vertex_group_remove", icon='X', text="Delete All").all=True
37
38
39 class MESH_MT_shape_key_specials(bpy.types.Menu):
40     bl_label = "Shape Key Specials"
41     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
42
43     def draw(self, context):
44         layout = self.layout
45
46         layout.operator("object.shape_key_transfer", icon='COPY_ID')  # icon is not ideal
47         layout.operator("object.join_shapes", icon='COPY_ID')  # icon is not ideal
48         layout.operator("object.shape_key_mirror", icon='ARROW_LEFTRIGHT')
49
50
51 class MeshButtonsPanel():
52     bl_space_type = 'PROPERTIES'
53     bl_region_type = 'WINDOW'
54     bl_context = "data"
55
56     @classmethod
57     def poll(cls, context):
58         engine = context.scene.render.engine
59         return context.mesh and (engine in cls.COMPAT_ENGINES)
60
61
62 class DATA_PT_context_mesh(MeshButtonsPanel, bpy.types.Panel):
63     bl_label = ""
64     bl_options = {'HIDE_HEADER'}
65     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
66
67     def draw(self, context):
68         layout = self.layout
69
70         ob = context.object
71         mesh = context.mesh
72         space = context.space_data
73
74         if ob:
75             layout.template_ID(ob, "data")
76         elif mesh:
77             layout.template_ID(space, "pin_id")
78
79
80 class DATA_PT_normals(MeshButtonsPanel, bpy.types.Panel):
81     bl_label = "Normals"
82     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
83
84     def draw(self, context):
85         layout = self.layout
86
87         mesh = context.mesh
88
89         split = layout.split()
90
91         col = split.column()
92         col.prop(mesh, "use_auto_smooth")
93         sub = col.column()
94         sub.active = mesh.use_auto_smooth
95         sub.prop(mesh, "auto_smooth_angle", text="Angle")
96
97         col = split.column()
98
99         col.prop(mesh, "show_double_sided")
100
101
102 class DATA_PT_settings(MeshButtonsPanel, bpy.types.Panel):
103     bl_label = "Settings"
104     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
105
106     def draw(self, context):
107         layout = self.layout
108
109         mesh = context.mesh
110
111         layout.prop(mesh, "texture_mesh")
112         layout.prop(mesh, "use_auto_texspace")
113
114
115 class DATA_PT_vertex_groups(MeshButtonsPanel, bpy.types.Panel):
116     bl_label = "Vertex Groups"
117     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
118
119     @classmethod
120     def poll(cls, context):
121         engine = context.scene.render.engine
122         obj = context.object
123         return (obj and obj.type in ('MESH', 'LATTICE') and (engine in cls.COMPAT_ENGINES))
124
125     def draw(self, context):
126         layout = self.layout
127
128         ob = context.object
129         group = ob.vertex_groups.active
130
131         rows = 2
132         if group:
133             rows = 5
134
135         row = layout.row()
136         row.template_list(ob, "vertex_groups", ob.vertex_groups, "active_index", rows=rows)
137
138         col = row.column(align=True)
139         col.operator("object.vertex_group_add", icon='ZOOMIN', text="")
140         col.operator("object.vertex_group_remove", icon='ZOOMOUT', text="")
141         col.menu("MESH_MT_vertex_group_specials", icon='DOWNARROW_HLT', text="")
142         if group:
143             col.operator("object.vertex_group_move", icon='TRIA_UP', text="").direction = 'UP'
144             col.operator("object.vertex_group_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
145
146         if group:
147             row = layout.row()
148             row.prop(group, "name")
149
150         if ob.mode == 'EDIT' and len(ob.vertex_groups) > 0:
151             row = layout.row()
152
153             sub = row.row(align=True)
154             sub.operator("object.vertex_group_assign", text="Assign")
155             sub.operator("object.vertex_group_remove_from", text="Remove")
156
157             sub = row.row(align=True)
158             sub.operator("object.vertex_group_select", text="Select")
159             sub.operator("object.vertex_group_deselect", text="Deselect")
160
161             layout.prop(context.tool_settings, "vertex_group_weight", text="Weight")
162
163
164 class DATA_PT_shape_keys(MeshButtonsPanel, bpy.types.Panel):
165     bl_label = "Shape Keys"
166     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
167
168     @classmethod
169     def poll(cls, context):
170         engine = context.scene.render.engine
171         obj = context.object
172         return (obj and obj.type in ('MESH', 'LATTICE', 'CURVE', 'SURFACE') and (engine in cls.COMPAT_ENGINES))
173
174     def draw(self, context):
175         layout = self.layout
176
177         ob = context.object
178         key = ob.data.shape_keys
179         kb = ob.active_shape_key
180
181         enable_edit = ob.mode != 'EDIT'
182         enable_edit_value = False
183
184         if ob.show_only_shape_key is False:
185             if enable_edit or (ob.type == 'MESH' and ob.use_shape_key_edit_mode):
186                 enable_edit_value = True
187
188         row = layout.row()
189
190         rows = 2
191         if kb:
192             rows = 5
193         row.template_list(key, "keys", ob, "active_shape_key_index", rows=rows)
194
195         col = row.column()
196
197         sub = col.column(align=True)
198         sub.operator("object.shape_key_add", icon='ZOOMIN', text="")
199         sub.operator("object.shape_key_remove", icon='ZOOMOUT', text="")
200         sub.menu("MESH_MT_shape_key_specials", icon='DOWNARROW_HLT', text="")
201
202         if kb:
203             col.separator()
204
205             sub = col.column(align=True)
206             sub.operator("object.shape_key_move", icon='TRIA_UP', text="").type = 'UP'
207             sub.operator("object.shape_key_move", icon='TRIA_DOWN', text="").type = 'DOWN'
208
209             split = layout.split(percentage=0.4)
210             row = split.row()
211             row.enabled = enable_edit
212             row.prop(key, "use_relative")
213
214             row = split.row()
215             row.alignment = 'RIGHT'
216
217             sub = row.row(align=True)
218             subsub = sub.row(align=True)
219             subsub.active = enable_edit_value
220             subsub.prop(ob, "show_only_shape_key", text="")
221             subsub.prop(kb, "mute", text="")
222             sub.prop(ob, "use_shape_key_edit_mode", text="")
223
224             sub = row.row()
225             sub.operator("object.shape_key_clear", icon='X', text="")
226
227             row = layout.row()
228             row.prop(kb, "name")
229
230             if key.use_relative:
231                 if ob.active_shape_key_index != 0:
232                     row = layout.row()
233                     row.active = enable_edit_value
234                     row.prop(kb, "value")
235
236                     split = layout.split()
237
238                     col = split.column(align=True)
239                     col.active = enable_edit_value
240                     col.label(text="Range:")
241                     col.prop(kb, "slider_min", text="Min")
242                     col.prop(kb, "slider_max", text="Max")
243
244                     col = split.column(align=True)
245                     col.active = enable_edit_value
246                     col.label(text="Blend:")
247                     col.prop_search(kb, "vertex_group", ob, "vertex_groups", text="")
248                     col.prop_search(kb, "relative_key", key, "keys", text="")
249
250             else:
251                 row = layout.row()
252                 row.active = enable_edit_value
253                 row.prop(key, "slurph")
254
255
256 class DATA_PT_uv_texture(MeshButtonsPanel, bpy.types.Panel):
257     bl_label = "UV Texture"
258     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
259
260     def draw(self, context):
261         layout = self.layout
262
263         me = context.mesh
264
265         row = layout.row()
266         col = row.column()
267
268         col.template_list(me, "uv_textures", me.uv_textures, "active_index", rows=2)
269
270         col = row.column(align=True)
271         col.operator("mesh.uv_texture_add", icon='ZOOMIN', text="")
272         col.operator("mesh.uv_texture_remove", icon='ZOOMOUT', text="")
273
274         lay = me.uv_textures.active
275         if lay:
276             layout.prop(lay, "name")
277
278
279 class DATA_PT_texface(MeshButtonsPanel, bpy.types.Panel):
280     bl_label = "Texture Face"
281     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
282
283     @classmethod
284     def poll(cls, context):
285         ob = context.active_object
286         rd = context.scene.render
287
288         return (context.mode == 'EDIT_MESH') and ob and ob.type == 'MESH'
289
290     def draw(self, context):
291         layout = self.layout
292         col = layout.column()
293
294         me = context.mesh
295
296         tf = me.faces.active_tface
297
298         if tf:
299             if context.scene.render.engine != 'BLENDER_GAME':
300                 col.label(text="Options only supported in Game Engine")
301
302             split = layout.split()
303             col = split.column()
304
305             col.prop(tf, "use_image")
306             col.prop(tf, "use_light")
307             col.prop(tf, "hide")
308             col.prop(tf, "use_collision")
309
310             col.prop(tf, "use_blend_shared")
311             col.prop(tf, "use_twoside")
312             col.prop(tf, "use_object_color")
313
314             col = split.column()
315
316             col.prop(tf, "use_halo")
317             col.prop(tf, "use_billboard")
318             col.prop(tf, "use_shadow_cast")
319             col.prop(tf, "use_bitmap_text")
320             col.prop(tf, "use_alpha_sort")
321
322             col = layout.column()
323             col.prop(tf, "blend_type")
324         else:
325             col.label(text="No UV Texture")
326
327
328 class DATA_PT_vertex_colors(MeshButtonsPanel, bpy.types.Panel):
329     bl_label = "Vertex Colors"
330     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
331
332     def draw(self, context):
333         layout = self.layout
334
335         me = context.mesh
336
337         row = layout.row()
338         col = row.column()
339
340         col.template_list(me, "vertex_colors", me.vertex_colors, "active_index", rows=2)
341
342         col = row.column(align=True)
343         col.operator("mesh.vertex_color_add", icon='ZOOMIN', text="")
344         col.operator("mesh.vertex_color_remove", icon='ZOOMOUT', text="")
345
346         lay = me.vertex_colors.active
347         if lay:
348             layout.prop(lay, "name")
349
350
351 class DATA_PT_custom_props_mesh(MeshButtonsPanel, PropertyPanel, bpy.types.Panel):
352     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
353     _context_path = "object.data"
354     _property_type = bpy.types.Mesh
355
356
357 def register():
358     pass
359
360
361 def unregister():
362     pass
363
364 if __name__ == "__main__":
365     register()