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