dd75850f1d3387dc09065ec9c02ef9b84f6eacf1
[blender.git] / release / scripts / 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
37
38 class MESH_MT_shape_key_specials(bpy.types.Menu):
39     bl_label = "Shape Key Specials"
40     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
41
42     def draw(self, context):
43         layout = self.layout
44
45         layout.operator("object.shape_key_transfer", icon='COPY_ID') # icon is not ideal
46         layout.operator("object.join_shapes", icon='COPY_ID') # icon is not ideal
47         layout.operator("object.shape_key_mirror", icon='ARROW_LEFTRIGHT')
48
49
50 class DataButtonsPanel():
51     bl_space_type = 'PROPERTIES'
52     bl_region_type = 'WINDOW'
53     bl_context = "data"
54
55
56 class DATA_PT_context_mesh(DataButtonsPanel, bpy.types.Panel):
57     bl_label = ""
58     bl_show_header = False
59     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
60
61     @staticmethod
62     def poll(context):
63         engine = context.scene.render.engine
64         return context.mesh and (engine in __class__.COMPAT_ENGINES)
65
66     def draw(self, context):
67         layout = self.layout
68
69         ob = context.object
70         mesh = context.mesh
71         space = context.space_data
72
73         split = layout.split(percentage=0.65)
74         if ob:
75             split.template_ID(ob, "data")
76             split.separator()
77         elif mesh:
78             split.template_ID(space, "pin_id")
79             split.separator()
80
81
82 class DATA_PT_custom_props_mesh(DataButtonsPanel, PropertyPanel, bpy.types.Panel):
83     _context_path = "object.data"
84     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
85
86     @staticmethod
87     def poll(context):
88         engine = context.scene.render.engine
89         return context.mesh and (engine in __class__.COMPAT_ENGINES)
90
91
92 class DATA_PT_normals(DataButtonsPanel, bpy.types.Panel):
93     bl_label = "Normals"
94     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
95
96     @staticmethod
97     def poll(context):
98         engine = context.scene.render.engine
99         return context.mesh and (engine in __class__.COMPAT_ENGINES)
100
101     def draw(self, context):
102         layout = self.layout
103
104         mesh = context.mesh
105
106         split = layout.split()
107
108         col = split.column()
109         col.prop(mesh, "autosmooth")
110         sub = col.column()
111         sub.active = mesh.autosmooth
112         sub.prop(mesh, "autosmooth_angle", text="Angle")
113
114         col = split.column()
115
116         col.prop(mesh, "double_sided")
117
118
119 class DATA_PT_settings(DataButtonsPanel, bpy.types.Panel):
120     bl_label = "Settings"
121     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
122
123     @staticmethod
124     def poll(context):
125         engine = context.scene.render.engine
126         return context.mesh and (engine in __class__.COMPAT_ENGINES)
127
128     def draw(self, context):
129         layout = self.layout
130
131         mesh = context.mesh
132
133         layout.prop(mesh, "texture_mesh")
134
135
136 class DATA_PT_vertex_groups(DataButtonsPanel, bpy.types.Panel):
137     bl_label = "Vertex Groups"
138     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
139
140     @staticmethod
141     def poll(context):
142         engine = context.scene.render.engine
143         obj = context.object
144         return (obj and obj.type in ('MESH', 'LATTICE') and (engine in __class__.COMPAT_ENGINES))
145
146     def draw(self, context):
147         layout = self.layout
148
149         ob = context.object
150         group = ob.active_vertex_group
151
152         rows = 2
153         if group:
154             rows = 5
155
156         row = layout.row()
157         row.template_list(ob, "vertex_groups", ob, "active_vertex_group_index", rows=rows)
158
159         col = row.column(align=True)
160         col.operator("object.vertex_group_add", icon='ZOOMIN', text="")
161         col.operator("object.vertex_group_remove", icon='ZOOMOUT', text="")
162         col.menu("MESH_MT_vertex_group_specials", icon='DOWNARROW_HLT', text="")
163         if group:
164             col.operator("object.vertex_group_move", icon='TRIA_UP', text="").direction = 'UP'
165             col.operator("object.vertex_group_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
166
167         if group:
168             row = layout.row()
169             row.prop(group, "name")
170
171         if ob.mode == 'EDIT' and len(ob.vertex_groups) > 0:
172             row = layout.row()
173
174             sub = row.row(align=True)
175             sub.operator("object.vertex_group_assign", text="Assign")
176             sub.operator("object.vertex_group_remove_from", text="Remove")
177
178             sub = row.row(align=True)
179             sub.operator("object.vertex_group_select", text="Select")
180             sub.operator("object.vertex_group_deselect", text="Deselect")
181
182             layout.prop(context.tool_settings, "vertex_group_weight", text="Weight")
183
184
185 class DATA_PT_shape_keys(DataButtonsPanel, bpy.types.Panel):
186     bl_label = "Shape Keys"
187     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
188
189     @staticmethod
190     def poll(context):
191         engine = context.scene.render.engine
192         obj = context.object
193         return (obj and obj.type in ('MESH', 'LATTICE', 'CURVE', 'SURFACE') and (engine in __class__.COMPAT_ENGINES))
194
195     def draw(self, context):
196         layout = self.layout
197
198         ob = context.object
199         key = ob.data.shape_keys
200         kb = ob.active_shape_key
201
202         enable_edit = ob.mode != 'EDIT'
203         enable_edit_value = False
204
205         if ob.shape_key_lock is False:
206             if enable_edit or (ob.type == 'MESH' and ob.shape_key_edit_mode):
207                 enable_edit_value = True
208
209         row = layout.row()
210
211         rows = 2
212         if kb:
213             rows = 5
214         row.template_list(key, "keys", ob, "active_shape_key_index", rows=rows)
215
216         col = row.column()
217
218         sub = col.column(align=True)
219         sub.operator("object.shape_key_add", icon='ZOOMIN', text="")
220         sub.operator("object.shape_key_remove", icon='ZOOMOUT', text="")
221         sub.menu("MESH_MT_shape_key_specials", icon='DOWNARROW_HLT', text="")
222
223         if kb:
224             col.separator()
225
226             sub = col.column(align=True)
227             sub.operator("object.shape_key_move", icon='TRIA_UP', text="").type = 'UP'
228             sub.operator("object.shape_key_move", icon='TRIA_DOWN', text="").type = 'DOWN'
229
230             split = layout.split(percentage=0.4)
231             row = split.row()
232             row.enabled = enable_edit
233             row.prop(key, "relative")
234
235             row = split.row()
236             row.alignment = 'RIGHT'
237
238             sub = row.row(align=True)
239             subsub = sub.row(align=True)
240             subsub.active = enable_edit_value
241             subsub.prop(ob, "shape_key_lock", text="")
242             subsub.prop(kb, "mute", text="")
243             sub.prop(ob, "shape_key_edit_mode", text="")
244
245             sub = row.row()
246             sub.operator("object.shape_key_clear", icon='X', text="")
247
248             row = layout.row()
249             row.prop(kb, "name")
250
251             if key.relative:
252                 if ob.active_shape_key_index != 0:
253                     row = layout.row()
254                     row.active = enable_edit_value
255                     row.prop(kb, "value")
256
257                     split = layout.split()
258
259                     col = split.column(align=True)
260                     col.active = enable_edit_value
261                     col.label(text="Range:")
262                     col.prop(kb, "slider_min", text="Min")
263                     col.prop(kb, "slider_max", text="Max")
264
265                     col = split.column(align=True)
266                     col.active = enable_edit_value
267                     col.label(text="Blend:")
268                     col.prop_object(kb, "vertex_group", ob, "vertex_groups", text="")
269                     col.prop_object(kb, "relative_key", key, "keys", text="")
270
271             else:
272                 row = layout.row()
273                 row.active = enable_edit_value
274                 row.prop(key, "slurph")
275
276
277 class DATA_PT_uv_texture(DataButtonsPanel, bpy.types.Panel):
278     bl_label = "UV Texture"
279     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
280
281     @staticmethod
282     def poll(context):
283         engine = context.scene.render.engine
284         return context.mesh and (engine in __class__.COMPAT_ENGINES)
285
286     def draw(self, context):
287         layout = self.layout
288
289         me = context.mesh
290
291         row = layout.row()
292         col = row.column()
293
294         col.template_list(me, "uv_textures", me, "active_uv_texture_index", rows=2)
295
296         col = row.column(align=True)
297         col.operator("mesh.uv_texture_add", icon='ZOOMIN', text="")
298         col.operator("mesh.uv_texture_remove", icon='ZOOMOUT', text="")
299
300         lay = me.active_uv_texture
301         if lay:
302             layout.prop(lay, "name")
303
304
305 class DATA_PT_texface(DataButtonsPanel, bpy.types.Panel):
306     bl_label = "Texture Face"
307     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
308
309     @staticmethod
310     def poll(context):
311         ob = context.active_object
312         rd = context.scene.render
313
314         return (context.mode == 'EDIT_MESH') and (rd.engine == 'BLENDER_GAME') and ob and ob.type == 'MESH'
315
316     def draw(self, context):
317         layout = self.layout
318         col = layout.column()
319
320         me = context.mesh
321
322         tf = me.faces.active_tface
323
324         if tf:
325             split = layout.split()
326             col = split.column()
327
328             col.prop(tf, "tex")
329             col.prop(tf, "light")
330             col.prop(tf, "invisible")
331             col.prop(tf, "collision")
332
333             col.prop(tf, "shared")
334             col.prop(tf, "twoside")
335             col.prop(tf, "object_color")
336
337             col = split.column()
338
339             col.prop(tf, "halo")
340             col.prop(tf, "billboard")
341             col.prop(tf, "shadow")
342             col.prop(tf, "text")
343             col.prop(tf, "alpha_sort")
344
345             col = layout.column()
346             col.prop(tf, "transp")
347         else:
348             col.label(text="No UV Texture")
349
350
351 class DATA_PT_vertex_colors(DataButtonsPanel, bpy.types.Panel):
352     bl_label = "Vertex Colors"
353     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
354
355     @staticmethod
356     def poll(context):
357         engine = context.scene.render.engine
358         return context.mesh and (engine in __class__.COMPAT_ENGINES)
359
360     def draw(self, context):
361         layout = self.layout
362
363         me = context.mesh
364
365         row = layout.row()
366         col = row.column()
367
368         col.template_list(me, "vertex_colors", me, "active_vertex_color_index", rows=2)
369
370         col = row.column(align=True)
371         col.operator("mesh.vertex_color_add", icon='ZOOMIN', text="")
372         col.operator("mesh.vertex_color_remove", icon='ZOOMOUT', text="")
373
374         lay = me.active_vertex_color
375         if lay:
376             layout.prop(lay, "name")
377
378
379 def register():
380     pass
381
382
383 def unregister():
384     pass
385
386 if __name__ == "__main__":
387     register()