b61d493607654d84cf62a4e03152f8fb07cd7d4b
[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_context_menu(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_context_menu(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         pass
179
180
181 class DATA_PT_normals_auto_smooth(MeshButtonsPanel, Panel):
182     bl_label = "Auto Smooth"
183     bl_parent_id = "DATA_PT_normals"
184     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
185
186     def draw_header(self, context):
187         mesh = context.mesh
188
189         self.layout.prop(mesh, "use_auto_smooth", text="")
190
191     def draw(self, context):
192         layout = self.layout
193         layout.use_property_split = True
194
195         mesh = context.mesh
196
197         layout.active = mesh.use_auto_smooth and not mesh.has_custom_normals
198         layout.prop(mesh, "auto_smooth_angle", text="Angle")
199
200
201 class DATA_PT_texture_space(MeshButtonsPanel, Panel):
202     bl_label = "Texture Space"
203     bl_options = {'DEFAULT_CLOSED'}
204     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
205
206     def draw(self, context):
207         layout = self.layout
208         layout.use_property_split = True
209
210         mesh = context.mesh
211
212         layout.prop(mesh, "texture_mesh")
213
214         layout.separator()
215
216         layout.prop(mesh, "use_auto_texspace")
217
218         layout.prop(mesh, "texspace_location", text="Location")
219         layout.prop(mesh, "texspace_size", text="Size")
220
221
222 class DATA_PT_vertex_groups(MeshButtonsPanel, Panel):
223     bl_label = "Vertex Groups"
224     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
225
226     @classmethod
227     def poll(cls, context):
228         engine = context.engine
229         obj = context.object
230         return (obj and obj.type in {'MESH', 'LATTICE'} and (engine in cls.COMPAT_ENGINES))
231
232     def draw(self, context):
233         layout = self.layout
234
235         ob = context.object
236         group = ob.vertex_groups.active
237
238         rows = 3
239         if group:
240             rows = 5
241
242         row = layout.row()
243         row.template_list("MESH_UL_vgroups", "", ob, "vertex_groups", ob.vertex_groups, "active_index", rows=rows)
244
245         col = row.column(align=True)
246
247         col.operator("object.vertex_group_add", icon='ADD', text="")
248         props = col.operator("object.vertex_group_remove", icon='REMOVE', text="")
249         props.all_unlocked = props.all = False
250
251         col.separator()
252
253         col.menu("MESH_MT_vertex_group_context_menu", icon='DOWNARROW_HLT', text="")
254
255         if group:
256             col.separator()
257             col.operator("object.vertex_group_move", icon='TRIA_UP', text="").direction = 'UP'
258             col.operator("object.vertex_group_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
259
260         if ob.vertex_groups and (ob.mode == 'EDIT' or (ob.mode == 'WEIGHT_PAINT' and ob.type == 'MESH' and ob.data.use_paint_mask_vertex)):
261             row = layout.row()
262
263             sub = row.row(align=True)
264             sub.operator("object.vertex_group_assign", text="Assign")
265             sub.operator("object.vertex_group_remove_from", text="Remove")
266
267             sub = row.row(align=True)
268             sub.operator("object.vertex_group_select", text="Select")
269             sub.operator("object.vertex_group_deselect", text="Deselect")
270
271             layout.prop(context.tool_settings, "vertex_group_weight", text="Weight")
272
273
274 class DATA_PT_face_maps(MeshButtonsPanel, Panel):
275     bl_label = "Face Maps"
276     bl_options = {'DEFAULT_CLOSED'}
277     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
278
279     @classmethod
280     def poll(cls, context):
281         obj = context.object
282         return (obj and obj.type == 'MESH')
283
284     def draw(self, context):
285         layout = self.layout
286
287         ob = context.object
288         facemap = ob.face_maps.active
289
290         rows = 2
291         if facemap:
292             rows = 4
293
294         row = layout.row()
295         row.template_list("MESH_UL_fmaps", "", ob, "face_maps", ob.face_maps, "active_index", rows=rows)
296
297         col = row.column(align=True)
298         col.operator("object.face_map_add", icon='ADD', text="")
299         col.operator("object.face_map_remove", icon='REMOVE', text="")
300
301         if facemap:
302             col.separator()
303             col.operator("object.face_map_move", icon='TRIA_UP', text="").direction = 'UP'
304             col.operator("object.face_map_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
305
306         if ob.face_maps and (ob.mode == 'EDIT' and ob.type == 'MESH'):
307             row = layout.row()
308
309             sub = row.row(align=True)
310             sub.operator("object.face_map_assign", text="Assign")
311             sub.operator("object.face_map_remove_from", text="Remove")
312
313             sub = row.row(align=True)
314             sub.operator("object.face_map_select", text="Select")
315             sub.operator("object.face_map_deselect", text="Deselect")
316
317
318 class DATA_PT_shape_keys(MeshButtonsPanel, Panel):
319     bl_label = "Shape Keys"
320     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
321
322     @classmethod
323     def poll(cls, context):
324         engine = context.engine
325         obj = context.object
326         return (obj and obj.type in {'MESH', 'LATTICE', 'CURVE', 'SURFACE'} and (engine in cls.COMPAT_ENGINES))
327
328     def draw(self, context):
329         layout = self.layout
330
331         ob = context.object
332         key = ob.data.shape_keys
333         kb = ob.active_shape_key
334
335         enable_edit = ob.mode != 'EDIT'
336         enable_edit_value = False
337
338         if ob.show_only_shape_key is False:
339             if enable_edit or (ob.type == 'MESH' and ob.use_shape_key_edit_mode):
340                 enable_edit_value = True
341
342         row = layout.row()
343
344         rows = 3
345         if kb:
346             rows = 5
347
348         row.template_list("MESH_UL_shape_keys", "", key, "key_blocks", ob, "active_shape_key_index", rows=rows)
349
350         col = row.column(align=True)
351
352         col.operator("object.shape_key_add", icon='ADD', text="").from_mix = False
353         col.operator("object.shape_key_remove", icon='REMOVE', text="").all = False
354
355         col.separator()
356
357         col.menu("MESH_MT_shape_key_context_menu", icon='DOWNARROW_HLT', text="")
358
359         if kb:
360             col.separator()
361
362             sub = col.column(align=True)
363             sub.operator("object.shape_key_move", icon='TRIA_UP', text="").type = 'UP'
364             sub.operator("object.shape_key_move", icon='TRIA_DOWN', text="").type = 'DOWN'
365
366             split = layout.split(factor=0.4)
367             row = split.row()
368             row.enabled = enable_edit
369             row.prop(key, "use_relative")
370
371             row = split.row()
372             row.alignment = 'RIGHT'
373
374             sub = row.row(align=True)
375             sub.label()  # XXX, for alignment only
376             subsub = sub.row(align=True)
377             subsub.active = enable_edit_value
378             subsub.prop(ob, "show_only_shape_key", text="")
379             sub.prop(ob, "use_shape_key_edit_mode", text="")
380
381             sub = row.row()
382             if key.use_relative:
383                 sub.operator("object.shape_key_clear", icon='X', text="")
384             else:
385                 sub.operator("object.shape_key_retime", icon='RECOVER_LAST', text="")
386
387             if key.use_relative:
388                 if ob.active_shape_key_index != 0:
389                     layout.use_property_split = True
390
391                     row = layout.row()
392                     row.active = enable_edit_value
393                     row.prop(kb, "value")
394
395                     col = layout.column()
396                     sub.active = enable_edit_value
397                     sub = col.column(align=True)
398                     sub.prop(kb, "slider_min", text="Range Min")
399                     sub.prop(kb, "slider_max", text="Max")
400
401                     col.prop_search(kb, "vertex_group", ob, "vertex_groups", text="Vertex Group")
402                     col.prop_search(kb, "relative_key", key, "key_blocks", text="Relative To")
403
404             else:
405                 layout.prop(kb, "interpolation")
406                 row = layout.column()
407                 row.active = enable_edit_value
408                 row.prop(key, "eval_time")
409
410
411 class DATA_PT_uv_texture(MeshButtonsPanel, Panel):
412     bl_label = "UV Maps"
413     bl_options = {'DEFAULT_CLOSED'}
414     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
415
416     def draw(self, context):
417         layout = self.layout
418
419         me = context.mesh
420
421         row = layout.row()
422         col = row.column()
423
424         col.template_list("MESH_UL_uvmaps", "uvmaps", me, "uv_layers", me.uv_layers, "active_index", rows=2)
425
426         col = row.column(align=True)
427         col.operator("mesh.uv_texture_add", icon='ADD', text="")
428         col.operator("mesh.uv_texture_remove", icon='REMOVE', text="")
429
430
431 class DATA_PT_vertex_colors(MeshButtonsPanel, Panel):
432     bl_label = "Vertex Colors"
433     bl_options = {'DEFAULT_CLOSED'}
434     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
435
436     def draw(self, context):
437         layout = self.layout
438
439         me = context.mesh
440
441         row = layout.row()
442         col = row.column()
443
444         col.template_list("MESH_UL_vcols", "vcols", me, "vertex_colors", me.vertex_colors, "active_index", rows=2)
445
446         col = row.column(align=True)
447         col.operator("mesh.vertex_color_add", icon='ADD', text="")
448         col.operator("mesh.vertex_color_remove", icon='REMOVE', text="")
449
450
451 class DATA_PT_customdata(MeshButtonsPanel, Panel):
452     bl_label = "Geometry Data"
453     bl_options = {'DEFAULT_CLOSED'}
454     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
455
456     def draw(self, context):
457         layout = self.layout
458         layout.use_property_split = True
459
460         obj = context.object
461         me = context.mesh
462         col = layout.column()
463
464         col.operator("mesh.customdata_mask_clear", icon='X')
465         col.operator("mesh.customdata_skin_clear", icon='X')
466
467         if me.has_custom_normals:
468             col.operator("mesh.customdata_custom_splitnormals_clear", icon='X')
469         else:
470             col.operator("mesh.customdata_custom_splitnormals_add", icon='ADD')
471
472         col = layout.column()
473
474         col.enabled = (obj.mode != 'EDIT')
475         col.prop(me, "use_customdata_vertex_bevel")
476         col.prop(me, "use_customdata_edge_bevel")
477         col.prop(me, "use_customdata_edge_crease")
478
479
480 class DATA_PT_custom_props_mesh(MeshButtonsPanel, PropertyPanel, Panel):
481     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
482     _context_path = "object.data"
483     _property_type = bpy.types.Mesh
484
485
486 classes = (
487     MESH_MT_vertex_group_context_menu,
488     MESH_MT_shape_key_context_menu,
489     MESH_UL_vgroups,
490     MESH_UL_fmaps,
491     MESH_UL_shape_keys,
492     MESH_UL_uvmaps,
493     MESH_UL_vcols,
494     DATA_PT_context_mesh,
495     DATA_PT_vertex_groups,
496     DATA_PT_shape_keys,
497     DATA_PT_uv_texture,
498     DATA_PT_vertex_colors,
499     DATA_PT_face_maps,
500     DATA_PT_normals,
501     DATA_PT_normals_auto_smooth,
502     DATA_PT_texture_space,
503     DATA_PT_customdata,
504     DATA_PT_custom_props_mesh,
505 )
506
507 if __name__ == "__main__":  # only for live edit.
508     from bpy.utils import register_class
509     for cls in classes:
510         register_class(cls)