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