5971e4492cebf7ae08e30df179ebedae573eca99
[blender-staging.git] / release / scripts / ui / buttons_data_bone.py
1
2 import bpy
3  
4 class BoneButtonsPanel(bpy.types.Panel):
5         __space_type__ = 'PROPERTIES'
6         __region_type__ = 'WINDOW'
7         __context__ = "bone"
8         
9         def poll(self, context):
10                 return (context.bone or context.edit_bone)
11
12 class BONE_PT_context_bone(BoneButtonsPanel):
13         __show_header__ = False
14
15         def draw(self, context):
16                 layout = self.layout
17                 
18                 bone = context.bone
19                 if not bone:
20                         bone = context.edit_bone
21                 
22                 row = layout.row()
23                 row.itemL(text="", icon='ICON_BONE_DATA')
24                 row.itemR(bone, "name", text="")
25
26 class BONE_PT_transform(BoneButtonsPanel):
27         __label__ = "Transform"
28
29         def draw(self, context):
30                 layout = self.layout
31                 
32                 ob = context.object
33                 bone = context.bone
34                 if not bone:
35                         bone = context.edit_bone
36
37                         row = layout.row()
38                         row.column().itemR(bone, "head")
39                         row.column().itemR(bone, "tail")
40
41                         col = row.column()
42                         sub = col.column(align=True)
43                         sub.itemL(text="Roll:")
44                         sub.itemR(bone, "roll", text="")
45                         sub.itemL()
46                         sub.itemR(bone, "locked")
47
48                 else:
49                         pchan = ob.pose.pose_channels[context.bone.name]
50
51                         layout.itemR(pchan, "rotation_mode")
52
53                         row = layout.row()
54                         col = row.column()
55                         col.itemR(pchan, "location")
56                         col.active = not (bone.parent and bone.connected)
57
58                         col = row.column()
59                         if pchan.rotation_mode == 'QUATERNION':
60                                 col.itemR(pchan, "rotation_quaternion", text="Rotation")
61                         elif pchan.rotation_mode == 'AXIS_ANGLE':
62                                 #col.itemL(text="Rotation")
63                                 #col.itemR(pchan, "rotation_angle", text="Angle")
64                                 #col.itemR(pchan, "rotation_axis", text="Axis")
65                                 col.itemR(pchan, "rotation_axis_angle", text="Rotation")
66                         else:
67                                 col.itemR(pchan, "rotation_euler", text="Rotation")
68
69                         row.column().itemR(pchan, "scale")
70                                 
71 class BONE_PT_transform_locks(BoneButtonsPanel):
72         __label__ = "Transform Locks"
73         __default_closed__ = True
74         
75         def poll(self, context):
76                 return context.bone
77         
78         def draw(self, context):
79                 layout = self.layout
80                 
81                 ob = context.object
82                 bone = context.bone
83                 pchan = ob.pose.pose_channels[context.bone.name]
84                 
85                 row = layout.row()
86                 col = row.column()
87                 col.itemR(pchan, "lock_location")
88                 col.active = not (bone.parent and bone.connected)
89                 
90                 col = row.column()
91                 if pchan.rotation_mode in ('QUATERNION', 'AXIS_ANGLE'):
92                         col.itemR(pchan, "lock_rotations_4d", text="Lock Rotation")
93                         if pchan.lock_rotations_4d:
94                                 col.itemR(pchan, "lock_rotation_w", text="W")
95                         col.itemR(pchan, "lock_rotation", text="")
96                 else:
97                         col.itemR(pchan, "lock_rotation", text="Rotation")
98                 
99                 row.column().itemR(pchan, "lock_scale")
100
101 class BONE_PT_bone(BoneButtonsPanel):
102         __label__ = "Bone"
103
104         def draw(self, context):
105                 layout = self.layout
106                 
107                 ob = context.object
108                 bone = context.bone
109                 arm = context.armature
110                 
111                 if not bone:
112                         bone = context.edit_bone
113                         pchan = None
114                 else:
115                         pchan = ob.pose.pose_channels[context.bone.name]
116
117                 split = layout.split()
118
119                 col = split.column()
120                 col.itemL(text="Parent:")
121                 if context.bone:
122                         col.itemR(bone, "parent", text="")
123                 else:
124                         col.item_pointerR(bone, "parent", arm, "edit_bones", text="")
125                 
126                 row = col.row()
127                 row.active = bone.parent != None
128                 row.itemR(bone, "connected")
129                 
130                 col.itemL(text="Layers:")
131                 col.itemR(bone, "layer", text="")
132                 
133                 col = split.column()
134                 col.itemL(text="Inherit:")
135                 col.itemR(bone, "hinge", text="Rotation")
136                 col.itemR(bone, "inherit_scale", text="Scale")
137                 col.itemL(text="Display:")
138                 col.itemR(bone, "draw_wire", text="Wireframe")
139                 col.itemR(bone, "hidden", text="Hide")
140                 
141                 if ob and pchan:
142                         split = layout.split()
143                         
144                         col = split.column()
145                         col.itemL(text="Bone Group:")
146                         col.item_pointerR(pchan, "bone_group", ob.pose, "bone_groups", text="")
147                         
148                         col = split.column()
149                         col.itemL(text="Custom Shape:")
150                         col.itemR(pchan, "custom_shape", text="")
151
152 class BONE_PT_inverse_kinematics(BoneButtonsPanel):
153         __label__ = "Inverse Kinematics"
154         __default_closed__ = True
155         
156         def poll(self, context):
157                 ob = context.object
158                 bone = context.bone
159
160                 if ob and context.bone:
161                         pchan = ob.pose.pose_channels[context.bone.name]
162                         return pchan.has_ik
163                 
164                 return False
165
166         def draw(self, context):
167                 layout = self.layout
168                 
169                 ob = context.object
170                 bone = context.bone
171                 pchan = ob.pose.pose_channels[context.bone.name]
172
173                 row = layout.row()
174                 row.itemR(ob.pose, "ik_solver")
175
176                 split = layout.split(percentage=0.25)
177                 split.itemR(pchan, "ik_dof_x", text="X")
178                 row = split.row()
179                 row.itemR(pchan, "ik_stiffness_x", text="Stiffness", slider=True)
180                 row.active = pchan.ik_dof_x
181
182                 split = layout.split(percentage=0.25)
183                 row = split.row()
184                 row.itemR(pchan, "ik_limit_x", text="Limit")
185                 row.active = pchan.ik_dof_x
186                 row = split.row(align=True)
187                 row.itemR(pchan, "ik_min_x", text="")
188                 row.itemR(pchan, "ik_max_x", text="")
189                 row.active = pchan.ik_dof_x and pchan.ik_limit_x
190
191                 split = layout.split(percentage=0.25)
192                 split.itemR(pchan, "ik_dof_y", text="Y")
193                 row = split.row()
194                 row.itemR(pchan, "ik_stiffness_y", text="Stiffness", slider=True)
195                 row.active = pchan.ik_dof_y
196
197                 split = layout.split(percentage=0.25)
198                 row = split.row()
199                 row.itemR(pchan, "ik_limit_y", text="Limit")
200                 row.active = pchan.ik_dof_y
201                 row = split.row(align=True)
202                 row.itemR(pchan, "ik_min_y", text="")
203                 row.itemR(pchan, "ik_max_y", text="")
204                 row.active = pchan.ik_dof_y and pchan.ik_limit_y
205
206                 split = layout.split(percentage=0.25)
207                 split.itemR(pchan, "ik_dof_z", text="Z")
208                 row = split.row()
209                 row.itemR(pchan, "ik_stiffness_z", text="Stiffness", slider=True)
210                 row.active = pchan.ik_dof_z
211
212                 split = layout.split(percentage=0.25)
213                 row = split.row()
214                 row.itemR(pchan, "ik_limit_z", text="Limit")
215                 row.active = pchan.ik_dof_z
216                 row = split.row(align=True)
217                 row.itemR(pchan, "ik_min_z", text="")
218                 row.itemR(pchan, "ik_max_z", text="")
219                 row.active = pchan.ik_dof_z and pchan.ik_limit_z
220                 split = layout.split()
221                 split.itemR(pchan, "ik_stretch", text="Stretch", slider=True)
222                 split.itemL()
223
224                 if ob.pose.ik_solver == "ITASC":
225                         layout.itemL(text="Joint constraint:")
226                         split = layout.split(percentage=0.3)
227                         row = split.row()
228                         row.itemR(pchan, "ik_rot_control", text="Rotation")
229                         row = split.row()
230                         row.itemR(pchan, "ik_rot_weight", text="Weight", slider=True)
231                         row.active = pchan.ik_rot_control
232                         # not supported yet
233                         #split = layout.split(percentage=0.3)
234                         #row = split.row()
235                         #row.itemR(pchan, "ik_lin_control", text="Size")
236                         #row = split.row()
237                         #row.itemR(pchan, "ik_lin_weight", text="Weight", slider=True)
238                         #row.active = pchan.ik_lin_control
239
240 class BONE_PT_deform(BoneButtonsPanel):
241         __label__ = "Deform"
242         __default_closed__ = True
243
244         def draw_header(self, context):
245                 bone = context.bone
246                 
247                 if not bone:
248                         bone = context.edit_bone
249                         
250                 self.layout.itemR(bone, "deform", text="")
251
252         def draw(self, context):
253                 layout = self.layout
254                 
255                 bone = context.bone
256                 
257                 if not bone:
258                         bone = context.edit_bone
259         
260                 layout.active = bone.deform
261                         
262                 split = layout.split()
263
264                 col = split.column()
265                 col.itemL(text="Envelope:")
266                 
267                 sub = col.column(align=True)
268                 sub.itemR(bone, "envelope_distance", text="Distance")
269                 sub.itemR(bone, "envelope_weight", text="Weight")
270                 col.itemR(bone, "multiply_vertexgroup_with_envelope", text="Multiply")
271
272                 sub = col.column(align=True)
273                 sub.itemL(text="Radius:")
274                 sub.itemR(bone, "head_radius", text="Head")
275                 sub.itemR(bone, "tail_radius", text="Tail")
276
277                 col = split.column()
278                 col.itemL(text="Curved Bones:")
279                 
280                 sub = col.column(align=True)
281                 sub.itemR(bone, "bbone_segments", text="Segments")
282                 sub.itemR(bone, "bbone_in", text="Ease In")
283                 sub.itemR(bone, "bbone_out", text="Ease Out")
284                 
285                 col.itemL(text="Offset:")
286                 col.itemR(bone, "cyclic_offset")
287
288 class BONE_PT_iksolver_itasc(BoneButtonsPanel):
289         __idname__ = "BONE_PT_iksolver_itasc"
290         __label__ = "iTaSC parameters"
291         __default_closed__ = True
292         
293         def poll(self, context):
294                 ob = context.object
295                 bone = context.bone
296
297                 if ob and context.bone:
298                         pchan = ob.pose.pose_channels[context.bone.name]
299                         return pchan.has_ik and ob.pose.ik_solver == "ITASC" and ob.pose.ik_param
300                 
301                 return False
302
303         def draw(self, context):
304                 layout = self.layout
305
306                 ob = context.object
307                 itasc = ob.pose.ik_param
308
309                 layout.row().itemR(itasc, "simulation")
310                 if itasc.simulation:
311                         split = layout.split()
312                         row = split.row()
313                         row.itemR(itasc, "reiteration")
314                         row = split.row()
315                         if itasc.reiteration:
316                                 itasc.initial_reiteration = True
317                         row.itemR(itasc, "initial_reiteration")
318                         row.active = not itasc.reiteration
319                 
320                 flow = layout.column_flow()
321                 flow.itemR(itasc, "precision")
322                 flow.itemR(itasc, "num_iter")
323                 flow.active = not itasc.simulation or itasc.initial_reiteration or itasc.reiteration
324
325                 if itasc.simulation:            
326                         layout.itemR(itasc, "auto_step")
327                         row = layout.row()
328                         if itasc.auto_step:
329                                 row.itemR(itasc, "min_step")
330                                 row.itemR(itasc, "max_step")
331                         else:
332                                 row.itemR(itasc, "num_step")
333                         
334                 layout.itemR(itasc, "solver")
335                 if itasc.simulation:
336                         layout.itemR(itasc, "feedback")
337                         layout.itemR(itasc, "max_velocity")
338                 if itasc.solver == "DLS":
339                         row = layout.row()
340                         row.itemR(itasc, "dampmax")
341                         row.itemR(itasc, "dampeps")
342
343 bpy.types.register(BONE_PT_context_bone)
344 bpy.types.register(BONE_PT_transform)
345 bpy.types.register(BONE_PT_transform_locks)
346 bpy.types.register(BONE_PT_bone)
347 bpy.types.register(BONE_PT_deform)
348 bpy.types.register(BONE_PT_inverse_kinematics)
349 bpy.types.register(BONE_PT_iksolver_itasc)