5ae004514bd8de1f9cca010053e60d3ac6b62a90
[blender-staging.git] / release / scripts / ui / buttons_data_mesh.py
1
2 import bpy
3
4 class DataButtonsPanel(bpy.types.Panel):
5         __space_type__ = 'PROPERTIES'
6         __region_type__ = 'WINDOW'
7         __context__ = "data"
8         
9         def poll(self, context):
10                 return context.mesh
11
12 class DATA_PT_context_mesh(DataButtonsPanel):
13         __show_header__ = False
14         
15         def draw(self, context):
16                 layout = self.layout
17                 
18                 ob = context.object
19                 mesh = context.mesh
20                 space = context.space_data
21
22                 split = layout.split(percentage=0.65)
23
24                 if ob:
25                         split.template_ID(ob, "data")
26                         split.itemS()
27                 elif mesh:
28                         split.template_ID(space, "pin_id")
29                         split.itemS()
30
31 class DATA_PT_normals(DataButtonsPanel):
32         __label__ = "Normals"
33
34         def draw(self, context):
35                 layout = self.layout
36                 
37                 mesh = context.mesh
38                 
39                 split = layout.split()
40                 
41                 col = split.column()
42                 col.itemR(mesh, "autosmooth")
43                 sub = col.column()
44                 sub.active = mesh.autosmooth
45                 sub.itemR(mesh, "autosmooth_angle", text="Angle")
46                 
47                 col = split.column()
48                 col.itemR(mesh, "vertex_normal_flip")
49                 col.itemR(mesh, "double_sided")
50
51 class DATA_PT_settings(DataButtonsPanel):
52         __label__ = "Settings"
53
54         def draw(self, context):
55                 layout = self.layout
56                 
57                 mesh = context.mesh
58                 
59                 split = layout.split()
60                 
61                 col = split.column()
62                 col.itemR(mesh, "texture_mesh")
63
64 class DATA_PT_vertex_groups(DataButtonsPanel):
65         __label__ = "Vertex Groups"
66         
67         def poll(self, context):
68                 return (context.object and context.object.type in ('MESH', 'LATTICE'))
69
70         def draw(self, context):
71                 layout = self.layout
72                 
73                 ob = context.object
74
75                 row = layout.row()
76                 row.template_list(ob, "vertex_groups", ob, "active_vertex_group_index", rows=2)
77
78                 col = row.column(align=True)
79                 col.itemO("object.vertex_group_add", icon='ICON_ZOOMIN', text="")
80                 col.itemO("object.vertex_group_remove", icon='ICON_ZOOMOUT', text="")
81
82                 col.itemO("object.vertex_group_copy", icon='ICON_COPY_ID', text="")
83                 if ob.data.users > 1:
84                         col.itemO("object.vertex_group_copy_to_linked", icon='ICON_LINK_AREA', text="")
85
86                 group = ob.active_vertex_group
87                 if group:
88                         row = layout.row()
89                         row.itemR(group, "name")
90
91                 if ob.mode == 'EDIT' and len(ob.vertex_groups) > 0:
92                         row = layout.row()
93                         
94                         sub = row.row(align=True)
95                         sub.itemO("object.vertex_group_assign", text="Assign")
96                         sub.itemO("object.vertex_group_remove_from", text="Remove")
97                         
98                         sub = row.row(align=True)
99                         sub.itemO("object.vertex_group_select", text="Select")
100                         sub.itemO("object.vertex_group_deselect", text="Deselect")
101
102                         layout.itemR(context.tool_settings, "vertex_group_weight", text="Weight")
103
104 class DATA_PT_shape_keys(DataButtonsPanel):
105         __label__ = "Shape Keys"
106         
107         def poll(self, context):
108                 return (context.object and context.object.type in ('MESH', 'LATTICE', 'CURVE', 'SURFACE'))
109
110         def draw(self, context):
111                 layout = self.layout
112                 
113                 ob = context.object
114                 key = ob.data.shape_keys
115                 kb = ob.active_shape_key
116
117                 row = layout.row()
118                 row.template_list(key, "keys", ob, "active_shape_key_index", rows=2)
119
120                 col = row.column()
121
122                 subcol = col.column(align=True)
123                 subcol.itemO("object.shape_key_add", icon='ICON_ZOOMIN', text="")
124                 subcol.itemO("object.shape_key_remove", icon='ICON_ZOOMOUT', text="")
125
126                 if kb:
127                         subcol.itemO("object.shape_key_mirror", icon='ICON_MOD_MIRROR', text="")
128                         
129                         col.itemS()
130
131                         subcol = col.column(align=True)
132                         subcol.item_enumO("object.shape_key_move", "type", 'UP', icon='ICON_TRIA_UP', text="")
133                         subcol.item_enumO("object.shape_key_move", "type", 'DOWN', icon='ICON_TRIA_DOWN', text="")
134                         
135                         col.itemS()
136
137                         subcol = col.column(align=True)
138                         subcol.itemR(ob, "shape_key_lock", icon='ICON_UNPINNED', text="")
139                         subcol.itemR(kb, "mute", icon='ICON_MUTE_IPO_OFF', text="")
140
141                         if key.relative:
142                                 row = layout.row()
143                                 row.itemR(key, "relative")
144                                 row.itemL()
145
146                                 row = layout.row()
147                                 row.itemR(kb, "name")
148
149                                 if ob.active_shape_key_index != 0:
150                                         
151                                         row = layout.row()
152                                         row.enabled = ob.shape_key_lock == False
153                                         row.itemR(kb, "value")
154                                         row.itemO("object.shape_key_clear", icon='ICON_X', text="")
155                                         
156                                         split = layout.split()
157                                         sub = split.column(align=True)
158                                         sub.enabled = ob.shape_key_lock == False
159                                         sub.itemL(text="Range:")
160                                         sub.itemR(kb, "slider_min", text="Min")
161                                         sub.itemR(kb, "slider_max", text="Max")
162                                         
163                                         sub = split.column(align=True)
164                                         sub.itemL(text="Blend:")
165                                         sub.item_pointerR(kb, "vertex_group", ob, "vertex_groups", text="")
166                                         sub.item_pointerR(kb, "relative_key", key, "keys", text="")
167                                         
168                         else:
169                                 row = layout.row()
170                                 row.itemR(key, "relative")
171                                 row.itemR(key, "slurph")
172
173                                 layout.itemR(kb, "name")
174
175                 if ob.mode == 'EDIT':
176                         layout.enabled = False
177
178 class DATA_PT_uv_texture(DataButtonsPanel):
179         __label__ = "UV Texture"
180         
181         def draw(self, context):
182                 layout = self.layout
183                 
184                 me = context.mesh
185
186                 row = layout.row()
187                 col = row.column()
188                 
189                 col.template_list(me, "uv_textures", me, "active_uv_texture_index", rows=2)
190
191                 col = row.column(align=True)
192                 col.itemO("mesh.uv_texture_add", icon='ICON_ZOOMIN', text="")
193                 col.itemO("mesh.uv_texture_remove", icon='ICON_ZOOMOUT', text="")
194
195                 lay = me.active_uv_texture
196                 if lay:
197                         layout.itemR(lay, "name")
198
199 class DATA_PT_vertex_colors(DataButtonsPanel):
200         __label__ = "Vertex Colors"
201         
202         def draw(self, context):
203                 layout = self.layout
204                 
205                 me = context.mesh
206
207                 row = layout.row()
208                 col = row.column()
209
210                 col.template_list(me, "vertex_colors", me, "active_vertex_color_index", rows=2)
211
212                 col = row.column(align=True)
213                 col.itemO("mesh.vertex_color_add", icon='ICON_ZOOMIN', text="")
214                 col.itemO("mesh.vertex_color_remove", icon='ICON_ZOOMOUT', text="")
215
216                 lay = me.active_vertex_color
217                 if lay:
218                         layout.itemR(lay, "name")
219
220 bpy.types.register(DATA_PT_context_mesh)
221 bpy.types.register(DATA_PT_normals)
222 bpy.types.register(DATA_PT_settings)
223 bpy.types.register(DATA_PT_vertex_groups)
224 bpy.types.register(DATA_PT_shape_keys)
225 bpy.types.register(DATA_PT_uv_texture)
226 bpy.types.register(DATA_PT_vertex_colors)
227