UI: rename "OpenGL" render engine to "Workbench".
[blender.git] / release / scripts / startup / bl_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 bpy.types import Menu, Panel, UIList
22 from rna_prop_ui import PropertyPanel
23
24
25 class MESH_MT_vertex_group_specials(Menu):
26     bl_label = "Vertex Group Specials"
27
28     def draw(self, context):
29         layout = self.layout
30
31         layout.operator("object.vertex_group_sort", icon='SORTALPHA', text="Sort by Name").sort_type = 'NAME'
32         layout.operator("object.vertex_group_sort", icon='BONE_DATA', text="Sort by Bone Hierarchy").sort_type = 'BONE_HIERARCHY'
33         layout.separator()
34         layout.operator("object.vertex_group_copy", icon='DUPLICATE')
35         layout.operator("object.vertex_group_copy_to_linked")
36         layout.operator("object.vertex_group_copy_to_selected")
37         layout.separator()
38         layout.operator("object.vertex_group_mirror", icon='ARROW_LEFTRIGHT').use_topology = False
39         layout.operator("object.vertex_group_mirror", text="Mirror Vertex Group (Topology)").use_topology = True
40         layout.separator()
41         layout.operator("object.vertex_group_remove_from", icon='X', text="Remove from All Groups").use_all_groups = True
42         layout.operator("object.vertex_group_remove_from", text="Clear Active Group").use_all_verts = True
43         layout.operator("object.vertex_group_remove", text="Delete All Unlocked Groups").all_unlocked = True
44         layout.operator("object.vertex_group_remove", text="Delete All Groups").all = True
45         layout.separator()
46         layout.operator("object.vertex_group_lock", icon='LOCKED', text="Lock All").action = 'LOCK'
47         layout.operator("object.vertex_group_lock", icon='UNLOCKED', text="UnLock All").action = 'UNLOCK'
48         layout.operator("object.vertex_group_lock", text="Lock Invert All").action = 'INVERT'
49
50
51 class MESH_MT_shape_key_specials(Menu):
52     bl_label = "Shape Key Specials"
53
54     def draw(self, context):
55         layout = self.layout
56
57         layout.operator("object.shape_key_add", icon='ADD', text="New Shape From Mix").from_mix = True
58         layout.separator()
59         layout.operator("object.shape_key_mirror", icon='ARROW_LEFTRIGHT').use_topology = False
60         layout.operator("object.shape_key_mirror", text="Mirror Shape Key (Topology)").use_topology = True
61         layout.separator()
62         layout.operator("object.join_shapes")
63         layout.operator("object.shape_key_transfer")
64         layout.separator()
65         layout.operator("object.shape_key_remove", icon='X', text="Delete All Shape Keys").all = True
66         layout.separator()
67         layout.operator("object.shape_key_move", icon='TRIA_UP_BAR', text="Move To Top").type = 'TOP'
68         layout.operator("object.shape_key_move", icon='TRIA_DOWN_BAR', text="Move To Bottom").type = 'BOTTOM'
69
70
71 class MESH_UL_vgroups(UIList):
72     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
73         # assert(isinstance(item, bpy.types.VertexGroup))
74         vgroup = item
75         if self.layout_type in {'DEFAULT', 'COMPACT'}:
76             layout.prop(vgroup, "name", text="", emboss=False, icon_value=icon)
77             icon = 'LOCKED' if vgroup.lock_weight else 'UNLOCKED'
78             layout.prop(vgroup, "lock_weight", text="", icon=icon, emboss=False)
79         elif self.layout_type == 'GRID':
80             layout.alignment = 'CENTER'
81             layout.label(text="", icon_value=icon)
82
83
84 class MESH_UL_fmaps(UIList):
85     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
86         # assert(isinstance(item, bpy.types.FaceMap))
87         fmap = item
88         if self.layout_type in {'DEFAULT', 'COMPACT'}:
89             layout.prop(fmap, "name", text="", emboss=False, icon='FACE_MAPS')
90         elif self.layout_type in {'GRID'}:
91             layout.alignment = 'CENTER'
92             layout.label(text="", icon_value=icon)
93
94
95 class MESH_UL_shape_keys(UIList):
96     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
97         # assert(isinstance(item, bpy.types.ShapeKey))
98         obj = active_data
99         # key = data
100         key_block = item
101         if self.layout_type in {'DEFAULT', 'COMPACT'}:
102             split = layout.split(factor=0.66, align=False)
103             split.prop(key_block, "name", text="", emboss=False, icon_value=icon)
104             row = split.row(align=True)
105             if key_block.mute or (obj.mode == 'EDIT' and not (obj.use_shape_key_edit_mode and obj.type == 'MESH')):
106                 row.active = False
107             if not item.id_data.use_relative:
108                 row.prop(key_block, "frame", text="", emboss=False)
109             elif index > 0:
110                 row.prop(key_block, "value", text="", emboss=False)
111             else:
112                 row.label(text="")
113             row.prop(key_block, "mute", text="", emboss=False)
114         elif self.layout_type == 'GRID':
115             layout.alignment = 'CENTER'
116             layout.label(text="", icon_value=icon)
117
118
119 class MESH_UL_uvmaps(UIList):
120     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
121         # assert(isinstance(item, (bpy.types.MeshTexturePolyLayer, bpy.types.MeshLoopColorLayer)))
122         if self.layout_type in {'DEFAULT', 'COMPACT'}:
123             layout.prop(item, "name", text="", emboss=False, icon='GROUP_UVS')
124             icon = 'RESTRICT_RENDER_OFF' if item.active_render else 'RESTRICT_RENDER_ON'
125             layout.prop(item, "active_render", text="", icon=icon, emboss=False)
126         elif self.layout_type == 'GRID':
127             layout.alignment = 'CENTER'
128             layout.label(text="", icon_value=icon)
129
130
131 class MESH_UL_vcols(UIList):
132     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
133         # assert(isinstance(item, (bpy.types.MeshTexturePolyLayer, bpy.types.MeshLoopColorLayer)))
134         if self.layout_type in {'DEFAULT', 'COMPACT'}:
135             layout.prop(item, "name", text="", emboss=False, icon='GROUP_VCOL')
136             icon = 'RESTRICT_RENDER_OFF' if item.active_render else 'RESTRICT_RENDER_ON'
137             layout.prop(item, "active_render", text="", icon=icon, emboss=False)
138         elif self.layout_type == 'GRID':
139             layout.alignment = 'CENTER'
140             layout.label(text="", icon_value=icon)
141
142
143 class MeshButtonsPanel:
144     bl_space_type = 'PROPERTIES'
145     bl_region_type = 'WINDOW'
146     bl_context = "data"
147
148     @classmethod
149     def poll(cls, context):
150         engine = context.engine
151         return context.mesh and (engine in cls.COMPAT_ENGINES)
152
153
154 class DATA_PT_context_mesh(MeshButtonsPanel, Panel):
155     bl_label = ""
156     bl_options = {'HIDE_HEADER'}
157     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
158
159     def draw(self, context):
160         layout = self.layout
161
162         ob = context.object
163         mesh = context.mesh
164         space = context.space_data
165
166         if ob:
167             layout.template_ID(ob, "data")
168         elif mesh:
169             layout.template_ID(space, "pin_id")
170
171
172 class DATA_PT_normals(MeshButtonsPanel, Panel):
173     bl_label = "Normals"
174     bl_options = {'DEFAULT_CLOSED'}
175     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
176
177     def draw(self, context):
178         layout = self.layout
179         layout.use_property_split = True
180
181         mesh = context.mesh
182
183         col = layout.column()
184         col.prop(mesh, "show_double_sided")
185
186         col.prop(mesh, "use_auto_smooth")
187         sub = col.column()
188         sub.active = mesh.use_auto_smooth and not mesh.has_custom_normals
189         sub.prop(mesh, "auto_smooth_angle", text="Angle")
190
191
192 class DATA_PT_texture_space(MeshButtonsPanel, Panel):
193     bl_label = "Texture Space"
194     bl_options = {'DEFAULT_CLOSED'}
195     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
196
197     def draw(self, context):
198         layout = self.layout
199         layout.use_property_split = True
200
201         mesh = context.mesh
202
203         layout.prop(mesh, "texture_mesh")
204
205         layout.separator()
206
207         layout.prop(mesh, "use_auto_texspace")
208
209         layout.prop(mesh, "texspace_location", text="Location")
210         layout.prop(mesh, "texspace_size", text="Size")
211
212
213 class DATA_PT_vertex_groups(MeshButtonsPanel, Panel):
214     bl_label = "Vertex Groups"
215     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
216
217     @classmethod
218     def poll(cls, context):
219         engine = context.engine
220         obj = context.object
221         return (obj and obj.type in {'MESH', 'LATTICE'} and (engine in cls.COMPAT_ENGINES))
222
223     def draw(self, context):
224         layout = self.layout
225
226         ob = context.object
227         group = ob.vertex_groups.active
228
229         rows = 3
230         if group:
231             rows = 5
232
233         row = layout.row()
234         row.template_list("MESH_UL_vgroups", "", ob, "vertex_groups", ob.vertex_groups, "active_index", rows=rows)
235
236         col = row.column(align=True)
237
238         col.operator("object.vertex_group_add", icon='ADD', text="")
239         props = col.operator("object.vertex_group_remove", icon='REMOVE', text="")
240         props.all_unlocked = props.all = False
241
242         col.separator()
243
244         col.menu("MESH_MT_vertex_group_specials", icon='DOWNARROW_HLT', text="")
245
246         if group:
247             col.separator()
248             col.operator("object.vertex_group_move", icon='TRIA_UP', text="").direction = 'UP'
249             col.operator("object.vertex_group_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
250
251         if ob.vertex_groups and (ob.mode == 'EDIT' or (ob.mode == 'WEIGHT_PAINT' and ob.type == 'MESH' and ob.data.use_paint_mask_vertex)):
252             row = layout.row()
253
254             sub = row.row(align=True)
255             sub.operator("object.vertex_group_assign", text="Assign")
256             sub.operator("object.vertex_group_remove_from", text="Remove")
257
258             sub = row.row(align=True)
259             sub.operator("object.vertex_group_select", text="Select")
260             sub.operator("object.vertex_group_deselect", text="Deselect")
261
262             layout.prop(context.tool_settings, "vertex_group_weight", text="Weight")
263
264
265 class DATA_PT_face_maps(MeshButtonsPanel, Panel):
266     bl_label = "Face Maps"
267     bl_options = {'DEFAULT_CLOSED'}
268     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
269
270     @classmethod
271     def poll(cls, context):
272         obj = context.object
273         return (obj and obj.type == 'MESH')
274
275     def draw(self, context):
276         layout = self.layout
277
278         ob = context.object
279         facemap = ob.face_maps.active
280
281         rows = 2
282         if facemap:
283             rows = 4
284
285         row = layout.row()
286         row.template_list("MESH_UL_fmaps", "", ob, "face_maps", ob.face_maps, "active_index", rows=rows)
287
288         col = row.column(align=True)
289         col.operator("object.face_map_add", icon='ADD', text="")
290         col.operator("object.face_map_remove", icon='REMOVE', text="")
291
292         if facemap:
293             col.separator()
294             col.operator("object.face_map_move", icon='TRIA_UP', text="").direction = 'UP'
295             col.operator("object.face_map_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
296
297         if ob.face_maps and (ob.mode == 'EDIT' and ob.type == 'MESH'):
298             row = layout.row()
299
300             sub = row.row(align=True)
301             sub.operator("object.face_map_assign", text="Assign")
302             sub.operator("object.face_map_remove_from", text="Remove")
303
304             sub = row.row(align=True)
305             sub.operator("object.face_map_select", text="Select")
306             sub.operator("object.face_map_deselect", text="Deselect")
307
308
309 class DATA_PT_shape_keys(MeshButtonsPanel, Panel):
310     bl_label = "Shape Keys"
311     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
312
313     @classmethod
314     def poll(cls, context):
315         engine = context.engine
316         obj = context.object
317         return (obj and obj.type in {'MESH', 'LATTICE', 'CURVE', 'SURFACE'} and (engine in cls.COMPAT_ENGINES))
318
319     def draw(self, context):
320         layout = self.layout
321
322         ob = context.object
323         key = ob.data.shape_keys
324         kb = ob.active_shape_key
325
326         enable_edit = ob.mode != 'EDIT'
327         enable_edit_value = False
328
329         if ob.show_only_shape_key is False:
330             if enable_edit or (ob.type == 'MESH' and ob.use_shape_key_edit_mode):
331                 enable_edit_value = True
332
333         row = layout.row()
334
335         rows = 3
336         if kb:
337             rows = 5
338
339         row.template_list("MESH_UL_shape_keys", "", key, "key_blocks", ob, "active_shape_key_index", rows=rows)
340
341         col = row.column(align=True)
342
343         col.operator("object.shape_key_add", icon='ADD', text="").from_mix = False
344         col.operator("object.shape_key_remove", icon='REMOVE', text="").all = False
345
346         col.separator()
347
348         col.menu("MESH_MT_shape_key_specials", icon='DOWNARROW_HLT', text="")
349
350         if kb:
351             col.separator()
352
353             sub = col.column(align=True)
354             sub.operator("object.shape_key_move", icon='TRIA_UP', text="").type = 'UP'
355             sub.operator("object.shape_key_move", icon='TRIA_DOWN', text="").type = 'DOWN'
356
357             split = layout.split(factor=0.4)
358             row = split.row()
359             row.enabled = enable_edit
360             row.prop(key, "use_relative")
361
362             row = split.row()
363             row.alignment = 'RIGHT'
364
365             sub = row.row(align=True)
366             sub.label()  # XXX, for alignment only
367             subsub = sub.row(align=True)
368             subsub.active = enable_edit_value
369             subsub.prop(ob, "show_only_shape_key", text="")
370             sub.prop(ob, "use_shape_key_edit_mode", text="")
371
372             sub = row.row()
373             if key.use_relative:
374                 sub.operator("object.shape_key_clear", icon='X', text="")
375             else:
376                 sub.operator("object.shape_key_retime", icon='RECOVER_LAST', text="")
377
378             if key.use_relative:
379                 if ob.active_shape_key_index != 0:
380                     layout.use_property_split = True
381
382                     row = layout.row()
383                     row.active = enable_edit_value
384                     row.prop(kb, "value")
385
386                     col = layout.column()
387                     sub.active = enable_edit_value
388                     sub = col.column(align=True)
389                     sub.prop(kb, "slider_min", text="Range Min")
390                     sub.prop(kb, "slider_max", text="Max")
391
392                     col.prop_search(kb, "vertex_group", ob, "vertex_groups", text="Vertex Group")
393                     col.prop_search(kb, "relative_key", key, "key_blocks", text="Relative To")
394
395             else:
396                 layout.prop(kb, "interpolation")
397                 row = layout.column()
398                 row.active = enable_edit_value
399                 row.prop(key, "eval_time")
400
401
402 class DATA_PT_uv_texture(MeshButtonsPanel, Panel):
403     bl_label = "UV Maps"
404     bl_options = {'DEFAULT_CLOSED'}
405     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
406
407     def draw(self, context):
408         layout = self.layout
409
410         me = context.mesh
411
412         row = layout.row()
413         col = row.column()
414
415         col.template_list("MESH_UL_uvmaps", "uvmaps", me, "uv_layers", me.uv_layers, "active_index", rows=2)
416
417         col = row.column(align=True)
418         col.operator("mesh.uv_texture_add", icon='ADD', text="")
419         col.operator("mesh.uv_texture_remove", icon='REMOVE', text="")
420
421
422 class DATA_PT_vertex_colors(MeshButtonsPanel, Panel):
423     bl_label = "Vertex Colors"
424     bl_options = {'DEFAULT_CLOSED'}
425     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
426
427     def draw(self, context):
428         layout = self.layout
429
430         me = context.mesh
431
432         row = layout.row()
433         col = row.column()
434
435         col.template_list("MESH_UL_vcols", "vcols", me, "vertex_colors", me.vertex_colors, "active_index", rows=2)
436
437         col = row.column(align=True)
438         col.operator("mesh.vertex_color_add", icon='ADD', text="")
439         col.operator("mesh.vertex_color_remove", icon='REMOVE', text="")
440
441
442 class DATA_PT_customdata(MeshButtonsPanel, Panel):
443     bl_label = "Geometry Data"
444     bl_options = {'DEFAULT_CLOSED'}
445     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
446
447     def draw(self, context):
448         layout = self.layout
449         layout.use_property_split = True
450
451         obj = context.object
452         me = context.mesh
453         col = layout.column()
454
455         col.operator("mesh.customdata_mask_clear", icon='X')
456         col.operator("mesh.customdata_skin_clear", icon='X')
457
458         if me.has_custom_normals:
459             col.operator("mesh.customdata_custom_splitnormals_clear", icon='X')
460         else:
461             col.operator("mesh.customdata_custom_splitnormals_add", icon='ADD')
462
463         col = layout.column()
464
465         col.enabled = (obj.mode != 'EDIT')
466         col.prop(me, "use_customdata_vertex_bevel")
467         col.prop(me, "use_customdata_edge_bevel")
468         col.prop(me, "use_customdata_edge_crease")
469
470
471 class DATA_PT_custom_props_mesh(MeshButtonsPanel, PropertyPanel, Panel):
472     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
473     _context_path = "object.data"
474     _property_type = bpy.types.Mesh
475
476
477 classes = (
478     MESH_MT_vertex_group_specials,
479     MESH_MT_shape_key_specials,
480     MESH_UL_vgroups,
481     MESH_UL_fmaps,
482     MESH_UL_shape_keys,
483     MESH_UL_uvmaps,
484     MESH_UL_vcols,
485     DATA_PT_context_mesh,
486     DATA_PT_vertex_groups,
487     DATA_PT_shape_keys,
488     DATA_PT_uv_texture,
489     DATA_PT_vertex_colors,
490     DATA_PT_face_maps,
491     DATA_PT_normals,
492     DATA_PT_texture_space,
493     DATA_PT_customdata,
494     DATA_PT_custom_props_mesh,
495 )
496
497 if __name__ == "__main__":  # only for live edit.
498     from bpy.utils import register_class
499     for cls in classes:
500         register_class(cls)