b5461c4543397ff6cbff1749cd69f0f5445e1e05
[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     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(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 = 2
195         if group:
196             rows = 5
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         if group:
211             row = layout.row()
212             row.prop(group, "name")
213
214         if ob.vertex_groups and (ob.mode == 'EDIT' or (ob.mode == 'WEIGHT_PAINT' and ob.type == 'MESH' and ob.data.use_paint_mask_vertex)):
215             row = layout.row()
216
217             sub = row.row(align=True)
218             sub.operator("object.vertex_group_assign", text="Assign")
219             sub.operator("object.vertex_group_remove_from", text="Remove")
220
221             sub = row.row(align=True)
222             sub.operator("object.vertex_group_select", text="Select")
223             sub.operator("object.vertex_group_deselect", text="Deselect")
224
225             layout.prop(context.tool_settings, "vertex_group_weight", text="Weight")
226
227
228 class DATA_PT_shape_keys(MeshButtonsPanel, Panel):
229     bl_label = "Shape Keys"
230     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
231
232     @classmethod
233     def poll(cls, context):
234         engine = context.scene.render.engine
235         obj = context.object
236         return (obj and obj.type in {'MESH', 'LATTICE', 'CURVE', 'SURFACE'} and (engine in cls.COMPAT_ENGINES))
237
238     def draw(self, context):
239         layout = self.layout
240
241         ob = context.object
242         key = ob.data.shape_keys
243         kb = ob.active_shape_key
244
245         enable_edit = ob.mode != 'EDIT'
246         enable_edit_value = False
247
248         if ob.show_only_shape_key is False:
249             if enable_edit or (ob.type == 'MESH' and ob.use_shape_key_edit_mode):
250                 enable_edit_value = True
251
252         row = layout.row()
253
254         rows = 2
255         if kb:
256             rows = 5
257         row.template_list("MESH_UL_shape_keys", "", key, "key_blocks", ob, "active_shape_key_index", rows=rows)
258
259         col = row.column()
260
261         sub = col.column(align=True)
262         sub.operator("object.shape_key_add", icon='ZOOMIN', text="").from_mix = False
263         sub.operator("object.shape_key_remove", icon='ZOOMOUT', text="").all = False
264         sub.menu("MESH_MT_shape_key_specials", icon='DOWNARROW_HLT', text="")
265
266         if kb:
267             col.separator()
268
269             sub = col.column(align=True)
270             sub.operator("object.shape_key_move", icon='TRIA_UP', text="").type = 'UP'
271             sub.operator("object.shape_key_move", icon='TRIA_DOWN', text="").type = 'DOWN'
272
273             split = layout.split(percentage=0.4)
274             row = split.row()
275             row.enabled = enable_edit
276             row.prop(key, "use_relative")
277
278             row = split.row()
279             row.alignment = 'RIGHT'
280
281             sub = row.row(align=True)
282             sub.label()  # XXX, for alignment only
283             subsub = sub.row(align=True)
284             subsub.active = enable_edit_value
285             subsub.prop(ob, "show_only_shape_key", text="")
286             sub.prop(ob, "use_shape_key_edit_mode", text="")
287
288             sub = row.row()
289             if key.use_relative:
290                 sub.operator("object.shape_key_clear", icon='X', text="")
291             else:
292                 sub.operator("object.shape_key_retime", icon='RECOVER_LAST', text="")
293
294             row = layout.row()
295             row.prop(kb, "name")
296
297             if key.use_relative:
298                 if ob.active_shape_key_index != 0:
299                     row = layout.row()
300                     row.active = enable_edit_value
301                     row.prop(kb, "value")
302
303                     split = layout.split()
304
305                     col = split.column(align=True)
306                     col.active = enable_edit_value
307                     col.label(text="Range:")
308                     col.prop(kb, "slider_min", text="Min")
309                     col.prop(kb, "slider_max", text="Max")
310
311                     col = split.column(align=True)
312                     col.active = enable_edit_value
313                     col.label(text="Blend:")
314                     col.prop_search(kb, "vertex_group", ob, "vertex_groups", text="")
315                     col.prop_search(kb, "relative_key", key, "key_blocks", text="")
316
317             else:
318                 layout.prop(kb, "interpolation")
319                 row = layout.column()
320                 row.active = enable_edit_value
321                 row.prop(key, "eval_time")
322                 row.prop(key, "slurph")
323
324
325 class DATA_PT_uv_texture(MeshButtonsPanel, Panel):
326     bl_label = "UV Maps"
327     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
328
329     def draw(self, context):
330         layout = self.layout
331
332         me = context.mesh
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=2)
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         lay = me.uv_textures.active
344         if lay:
345             layout.prop(lay, "name")
346
347
348 class DATA_PT_vertex_colors(MeshButtonsPanel, Panel):
349     bl_label = "Vertex Colors"
350     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
351
352     def draw(self, context):
353         layout = self.layout
354
355         me = context.mesh
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=2)
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         lay = me.vertex_colors.active
367         if lay:
368             layout.prop(lay, "name")
369
370
371 class DATA_PT_customdata(MeshButtonsPanel, Panel):
372     bl_label = "Geometry Data"
373     bl_options = {'DEFAULT_CLOSED'}
374     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
375
376     def draw(self, context):
377         layout = self.layout
378
379         obj = context.object
380         me = context.mesh
381         col = layout.column()
382
383         col.operator("mesh.customdata_clear_mask", icon='X')
384         col.operator("mesh.customdata_clear_skin", icon='X')
385
386         col = layout.column()
387
388         col.enabled = (obj.mode != 'EDIT')
389         col.prop(me, "use_customdata_vertex_bevel")
390         col.prop(me, "use_customdata_edge_bevel")
391         col.prop(me, "use_customdata_edge_crease")
392
393
394 class DATA_PT_custom_props_mesh(MeshButtonsPanel, PropertyPanel, Panel):
395     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
396     _context_path = "object.data"
397     _property_type = bpy.types.Mesh
398
399
400 if __name__ == "__main__":  # only for live edit.
401     bpy.utils.register_module(__name__)