82185b0b1b059b42346d7ce6a45b06a4870059ef
[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
22 from rna_prop_ui import PropertyPanel
23 from blf import gettext as _
24
25
26 class MESH_MT_vertex_group_specials(Menu):
27     bl_label = _("Vertex Group Specials")
28     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
29
30     def draw(self, context):
31         layout = self.layout
32
33         layout.operator("object.vertex_group_sort", icon='SORTALPHA')
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')
38         layout.operator("object.vertex_group_remove", icon='X', text=_("Delete All")).all = True
39         layout.separator()
40         layout.operator("object.vertex_group_lock", icon='LOCK', text="Lock All").action = 'SELECT'
41         layout.operator("object.vertex_group_lock", icon='UNLOCK', text="UnLock All").action = 'DESELECT'
42         layout.operator("object.vertex_group_lock", icon='LOCK', text="Lock Invert All").action = 'INVERT'
43
44
45 class MESH_MT_shape_key_specials(Menu):
46     bl_label = "Shape Key Specials"
47     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
48
49     def draw(self, context):
50         layout = self.layout
51
52         layout.operator("object.shape_key_transfer", icon='COPY_ID')  # icon is not ideal
53         layout.operator("object.join_shapes", icon='COPY_ID')  # icon is not ideal
54         layout.operator("object.shape_key_mirror", icon='ARROW_LEFTRIGHT')
55         op = layout.operator("object.shape_key_add", icon='ZOOMIN', text=_("New Shape From Mix"))
56         op.from_mix = True
57
58
59 class MeshButtonsPanel():
60     bl_space_type = 'PROPERTIES'
61     bl_region_type = 'WINDOW'
62     bl_context = "data"
63
64     @classmethod
65     def poll(cls, context):
66         engine = context.scene.render.engine
67         return context.mesh and (engine in cls.COMPAT_ENGINES)
68
69
70 class DATA_PT_context_mesh(MeshButtonsPanel, Panel):
71     bl_label = ""
72     bl_options = {'HIDE_HEADER'}
73     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
74
75     def draw(self, context):
76         layout = self.layout
77
78         ob = context.object
79         mesh = context.mesh
80         space = context.space_data
81
82         if ob:
83             layout.template_ID(ob, "data")
84         elif mesh:
85             layout.template_ID(space, "pin_id")
86
87
88 class DATA_PT_normals(MeshButtonsPanel, Panel):
89     bl_label = "Normals"
90     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
91
92     def draw(self, context):
93         layout = self.layout
94
95         mesh = context.mesh
96
97         split = layout.split()
98
99         col = split.column()
100         col.prop(mesh, "use_auto_smooth")
101         sub = col.column()
102         sub.active = mesh.use_auto_smooth
103         sub.prop(mesh, "auto_smooth_angle", text=_("Angle"))
104
105         split.prop(mesh, "show_double_sided")
106
107
108 class DATA_PT_texture_space(MeshButtonsPanel, Panel):
109     bl_label = "Texture Space"
110     bl_options = {'DEFAULT_CLOSED'}
111     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
112
113     def draw(self, context):
114         layout = self.layout
115
116         mesh = context.mesh
117
118         layout.prop(mesh, "texture_mesh")
119
120         layout.separator()
121
122         layout.prop(mesh, "use_auto_texspace")
123         row = layout.row()
124         row.column().prop(mesh, "texspace_location", text=_("Location"))
125         row.column().prop(mesh, "texspace_size", text=_("Size"))
126
127
128 class DATA_PT_vertex_groups(MeshButtonsPanel, Panel):
129     bl_label = "Vertex Groups"
130     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
131
132     @classmethod
133     def poll(cls, context):
134         engine = context.scene.render.engine
135         obj = context.object
136         return (obj and obj.type in {'MESH', 'LATTICE'} and (engine in cls.COMPAT_ENGINES))
137
138     def draw(self, context):
139         layout = self.layout
140
141         ob = context.object
142         group = ob.vertex_groups.active
143
144         rows = 2
145         if group:
146             rows = 5
147
148         row = layout.row()
149         row.template_list(ob, "vertex_groups", ob.vertex_groups, "active_index", rows=rows)
150
151         col = row.column(align=True)
152         col.operator("object.vertex_group_add", icon='ZOOMIN', text="")
153         col.operator("object.vertex_group_remove", icon='ZOOMOUT', text="")
154         col.menu("MESH_MT_vertex_group_specials", icon='DOWNARROW_HLT', text="")
155         if group:
156             col.operator("object.vertex_group_move", icon='TRIA_UP', text="").direction = 'UP'
157             col.operator("object.vertex_group_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
158
159         if group:
160             row = layout.row()
161             row.prop(group, "name")
162
163         if ob.mode == 'EDIT' and len(ob.vertex_groups) > 0:
164             row = layout.row()
165
166             sub = row.row(align=True)
167             sub.operator("object.vertex_group_assign", text=_("Assign"))
168             sub.operator("object.vertex_group_remove_from", text=_("Remove"))
169
170             sub = row.row(align=True)
171             sub.operator("object.vertex_group_select", text=_("Select"))
172             sub.operator("object.vertex_group_deselect", text=_("Deselect"))
173
174             layout.prop(context.tool_settings, "vertex_group_weight", text=_("Weight"))
175
176
177 class DATA_PT_shape_keys(MeshButtonsPanel, Panel):
178     bl_label = "Shape Keys"
179     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
180
181     @classmethod
182     def poll(cls, context):
183         engine = context.scene.render.engine
184         obj = context.object
185         return (obj and obj.type in {'MESH', 'LATTICE', 'CURVE', 'SURFACE'} and (engine in cls.COMPAT_ENGINES))
186
187     def draw(self, context):
188         layout = self.layout
189
190         ob = context.object
191         key = ob.data.shape_keys
192         kb = ob.active_shape_key
193
194         enable_edit = ob.mode != 'EDIT'
195         enable_edit_value = False
196
197         if ob.show_only_shape_key is False:
198             if enable_edit or (ob.type == 'MESH' and ob.use_shape_key_edit_mode):
199                 enable_edit_value = True
200
201         row = layout.row()
202
203         rows = 2
204         if kb:
205             rows = 5
206         row.template_list(key, "key_blocks", ob, "active_shape_key_index", rows=rows)
207
208         col = row.column()
209
210         sub = col.column(align=True)
211         op = sub.operator("object.shape_key_add", icon='ZOOMIN', text="")
212         op.from_mix = False
213         sub.operator("object.shape_key_remove", icon='ZOOMOUT', text="")
214         sub.menu("MESH_MT_shape_key_specials", icon='DOWNARROW_HLT', text="")
215
216         if kb:
217             col.separator()
218
219             sub = col.column(align=True)
220             sub.operator("object.shape_key_move", icon='TRIA_UP', text="").type = 'UP'
221             sub.operator("object.shape_key_move", icon='TRIA_DOWN', text="").type = 'DOWN'
222
223             split = layout.split(percentage=0.4)
224             row = split.row()
225             row.enabled = enable_edit
226             row.prop(key, "use_relative")
227
228             row = split.row()
229             row.alignment = 'RIGHT'
230
231             sub = row.row(align=True)
232             subsub = sub.row(align=True)
233             subsub.active = enable_edit_value
234             subsub.prop(ob, "show_only_shape_key", text="")
235             subsub.prop(kb, "mute", text="")
236             sub.prop(ob, "use_shape_key_edit_mode", text="")
237
238             sub = row.row()
239             sub.operator("object.shape_key_clear", icon='X', text="")
240
241             row = layout.row()
242             row.prop(kb, "name")
243
244             if key.use_relative:
245                 if ob.active_shape_key_index != 0:
246                     row = layout.row()
247                     row.active = enable_edit_value
248                     row.prop(kb, "value")
249
250                     split = layout.split()
251
252                     col = split.column(align=True)
253                     col.active = enable_edit_value
254                     col.label(text=_("Range:"))
255                     col.prop(kb, "slider_min", text=_("Min"))
256                     col.prop(kb, "slider_max", text=_("Max"))
257
258                     col = split.column(align=True)
259                     col.active = enable_edit_value
260                     col.label(text=_("Blend:"))
261                     col.prop_search(kb, "vertex_group", ob, "vertex_groups", text="")
262                     col.prop_search(kb, "relative_key", key, "key_blocks", text="")
263
264             else:
265                 row = layout.row()
266                 row.active = enable_edit_value
267                 row.prop(key, "slurph")
268
269
270 class DATA_PT_uv_texture(MeshButtonsPanel, Panel):
271     bl_label = "UV Texture"
272     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
273
274     def draw(self, context):
275         layout = self.layout
276
277         me = context.mesh
278
279         row = layout.row()
280         col = row.column()
281
282         col.template_list(me, "uv_textures", me.uv_textures, "active_index", rows=2)
283
284         col = row.column(align=True)
285         col.operator("mesh.uv_texture_add", icon='ZOOMIN', text="")
286         col.operator("mesh.uv_texture_remove", icon='ZOOMOUT', text="")
287
288         lay = me.uv_textures.active
289         if lay:
290             layout.prop(lay, "name")
291
292
293 class DATA_PT_vertex_colors(MeshButtonsPanel, Panel):
294     bl_label = "Vertex Colors"
295     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
296
297     def draw(self, context):
298         layout = self.layout
299
300         me = context.mesh
301
302         row = layout.row()
303         col = row.column()
304
305         col.template_list(me, "vertex_colors", me.vertex_colors, "active_index", rows=2)
306
307         col = row.column(align=True)
308         col.operator("mesh.vertex_color_add", icon='ZOOMIN', text="")
309         col.operator("mesh.vertex_color_remove", icon='ZOOMOUT', text="")
310
311         lay = me.vertex_colors.active
312         if lay:
313             layout.prop(lay, "name")
314
315
316 class DATA_PT_custom_props_mesh(MeshButtonsPanel, PropertyPanel, Panel):
317     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
318     _context_path = "object.data"
319     _property_type = bpy.types.Mesh
320
321 if __name__ == "__main__":  # only for live edit.
322     bpy.utils.register_module(__name__)