a14e34580c55d13b003b842c8694205b8856afac
[blender-staging.git] / release / scripts / startup / bl_ui / properties_data_bone.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
21 import bpy
22 from bpy.types import Panel
23 from rna_prop_ui import PropertyPanel
24
25
26 class BoneButtonsPanel:
27     bl_space_type = 'PROPERTIES'
28     bl_region_type = 'WINDOW'
29     bl_context = "bone"
30
31     @classmethod
32     def poll(cls, context):
33         return (context.bone or context.edit_bone)
34
35
36 class BONE_PT_context_bone(BoneButtonsPanel, Panel):
37     bl_label = ""
38     bl_options = {'HIDE_HEADER'}
39
40     def draw(self, context):
41         layout = self.layout
42
43         bone = context.bone
44         if not bone:
45             bone = context.edit_bone
46
47         row = layout.row()
48         row.label(text="", icon='BONE_DATA')
49         row.prop(bone, "name", text="")
50
51
52 class BONE_PT_transform(BoneButtonsPanel, Panel):
53     bl_label = "Transform"
54
55     @classmethod
56     def poll(cls, context):
57         if context.edit_bone:
58             return True
59
60         ob = context.object
61         return ob and ob.mode == 'POSE' and context.bone
62
63     def draw(self, context):
64         layout = self.layout
65
66         ob = context.object
67         bone = context.bone
68
69         if bone and ob:
70             pchan = ob.pose.bones[bone.name]
71
72             row = layout.row()
73             col = row.column()
74             col.prop(pchan, "location")
75             col.active = not (bone.parent and bone.use_connect)
76
77             col = row.column()
78             if pchan.rotation_mode == 'QUATERNION':
79                 col.prop(pchan, "rotation_quaternion", text="Rotation")
80             elif pchan.rotation_mode == 'AXIS_ANGLE':
81                 #col.label(text="Rotation")
82                 #col.prop(pchan, "rotation_angle", text="Angle")
83                 #col.prop(pchan, "rotation_axis", text="Axis")
84                 col.prop(pchan, "rotation_axis_angle", text="Rotation")
85             else:
86                 col.prop(pchan, "rotation_euler", text="Rotation")
87
88             row.column().prop(pchan, "scale")
89
90             layout.prop(pchan, "rotation_mode")
91
92         elif context.edit_bone:
93             bone = context.edit_bone
94             row = layout.row()
95             row.column().prop(bone, "head")
96             row.column().prop(bone, "tail")
97
98             col = row.column()
99             sub = col.column(align=True)
100             sub.label(text="Roll:")
101             sub.prop(bone, "roll", text="")
102             sub.label()
103             sub.prop(bone, "lock")
104
105
106 class BONE_PT_transform_locks(BoneButtonsPanel, Panel):
107     bl_label = "Transform Locks"
108     bl_options = {'DEFAULT_CLOSED'}
109
110     @classmethod
111     def poll(cls, context):
112         ob = context.object
113         return ob and ob.mode == 'POSE' and context.bone
114
115     def draw(self, context):
116         layout = self.layout
117
118         ob = context.object
119         bone = context.bone
120         pchan = ob.pose.bones[bone.name]
121
122         split = layout.split(percentage=0.1)
123
124         col = split.column(align=True)
125         col.label(text="")
126         col.label(text="X:")
127         col.label(text="Y:")
128         col.label(text="Z:")
129
130         col = split.column()
131         col.active = not (bone.parent and bone.use_connect)
132         col.prop(pchan, "lock_location", text="Location")
133
134         col = split.column()
135         col.prop(pchan, "lock_rotation", text="Rotation")
136
137         col = split.column()
138         col.prop(pchan, "lock_scale", text="Scale")
139
140         if pchan.rotation_mode in {'QUATERNION', 'AXIS_ANGLE'}:
141             row = layout.row()
142             row.prop(pchan, "lock_rotations_4d", text="Lock Rotation")
143
144             sub = row.row()
145             sub.active = pchan.lock_rotations_4d
146             sub.prop(pchan, "lock_rotation_w", text="W")
147
148
149 class BONE_PT_relations(BoneButtonsPanel, Panel):
150     bl_label = "Relations"
151
152     def draw(self, context):
153         layout = self.layout
154
155         ob = context.object
156         bone = context.bone
157         arm = context.armature
158         pchan = None
159
160         if ob and bone:
161             pchan = ob.pose.bones[bone.name]
162         elif bone is None:
163             bone = context.edit_bone
164
165         split = layout.split()
166
167         col = split.column()
168         col.label(text="Layers:")
169         col.prop(bone, "layers", text="")
170
171         col.separator()
172
173         if ob and pchan:
174             col.label(text="Bone Group:")
175             col.prop_search(pchan, "bone_group", ob.pose, "bone_groups", text="")
176             col.label(text="Object Children:")
177             col.prop(bone, "use_relative_parent")
178
179         col = split.column()
180         col.label(text="Parent:")
181         if context.bone:
182             col.prop(bone, "parent", text="")
183         else:
184             col.prop_search(bone, "parent", arm, "edit_bones", text="")
185
186         sub = col.column()
187         sub.active = (bone.parent is not None)
188         sub.prop(bone, "use_connect")
189         sub.prop(bone, "use_inherit_rotation")
190         sub.prop(bone, "use_inherit_scale")
191         sub = col.column()
192         sub.active = (not bone.parent or not bone.use_connect)
193         sub.prop(bone, "use_local_location")
194
195
196 class BONE_PT_display(BoneButtonsPanel, Panel):
197     bl_label = "Display"
198
199     @classmethod
200     def poll(cls, context):
201         return context.bone
202
203     def draw(self, context):
204         # note. this works ok in edit-mode but isn't
205         # all that useful so disabling for now.
206         layout = self.layout
207
208         ob = context.object
209         bone = context.bone
210         pchan = None
211
212         if ob and bone:
213             pchan = ob.pose.bones[bone.name]
214         elif bone is None:
215             bone = context.edit_bone
216
217         if bone:
218             split = layout.split()
219
220             col = split.column()
221             col.prop(bone, "hide", text="Hide")
222             sub = col.column()
223             sub.active = bool(pchan.custom_shape)
224             sub.prop(bone, "show_wire", text="Wireframe")
225
226             if pchan:
227                 col = split.column()
228
229                 col.label(text="Custom Shape:")
230                 col.prop(pchan, "custom_shape", text="")
231                 if pchan.custom_shape:
232                     col.prop_search(pchan, "custom_shape_transform", ob.pose, "bones", text="At")
233
234
235 class BONE_PT_inverse_kinematics(BoneButtonsPanel, Panel):
236     bl_label = "Inverse Kinematics"
237     bl_options = {'DEFAULT_CLOSED'}
238
239     @classmethod
240     def poll(cls, context):
241         ob = context.object
242         return ob and ob.mode == 'POSE' and context.bone
243
244     def draw(self, context):
245         layout = self.layout
246
247         ob = context.object
248         bone = context.bone
249         pchan = ob.pose.bones[bone.name]
250
251         row = layout.row()
252
253         active = pchan.is_in_ik_chain
254
255         split = layout.split(percentage=0.25)
256         split.prop(pchan, "lock_ik_x", text="X")
257         split.active = active
258         row = split.row()
259         row.prop(pchan, "ik_stiffness_x", text="Stiffness", slider=True)
260         row.active = pchan.lock_ik_x is False and active
261
262         split = layout.split(percentage=0.25)
263         sub = split.row()
264
265         sub.prop(pchan, "use_ik_limit_x", text="Limit")
266         sub.active = pchan.lock_ik_x is False and active
267         sub = split.row(align=True)
268         sub.prop(pchan, "ik_min_x", text="")
269         sub.prop(pchan, "ik_max_x", text="")
270         sub.active = pchan.lock_ik_x is False and pchan.use_ik_limit_x and active
271
272         split = layout.split(percentage=0.25)
273         split.prop(pchan, "lock_ik_y", text="Y")
274         split.active = active
275         row = split.row()
276         row.prop(pchan, "ik_stiffness_y", text="Stiffness", slider=True)
277         row.active = pchan.lock_ik_y is False and active
278
279         split = layout.split(percentage=0.25)
280         sub = split.row()
281
282         sub.prop(pchan, "use_ik_limit_y", text="Limit")
283         sub.active = pchan.lock_ik_y is False and active
284
285         sub = split.row(align=True)
286         sub.prop(pchan, "ik_min_y", text="")
287         sub.prop(pchan, "ik_max_y", text="")
288         sub.active = pchan.lock_ik_y is False and pchan.use_ik_limit_y and active
289
290         split = layout.split(percentage=0.25)
291         split.prop(pchan, "lock_ik_z", text="Z")
292         split.active = active
293         sub = split.row()
294         sub.prop(pchan, "ik_stiffness_z", text="Stiffness", slider=True)
295         sub.active = pchan.lock_ik_z is False and active
296
297         split = layout.split(percentage=0.25)
298         sub = split.row()
299
300         sub.prop(pchan, "use_ik_limit_z", text="Limit")
301         sub.active = pchan.lock_ik_z is False and active
302         sub = split.row(align=True)
303         sub.prop(pchan, "ik_min_z", text="")
304         sub.prop(pchan, "ik_max_z", text="")
305         sub.active = pchan.lock_ik_z is False and pchan.use_ik_limit_z and active
306
307         split = layout.split(percentage=0.25)
308         split.label(text="Stretch:")
309         sub = split.row()
310         sub.prop(pchan, "ik_stretch", text="", slider=True)
311         sub.active = active
312
313         if ob.pose.ik_solver == 'ITASC':
314             split = layout.split()
315             col = split.column()
316             col.prop(pchan, "use_ik_rotation_control", text="Control Rotation")
317             col.active = active
318             col = split.column()
319             col.prop(pchan, "ik_rotation_weight", text="Weight", slider=True)
320             col.active = active
321             # not supported yet
322             #row = layout.row()
323             #row.prop(pchan, "use_ik_linear_control", text="Joint Size")
324             #row.prop(pchan, "ik_linear_weight", text="Weight", slider=True)
325
326
327 class BONE_PT_deform(BoneButtonsPanel, Panel):
328     bl_label = "Deform"
329     bl_options = {'DEFAULT_CLOSED'}
330
331     def draw_header(self, context):
332         bone = context.bone
333
334         if not bone:
335             bone = context.edit_bone
336
337         self.layout.prop(bone, "use_deform", text="")
338
339     def draw(self, context):
340         layout = self.layout
341
342         bone = context.bone
343
344         if not bone:
345             bone = context.edit_bone
346
347         layout.active = bone.use_deform
348
349         split = layout.split()
350
351         col = split.column()
352         col.label(text="Envelope:")
353
354         sub = col.column(align=True)
355         sub.prop(bone, "envelope_distance", text="Distance")
356         sub.prop(bone, "envelope_weight", text="Weight")
357         col.prop(bone, "use_envelope_multiply", text="Multiply")
358
359         sub = col.column(align=True)
360         sub.label(text="Radius:")
361         sub.prop(bone, "head_radius", text="Head")
362         sub.prop(bone, "tail_radius", text="Tail")
363
364         col = split.column()
365         col.label(text="Curved Bones:")
366
367         sub = col.column(align=True)
368         sub.prop(bone, "bbone_segments", text="Segments")
369         sub.prop(bone, "bbone_in", text="Ease In")
370         sub.prop(bone, "bbone_out", text="Ease Out")
371
372
373 class BONE_PT_custom_props(BoneButtonsPanel, PropertyPanel, Panel):
374     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
375     _property_type = bpy.types.Bone, bpy.types.EditBone, bpy.types.PoseBone
376
377     @property
378     def _context_path(self):
379         obj = bpy.context.object
380         if obj and obj.mode == 'POSE':
381             return "active_pose_bone"
382         else:
383             return "active_bone"
384
385 if __name__ == "__main__":  # only for live edit.
386     bpy.utils.register_module(__name__)