Shape Keys
[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                 group = ob.active_vertex_group
75
76                 rows = 2
77                 if group:
78                         rows= 5
79
80                 row = layout.row()
81                 row.template_list(ob, "vertex_groups", ob, "active_vertex_group_index", rows=rows)
82
83                 col = row.column(align=True)
84                 col.itemO("object.vertex_group_add", icon='ICON_ZOOMIN', text="")
85                 col.itemO("object.vertex_group_remove", icon='ICON_ZOOMOUT', text="")
86
87                 col.itemO("object.vertex_group_copy", icon='ICON_COPY_ID', text="")
88                 if ob.data.users > 1:
89                         col.itemO("object.vertex_group_copy_to_linked", icon='ICON_LINK_AREA', text="")
90
91                 if group:
92                         row = layout.row()
93                         row.itemR(group, "name")
94
95                 if ob.mode == 'EDIT' and len(ob.vertex_groups) > 0:
96                         row = layout.row()
97                         
98                         sub = row.row(align=True)
99                         sub.itemO("object.vertex_group_assign", text="Assign")
100                         sub.itemO("object.vertex_group_remove_from", text="Remove")
101                         
102                         sub = row.row(align=True)
103                         sub.itemO("object.vertex_group_select", text="Select")
104                         sub.itemO("object.vertex_group_deselect", text="Deselect")
105
106                         layout.itemR(context.tool_settings, "vertex_group_weight", text="Weight")
107
108 class DATA_PT_shape_keys(DataButtonsPanel):
109         __label__ = "Shape Keys"
110         
111         def poll(self, context):
112                 return (context.object and context.object.type in ('MESH', 'LATTICE', 'CURVE', 'SURFACE'))
113
114         def draw(self, context):
115                 layout = self.layout
116                 
117                 ob = context.object
118                 key = ob.data.shape_keys
119                 kb = ob.active_shape_key
120
121                 enable_edit = ob.mode != 'EDIT'
122                 enable_edit_value = False
123
124                 if ob.shape_key_lock == False:
125                         if enable_edit or (ob.type == 'MESH' and ob.shape_key_edit_mode):
126                                 enable_edit_value = True
127
128                 row = layout.row()
129
130                 rows = 2
131                 if kb:
132                         rows= 5
133                 row.template_list(key, "keys", ob, "active_shape_key_index", rows=rows)
134
135                 col = row.column()
136
137                 subcol = col.column(align=True)
138                 subcol.itemO("object.shape_key_add", icon='ICON_ZOOMIN', text="")
139                 subcol.itemO("object.shape_key_remove", icon='ICON_ZOOMOUT', text="")
140
141                 if kb:
142                         col.itemS()
143
144                         subcol = col.column(align=True)
145                         subcol.item_enumO("object.shape_key_move", "type", 'UP', icon='ICON_TRIA_UP', text="")
146                         subcol.item_enumO("object.shape_key_move", "type", 'DOWN', icon='ICON_TRIA_DOWN', text="")
147
148                         split = layout.split(percentage=0.4)
149                         sub = split.row()
150                         sub.enabled = enable_edit
151                         sub.itemR(key, "relative")
152
153                         sub = split.row()
154                         sub.alignment = 'RIGHT'
155
156                         subrow = sub.row(align=True)
157                         subrow.itemR(ob, "shape_key_lock", icon='ICON_UNPINNED', text="")
158                         subrow.itemR(kb, "mute", icon='ICON_MUTE_IPO_OFF', text="")
159                         subrow.itemO("object.shape_key_clear", icon='ICON_X', text="")
160
161                         sub.itemO("object.shape_key_mirror", icon='ICON_MOD_MIRROR', text="")
162
163                         sub.itemR(ob, "shape_key_edit_mode", text="")
164
165                         row = layout.row()
166                         row.enabled = enable_edit_value
167                         row.itemR(kb, "name")
168
169                         if key.relative:
170                                 if ob.active_shape_key_index != 0:
171                                         row = layout.row()
172                                         row.enabled = enable_edit_value
173                                         row.itemR(kb, "value")
174                                         
175                                         split = layout.split()
176                                         sub = split.column(align=True)
177                                         sub.enabled = enable_edit_value
178                                         sub.itemL(text="Range:")
179                                         sub.itemR(kb, "slider_min", text="Min")
180                                         sub.itemR(kb, "slider_max", text="Max")
181                                         
182                                         sub = split.column(align=True)
183                                         sub.enabled = enable_edit_value
184                                         sub.itemL(text="Blend:")
185                                         sub.item_pointerR(kb, "vertex_group", ob, "vertex_groups", text="")
186                                         sub.item_pointerR(kb, "relative_key", key, "keys", text="")
187                                         
188                         else:
189                                 row = layout.row()
190                                 row.enabled = enable_edit
191                                 row.itemR(key, "slurph")
192
193 class DATA_PT_uv_texture(DataButtonsPanel):
194         __label__ = "UV Texture"
195         
196         def draw(self, context):
197                 layout = self.layout
198                 
199                 me = context.mesh
200
201                 row = layout.row()
202                 col = row.column()
203                 
204                 col.template_list(me, "uv_textures", me, "active_uv_texture_index", rows=2)
205
206                 col = row.column(align=True)
207                 col.itemO("mesh.uv_texture_add", icon='ICON_ZOOMIN', text="")
208                 col.itemO("mesh.uv_texture_remove", icon='ICON_ZOOMOUT', text="")
209
210                 lay = me.active_uv_texture
211                 if lay:
212                         layout.itemR(lay, "name")
213
214 class DATA_PT_vertex_colors(DataButtonsPanel):
215         __label__ = "Vertex Colors"
216         
217         def draw(self, context):
218                 layout = self.layout
219                 
220                 me = context.mesh
221
222                 row = layout.row()
223                 col = row.column()
224
225                 col.template_list(me, "vertex_colors", me, "active_vertex_color_index", rows=2)
226
227                 col = row.column(align=True)
228                 col.itemO("mesh.vertex_color_add", icon='ICON_ZOOMIN', text="")
229                 col.itemO("mesh.vertex_color_remove", icon='ICON_ZOOMOUT', text="")
230
231                 lay = me.active_vertex_color
232                 if lay:
233                         layout.itemR(lay, "name")
234
235 bpy.types.register(DATA_PT_context_mesh)
236 bpy.types.register(DATA_PT_normals)
237 bpy.types.register(DATA_PT_settings)
238 bpy.types.register(DATA_PT_vertex_groups)
239 bpy.types.register(DATA_PT_shape_keys)
240 bpy.types.register(DATA_PT_uv_texture)
241 bpy.types.register(DATA_PT_vertex_colors)
242