f59d479c50919ca54b753790e3ead97232d46b35
[blender-staging.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     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
28
29     def draw(self, context):
30         layout = self.layout
31
32         layout.operator("object.vertex_group_sort", icon='SORTALPHA')
33         layout.operator("object.vertex_group_copy", icon='COPY_ID')
34         layout.operator("object.vertex_group_copy_to_linked", icon='LINK_AREA')
35         layout.operator("object.vertex_group_copy_to_selected", icon='LINK_AREA')
36         layout.operator("object.vertex_group_mirror", icon='ARROW_LEFTRIGHT').use_topology = False
37         layout.operator("object.vertex_group_mirror", text="Mirror Vertex Group (Topology)", icon='ARROW_LEFTRIGHT').use_topology = True
38         layout.operator("object.vertex_group_remove_from", icon='X', text="Remove from All Groups").use_all_groups = True
39         layout.operator("object.vertex_group_remove_from", icon='X', text="Clear Active Group").use_all_verts = True
40         layout.operator("object.vertex_group_remove", icon='X', text="Delete All Groups").all = True
41         layout.separator()
42         layout.operator("object.vertex_group_lock", icon='LOCKED', text="Lock All").action = 'LOCK'
43         layout.operator("object.vertex_group_lock", icon='UNLOCKED', text="UnLock All").action = 'UNLOCK'
44         layout.operator("object.vertex_group_lock", icon='LOCKED', text="Lock Invert All").action = 'INVERT'
45
46
47 class MESH_MT_shape_key_specials(Menu):
48     bl_label = "Shape Key Specials"
49     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
50
51     def draw(self, context):
52         layout = self.layout
53
54         layout.operator("object.shape_key_transfer", icon='COPY_ID')  # icon is not ideal
55         layout.operator("object.join_shapes", icon='COPY_ID')  # icon is not ideal
56         layout.operator("object.shape_key_mirror", icon='ARROW_LEFTRIGHT').use_topology = False
57         layout.operator("object.shape_key_mirror", text="Mirror Shape Key (Topology)", icon='ARROW_LEFTRIGHT').use_topology = True
58         layout.operator("object.shape_key_add", icon='ZOOMIN', text="New Shape From Mix").from_mix = True
59         layout.operator("object.shape_key_remove", icon='X', text="Delete All Shapes").all = True
60
61
62 class MESH_UL_vgroups(UIList):
63     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
64         # assert(isinstance(item, bpy.types.VertexGroup)
65         vgroup = item
66         if self.layout_type in {'DEFAULT', 'COMPACT'}:
67             layout.label(text=vgroup.name, translate=False, icon_value=icon)
68             icon = 'LOCKED' if vgroup.lock_weight else 'UNLOCKED'
69             layout.prop(vgroup, "lock_weight", text="", icon=icon, emboss=False)
70         elif self.layout_type in {'GRID'}:
71             layout.alignment = 'CENTER'
72             layout.label(text="", icon_value=icon)
73
74
75 class MESH_UL_shape_keys(UIList):
76     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
77         # assert(isinstance(item, bpy.types.ShapeKey)
78         obj = active_data
79         key = data
80         key_block = item
81         if self.layout_type in {'DEFAULT', 'COMPACT'}:
82             split = layout.split(0.66, False)
83             split.label(text=item.name, translate=False, icon_value=icon)
84             row = split.row(align=True)
85             if key_block.mute or (obj.mode == 'EDIT' and not (obj.use_shape_key_edit_mode and obj.type == 'MESH')):
86                 row.active = False
87             if not item.relative_key or index > 0:
88                 row.prop(key_block, "value", text="", emboss=False)
89             else:
90                 row.label(text="")
91             row.prop(key_block, "mute", text="", emboss=False)
92         elif self.layout_type in {'GRID'}:
93             layout.alignment = 'CENTER'
94             layout.label(text="", icon_value=icon)
95
96
97 class MESH_UL_uvmaps_vcols(UIList):
98     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
99         # assert(isinstance(item, (bpy.types.MeshTexturePolyLayer, bpy.types.MeshLoopColorLayer))
100         if self.layout_type in {'DEFAULT', 'COMPACT'}:
101             layout.label(text=item.name, translate=False, icon_value=icon)
102             icon = 'RESTRICT_RENDER_OFF' if item.active_render else 'RESTRICT_RENDER_ON'
103             layout.prop(item, "active_render", text="", icon=icon, emboss=False)
104         elif self.layout_type in {'GRID'}:
105             layout.alignment = 'CENTER'
106             layout.label(text="", icon_value=icon)
107
108
109 class MeshButtonsPanel():
110     bl_space_type = 'PROPERTIES'
111     bl_region_type = 'WINDOW'
112     bl_context = "data"
113
114     @classmethod
115     def poll(cls, context):
116         engine = context.scene.render.engine
117         return context.mesh and (engine in cls.COMPAT_ENGINES)
118
119
120 class DATA_PT_context_mesh(MeshButtonsPanel, Panel):
121     bl_label = ""
122     bl_options = {'HIDE_HEADER'}
123     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
124
125     def draw(self, context):
126         layout = self.layout
127
128         ob = context.object
129         mesh = context.mesh
130         space = context.space_data
131
132         if ob:
133             layout.template_ID(ob, "data")
134         elif mesh:
135             layout.template_ID(space, "pin_id")
136
137
138 class DATA_PT_normals(MeshButtonsPanel, Panel):
139     bl_label = "Normals"
140     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
141
142     def draw(self, context):
143         layout = self.layout
144
145         mesh = context.mesh
146
147         split = layout.split()
148
149         col = split.column()
150         col.prop(mesh, "use_auto_smooth")
151         sub = col.column()
152         sub.active = mesh.use_auto_smooth
153         sub.prop(mesh, "auto_smooth_angle", text="Angle")
154
155         split.prop(mesh, "show_double_sided")
156
157
158 class DATA_PT_texture_space(MeshButtonsPanel, Panel):
159     bl_label = "Texture Space"
160     bl_options = {'DEFAULT_CLOSED'}
161     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
162
163     def draw(self, context):
164         layout = self.layout
165
166         mesh = context.mesh
167
168         layout.prop(mesh, "texture_mesh")
169
170         layout.separator()
171
172         layout.prop(mesh, "use_auto_texspace")
173         row = layout.row()
174         row.column().prop(mesh, "texspace_location", text="Location")
175         row.column().prop(mesh, "texspace_size", text="Size")
176
177
178 class DATA_PT_vertex_groups(MeshButtonsPanel, Panel):
179     bl_label = "Vertex Groups"
180     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
181
182     @classmethod
183     def poll(cls, context):
184         engine = context.scene.render.engine
185         obj = context.object
186         return (obj and obj.type in {'MESH', 'LATTICE'} and (engine in cls.COMPAT_ENGINES))
187
188     def draw(self, context):
189         layout = self.layout
190
191         ob = context.object
192         group = ob.vertex_groups.active
193
194         rows = 1
195         if group:
196             rows = 4
197
198         row = layout.row()
199         row.template_list("MESH_UL_vgroups", "", ob, "vertex_groups", ob.vertex_groups, "active_index", rows=rows)
200
201         col = row.column(align=True)
202         col.operator("object.vertex_group_add", icon='ZOOMIN', text="")
203         col.operator("object.vertex_group_remove", icon='ZOOMOUT', text="").all = False
204         col.menu("MESH_MT_vertex_group_specials", icon='DOWNARROW_HLT', text="")
205         if group:
206             col.separator()
207             col.operator("object.vertex_group_move", icon='TRIA_UP', text="").direction = 'UP'
208             col.operator("object.vertex_group_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
209
210             row = layout.row()
211             row.prop(group, "name")
212
213         if ob.vertex_groups and (ob.mode == 'EDIT' or (ob.mode == 'WEIGHT_PAINT' and ob.type == 'MESH' and ob.data.use_paint_mask_vertex)):
214             row = layout.row()
215
216             sub = row.row(align=True)
217             sub.operator("object.vertex_group_assign", text="Assign")
218             sub.operator("object.vertex_group_remove_from", text="Remove")
219
220             sub = row.row(align=True)
221             sub.operator("object.vertex_group_select", text="Select")
222             sub.operator("object.vertex_group_deselect", text="Deselect")
223
224             layout.prop(context.tool_settings, "vertex_group_weight", text="Weight")
225
226
227 class DATA_PT_shape_keys(MeshButtonsPanel, Panel):
228     bl_label = "Shape Keys"
229     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
230
231     @classmethod
232     def poll(cls, context):
233         engine = context.scene.render.engine
234         obj = context.object
235         return (obj and obj.type in {'MESH', 'LATTICE', 'CURVE', 'SURFACE'} and (engine in cls.COMPAT_ENGINES))
236
237     def draw(self, context):
238         layout = self.layout
239
240         ob = context.object
241         key = ob.data.shape_keys
242         kb = ob.active_shape_key
243
244         enable_edit = ob.mode != 'EDIT'
245         enable_edit_value = False
246
247         if ob.show_only_shape_key is False:
248             if enable_edit or (ob.type == 'MESH' and ob.use_shape_key_edit_mode):
249                 enable_edit_value = True
250
251         row = layout.row()
252
253         rows = 1
254         if kb:
255             rows = 4
256         row.template_list("MESH_UL_shape_keys", "", key, "key_blocks", ob, "active_shape_key_index", rows=rows)
257
258         col = row.column()
259
260         sub = col.column(align=True)
261         sub.operator("object.shape_key_add", icon='ZOOMIN', text="").from_mix = False
262         sub.operator("object.shape_key_remove", icon='ZOOMOUT', text="").all = False
263         sub.menu("MESH_MT_shape_key_specials", icon='DOWNARROW_HLT', text="")
264
265         if kb:
266             col.separator()
267
268             sub = col.column(align=True)
269             sub.operator("object.shape_key_move", icon='TRIA_UP', text="").type = 'UP'
270             sub.operator("object.shape_key_move", icon='TRIA_DOWN', text="").type = 'DOWN'
271
272             split = layout.split(percentage=0.4)
273             row = split.row()
274             row.enabled = enable_edit
275             row.prop(key, "use_relative")
276
277             row = split.row()
278             row.alignment = 'RIGHT'
279
280             sub = row.row(align=True)
281             sub.label()  # XXX, for alignment only
282             subsub = sub.row(align=True)
283             subsub.active = enable_edit_value
284             subsub.prop(ob, "show_only_shape_key", text="")
285             sub.prop(ob, "use_shape_key_edit_mode", text="")
286
287             sub = row.row()
288             if key.use_relative:
289                 sub.operator("object.shape_key_clear", icon='X', text="")
290             else:
291                 sub.operator("object.shape_key_retime", icon='RECOVER_LAST', text="")
292
293             row = layout.row()
294             row.prop(kb, "name")
295
296             if key.use_relative:
297                 if ob.active_shape_key_index != 0:
298                     row = layout.row()
299                     row.active = enable_edit_value
300                     row.prop(kb, "value")
301
302                     split = layout.split()
303
304                     col = split.column(align=True)
305                     col.active = enable_edit_value
306                     col.label(text="Range:")
307                     col.prop(kb, "slider_min", text="Min")
308                     col.prop(kb, "slider_max", text="Max")
309
310                     col = split.column(align=True)
311                     col.active = enable_edit_value
312                     col.label(text="Blend:")
313                     col.prop_search(kb, "vertex_group", ob, "vertex_groups", text="")
314                     col.prop_search(kb, "relative_key", key, "key_blocks", text="")
315
316             else:
317                 layout.prop(kb, "interpolation")
318                 row = layout.column()
319                 row.active = enable_edit_value
320                 row.prop(key, "eval_time")
321                 row.prop(key, "slurph")
322
323
324 class DATA_PT_uv_texture(MeshButtonsPanel, Panel):
325     bl_label = "UV Maps"
326     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
327
328     def draw(self, context):
329         layout = self.layout
330
331         me = context.mesh
332         lay = me.uv_textures.active
333
334         row = layout.row()
335         col = row.column()
336
337         col.template_list("MESH_UL_uvmaps_vcols", "uvmaps", me, "uv_textures", me.uv_textures, "active_index", rows=1)
338
339         col = row.column(align=True)
340         col.operator("mesh.uv_texture_add", icon='ZOOMIN', text="")
341         col.operator("mesh.uv_texture_remove", icon='ZOOMOUT', text="")
342
343         if lay:
344             layout.prop(lay, "name")
345
346
347 class DATA_PT_vertex_colors(MeshButtonsPanel, Panel):
348     bl_label = "Vertex Colors"
349     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
350
351     def draw(self, context):
352         layout = self.layout
353
354         me = context.mesh
355         lay = me.vertex_colors.active
356
357         row = layout.row()
358         col = row.column()
359
360         col.template_list("MESH_UL_uvmaps_vcols", "vcols", me, "vertex_colors", me.vertex_colors, "active_index", rows=1)
361
362         col = row.column(align=True)
363         col.operator("mesh.vertex_color_add", icon='ZOOMIN', text="")
364         col.operator("mesh.vertex_color_remove", icon='ZOOMOUT', text="")
365
366         if lay:
367             layout.prop(lay, "name")
368
369
370 class DATA_PT_customdata(MeshButtonsPanel, Panel):
371     bl_label = "Geometry Data"
372     bl_options = {'DEFAULT_CLOSED'}
373     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
374
375     def draw(self, context):
376         layout = self.layout
377
378         obj = context.object
379         me = context.mesh
380         col = layout.column()
381
382         col.operator("mesh.customdata_clear_mask", icon='X')
383         col.operator("mesh.customdata_clear_skin", icon='X')
384
385         col = layout.column()
386
387         col.enabled = (obj.mode != 'EDIT')
388         col.prop(me, "use_customdata_vertex_bevel")
389         col.prop(me, "use_customdata_edge_bevel")
390         col.prop(me, "use_customdata_edge_crease")
391
392
393 class DATA_PT_custom_props_mesh(MeshButtonsPanel, PropertyPanel, Panel):
394     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
395     _context_path = "object.data"
396     _property_type = bpy.types.Mesh
397
398
399 if __name__ == "__main__":  # only for live edit.
400     bpy.utils.register_module(__name__)