1188de7f11ccedbe8ffb73422499b616f70708d3
[blender-staging.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 MeshButtonsPanel():
51     bl_space_type = 'PROPERTIES'
52     bl_region_type = 'WINDOW'
53     bl_context = "data"
54
55     @classmethod
56     def poll(cls, context):
57         engine = context.scene.render.engine
58         return context.mesh and (engine in cls.COMPAT_ENGINES)
59
60
61 class DATA_PT_context_mesh(MeshButtonsPanel, bpy.types.Panel):
62     bl_label = ""
63     bl_show_header = False
64     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
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_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, "autosmooth")
95         sub = col.column()
96         sub.active = mesh.autosmooth
97         sub.prop(mesh, "autosmooth_angle", text="Angle")
98
99         col = split.column()
100
101         col.prop(mesh, "show_double_sided")
102
103
104 class DATA_PT_settings(MeshButtonsPanel, bpy.types.Panel):
105     bl_label = "Settings"
106     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
107
108     def draw(self, context):
109         layout = self.layout
110
111         mesh = context.mesh
112
113         layout.prop(mesh, "texture_mesh")
114
115
116 class DATA_PT_vertex_groups(MeshButtonsPanel, bpy.types.Panel):
117     bl_label = "Vertex Groups"
118     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
119
120     @classmethod
121     def poll(cls, context):
122         engine = context.scene.render.engine
123         obj = context.object
124         return (obj and obj.type in ('MESH', 'LATTICE') and (engine in cls.COMPAT_ENGINES))
125
126     def draw(self, context):
127         layout = self.layout
128
129         ob = context.object
130         group = ob.active_vertex_group
131
132         rows = 2
133         if group:
134             rows = 5
135
136         row = layout.row()
137         row.template_list(ob, "vertex_groups", ob, "active_vertex_group_index", rows=rows)
138
139         col = row.column(align=True)
140         col.operator("object.vertex_group_add", icon='ZOOMIN', text="")
141         col.operator("object.vertex_group_remove", icon='ZOOMOUT', text="")
142         col.menu("MESH_MT_vertex_group_specials", icon='DOWNARROW_HLT', text="")
143         if group:
144             col.operator("object.vertex_group_move", icon='TRIA_UP', text="").direction = 'UP'
145             col.operator("object.vertex_group_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
146
147         if group:
148             row = layout.row()
149             row.prop(group, "name")
150
151         if ob.mode == 'EDIT' and len(ob.vertex_groups) > 0:
152             row = layout.row()
153
154             sub = row.row(align=True)
155             sub.operator("object.vertex_group_assign", text="Assign")
156             sub.operator("object.vertex_group_remove_from", text="Remove")
157
158             sub = row.row(align=True)
159             sub.operator("object.vertex_group_select", text="Select")
160             sub.operator("object.vertex_group_deselect", text="Deselect")
161
162             layout.prop(context.tool_settings, "vertex_group_weight", text="Weight")
163
164
165 class DATA_PT_shape_keys(MeshButtonsPanel, bpy.types.Panel):
166     bl_label = "Shape Keys"
167     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
168
169     @classmethod
170     def poll(cls, context):
171         engine = context.scene.render.engine
172         obj = context.object
173         return (obj and obj.type in ('MESH', 'LATTICE', 'CURVE', 'SURFACE') and (engine in cls.COMPAT_ENGINES))
174
175     def draw(self, context):
176         layout = self.layout
177
178         ob = context.object
179         key = ob.data.shape_keys
180         kb = ob.active_shape_key
181
182         enable_edit = ob.mode != 'EDIT'
183         enable_edit_value = False
184
185         if ob.show_shape_key is False:
186             if enable_edit or (ob.type == 'MESH' and ob.shape_key_edit_mode):
187                 enable_edit_value = True
188
189         row = layout.row()
190
191         rows = 2
192         if kb:
193             rows = 5
194         row.template_list(key, "keys", ob, "active_shape_key_index", rows=rows)
195
196         col = row.column()
197
198         sub = col.column(align=True)
199         sub.operator("object.shape_key_add", icon='ZOOMIN', text="")
200         sub.operator("object.shape_key_remove", icon='ZOOMOUT', text="")
201         sub.menu("MESH_MT_shape_key_specials", icon='DOWNARROW_HLT', text="")
202
203         if kb:
204             col.separator()
205
206             sub = col.column(align=True)
207             sub.operator("object.shape_key_move", icon='TRIA_UP', text="").type = 'UP'
208             sub.operator("object.shape_key_move", icon='TRIA_DOWN', text="").type = 'DOWN'
209
210             split = layout.split(percentage=0.4)
211             row = split.row()
212             row.enabled = enable_edit
213             row.prop(key, "use_relative")
214
215             row = split.row()
216             row.alignment = 'RIGHT'
217
218             sub = row.row(align=True)
219             subsub = sub.row(align=True)
220             subsub.active = enable_edit_value
221             subsub.prop(ob, "show_shape_key", text="")
222             subsub.prop(kb, "mute", text="")
223             sub.prop(ob, "shape_key_edit_mode", text="")
224
225             sub = row.row()
226             sub.operator("object.shape_key_clear", icon='X', text="")
227
228             row = layout.row()
229             row.prop(kb, "name")
230
231             if key.relative:
232                 if ob.active_shape_key_index != 0:
233                     row = layout.row()
234                     row.active = enable_edit_value
235                     row.prop(kb, "value")
236
237                     split = layout.split()
238
239                     col = split.column(align=True)
240                     col.active = enable_edit_value
241                     col.label(text="Range:")
242                     col.prop(kb, "slider_min", text="Min")
243                     col.prop(kb, "slider_max", text="Max")
244
245                     col = split.column(align=True)
246                     col.active = enable_edit_value
247                     col.label(text="Blend:")
248                     col.prop_object(kb, "vertex_group", ob, "vertex_groups", text="")
249                     col.prop_object(kb, "relative_key", key, "keys", text="")
250
251             else:
252                 row = layout.row()
253                 row.active = enable_edit_value
254                 row.prop(key, "slurph")
255
256
257 class DATA_PT_uv_texture(MeshButtonsPanel, bpy.types.Panel):
258     bl_label = "UV Texture"
259     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
260
261     def draw(self, context):
262         layout = self.layout
263
264         me = context.mesh
265
266         row = layout.row()
267         col = row.column()
268
269         col.template_list(me, "uv_textures", me, "active_uv_texture_index", rows=2)
270
271         col = row.column(align=True)
272         col.operator("mesh.uv_texture_add", icon='ZOOMIN', text="")
273         col.operator("mesh.uv_texture_remove", icon='ZOOMOUT', text="")
274
275         lay = me.active_uv_texture
276         if lay:
277             layout.prop(lay, "name")
278
279
280 class DATA_PT_texface(MeshButtonsPanel, bpy.types.Panel):
281     bl_label = "Texture Face"
282     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
283
284     @classmethod
285     def poll(cls, context):
286         ob = context.active_object
287         rd = context.scene.render
288
289         return (context.mode == 'EDIT_MESH') and (rd.engine == 'BLENDER_GAME') and ob and ob.type == 'MESH'
290
291     def draw(self, context):
292         layout = self.layout
293         col = layout.column()
294
295         me = context.mesh
296
297         tf = me.faces.active_tface
298
299         if tf:
300             split = layout.split()
301             col = split.column()
302
303             col.prop(tf, "use_bitmap_text")
304             col.prop(tf, "use_light")
305             col.prop(tf, "hide")
306             col.prop(tf, "use_collision")
307
308             col.prop(tf, "use_blend_shared")
309             col.prop(tf, "use_twoside")
310             col.prop(tf, "use_object_color")
311
312             col = split.column()
313
314             col.prop(tf, "use_halo")
315             col.prop(tf, "use_billboard")
316             col.prop(tf, "use_shadow_cast")
317             col.prop(tf, "use_bitmap_text")
318             col.prop(tf, "use_alpha_sort")
319
320             col = layout.column()
321             col.prop(tf, "blend_type")
322         else:
323             col.label(text="No UV Texture")
324
325
326 class DATA_PT_vertex_colors(MeshButtonsPanel, bpy.types.Panel):
327     bl_label = "Vertex Colors"
328     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
329
330     def draw(self, context):
331         layout = self.layout
332
333         me = context.mesh
334
335         row = layout.row()
336         col = row.column()
337
338         col.template_list(me, "vertex_colors", me, "active_vertex_color_index", rows=2)
339
340         col = row.column(align=True)
341         col.operator("mesh.vertex_color_add", icon='ZOOMIN', text="")
342         col.operator("mesh.vertex_color_remove", icon='ZOOMOUT', text="")
343
344         lay = me.active_vertex_color
345         if lay:
346             layout.prop(lay, "name")
347
348
349 class DATA_PT_custom_props_mesh(MeshButtonsPanel, PropertyPanel, bpy.types.Panel):
350     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
351     _context_path = "object.data"
352
353
354 def register():
355     pass
356
357
358 def unregister():
359     pass
360
361 if __name__ == "__main__":
362     register()