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