Merge branch 'master' into blender2.8
[blender.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_curved(BoneButtonsPanel, Panel):
150     bl_label = "Bendy Bones"
151     #bl_options = {'DEFAULT_CLOSED'}
152
153     def draw(self, context):
154         ob = context.object
155         bone = context.bone
156         # arm = context.armature
157         pchan = None
158
159         if ob and bone:
160             pchan = ob.pose.bones[bone.name]
161             bbone = pchan
162         elif bone is None:
163             bone = context.edit_bone
164             bbone = bone
165         else:
166             bbone = bone
167
168         layout = self.layout
169         layout.prop(bone, "bbone_segments", text="Segments")
170
171         col = layout.column()
172         col.active = bone.bbone_segments > 1
173
174         row = col.row()
175         sub = row.column(align=True)
176         sub.label(text="Curve XY Offsets:")
177         sub.prop(bbone, "bbone_curveinx", text="In X")
178         sub.prop(bbone, "bbone_curveoutx", text="Out X")
179         sub.prop(bbone, "bbone_curveiny", text="In Y")
180         sub.prop(bbone, "bbone_curveouty", text="Out Y")
181
182         sub = row.column(align=True)
183         sub.label("Roll:")
184         sub.prop(bbone, "bbone_rollin", text="In")
185         sub.prop(bbone, "bbone_rollout", text="Out")
186         sub.prop(bone, "use_endroll_as_inroll")
187
188         row = col.row()
189         sub = row.column(align=True)
190         sub.label(text="Scale:")
191         sub.prop(bbone, "bbone_scalein", text="In")
192         sub.prop(bbone, "bbone_scaleout", text="Out")
193
194         sub = row.column(align=True)
195         sub.label("Easing:")
196         sub.prop(bbone, "bbone_easein", text="In")
197         sub.prop(bbone, "bbone_easeout", text="Out")
198
199         if pchan:
200             layout.separator()
201
202             col = layout.column()
203             col.prop(pchan, "use_bbone_custom_handles")
204
205             row = col.row()
206             row.active = pchan.use_bbone_custom_handles
207
208             sub = row.column(align=True)
209             sub.label(text="In:")
210             sub.prop_search(pchan, "bbone_custom_handle_start", ob.pose, "bones", text="")
211             sub.prop(pchan, "use_bbone_relative_start_handle", text="Relative")
212
213             sub = row.column(align=True)
214             sub.label(text="Out:")
215             sub.prop_search(pchan, "bbone_custom_handle_end", ob.pose, "bones", text="")
216             sub.prop(pchan, "use_bbone_relative_end_handle", text="Relative")
217
218
219 class BONE_PT_relations(BoneButtonsPanel, Panel):
220     bl_label = "Relations"
221
222     def draw(self, context):
223         layout = self.layout
224
225         ob = context.object
226         bone = context.bone
227         arm = context.armature
228         pchan = None
229
230         if ob and bone:
231             pchan = ob.pose.bones[bone.name]
232         elif bone is None:
233             bone = context.edit_bone
234
235         split = layout.split()
236
237         col = split.column()
238         col.label(text="Layers:")
239         col.prop(bone, "layers", text="")
240
241         col.separator()
242
243         if ob and pchan:
244             col.label(text="Bone Group:")
245             col.prop_search(pchan, "bone_group", ob.pose, "bone_groups", text="")
246             col.label(text="Object Children:")
247             col.prop(bone, "use_relative_parent")
248
249         col = split.column()
250         col.label(text="Parent:")
251         if context.bone:
252             col.prop(bone, "parent", text="")
253         else:
254             col.prop_search(bone, "parent", arm, "edit_bones", text="")
255
256         sub = col.column()
257         sub.active = (bone.parent is not None)
258         sub.prop(bone, "use_connect")
259         sub.prop(bone, "use_inherit_rotation")
260         sub.prop(bone, "use_inherit_scale")
261         sub = col.column()
262         sub.active = (not bone.parent or not bone.use_connect)
263         sub.prop(bone, "use_local_location")
264
265
266 class BONE_PT_display(BoneButtonsPanel, Panel):
267     bl_label = "Display"
268
269     @classmethod
270     def poll(cls, context):
271         return context.bone
272
273     def draw(self, context):
274         # note. this works ok in edit-mode but isn't
275         # all that useful so disabling for now.
276         layout = self.layout
277
278         ob = context.object
279         bone = context.bone
280         pchan = None
281
282         if ob and bone:
283             pchan = ob.pose.bones[bone.name]
284         elif bone is None:
285             bone = context.edit_bone
286
287         if bone:
288             split = layout.split()
289
290             col = split.column()
291             col.prop(bone, "hide", text="Hide")
292             sub = col.column()
293             sub.active = bool(pchan and pchan.custom_shape)
294             sub.prop(bone, "show_wire", text="Wireframe")
295
296             if pchan:
297                 col = split.column()
298
299                 col.label(text="Custom Shape:")
300                 col.prop(pchan, "custom_shape", text="")
301                 if pchan.custom_shape:
302                     col.prop(pchan, "use_custom_shape_bone_size", text="Bone Size")
303                     col.prop(pchan, "custom_shape_scale", text="Scale")
304                     col.prop_search(pchan, "custom_shape_transform", ob.pose, "bones", text="At")
305
306
307 class BONE_PT_inverse_kinematics(BoneButtonsPanel, Panel):
308     bl_label = "Inverse Kinematics"
309     bl_options = {'DEFAULT_CLOSED'}
310
311     @classmethod
312     def poll(cls, context):
313         ob = context.object
314         return ob and ob.mode == 'POSE' and context.bone
315
316     def draw(self, context):
317         layout = self.layout
318
319         ob = context.object
320         bone = context.bone
321         pchan = ob.pose.bones[bone.name]
322
323         row = layout.row()
324
325         active = pchan.is_in_ik_chain
326
327         split = layout.split(percentage=0.25)
328         split.prop(pchan, "lock_ik_x", text="X")
329         split.active = active
330         row = split.row()
331         row.prop(pchan, "ik_stiffness_x", text="Stiffness", slider=True)
332         row.active = pchan.lock_ik_x is False and active
333
334         split = layout.split(percentage=0.25)
335         sub = split.row()
336
337         sub.prop(pchan, "use_ik_limit_x", text="Limit")
338         sub.active = pchan.lock_ik_x is False and active
339         sub = split.row(align=True)
340         sub.prop(pchan, "ik_min_x", text="")
341         sub.prop(pchan, "ik_max_x", text="")
342         sub.active = pchan.lock_ik_x is False and pchan.use_ik_limit_x and active
343
344         split = layout.split(percentage=0.25)
345         split.prop(pchan, "lock_ik_y", text="Y")
346         split.active = active
347         row = split.row()
348         row.prop(pchan, "ik_stiffness_y", text="Stiffness", slider=True)
349         row.active = pchan.lock_ik_y is False and active
350
351         split = layout.split(percentage=0.25)
352         sub = split.row()
353
354         sub.prop(pchan, "use_ik_limit_y", text="Limit")
355         sub.active = pchan.lock_ik_y is False and active
356
357         sub = split.row(align=True)
358         sub.prop(pchan, "ik_min_y", text="")
359         sub.prop(pchan, "ik_max_y", text="")
360         sub.active = pchan.lock_ik_y is False and pchan.use_ik_limit_y and active
361
362         split = layout.split(percentage=0.25)
363         split.prop(pchan, "lock_ik_z", text="Z")
364         split.active = active
365         sub = split.row()
366         sub.prop(pchan, "ik_stiffness_z", text="Stiffness", slider=True)
367         sub.active = pchan.lock_ik_z is False and active
368
369         split = layout.split(percentage=0.25)
370         sub = split.row()
371
372         sub.prop(pchan, "use_ik_limit_z", text="Limit")
373         sub.active = pchan.lock_ik_z is False and active
374         sub = split.row(align=True)
375         sub.prop(pchan, "ik_min_z", text="")
376         sub.prop(pchan, "ik_max_z", text="")
377         sub.active = pchan.lock_ik_z is False and pchan.use_ik_limit_z and active
378
379         split = layout.split(percentage=0.25)
380         split.label(text="Stretch:")
381         sub = split.row()
382         sub.prop(pchan, "ik_stretch", text="", slider=True)
383         sub.active = active
384
385         if ob.pose.ik_solver == 'ITASC':
386             split = layout.split()
387             col = split.column()
388             col.prop(pchan, "use_ik_rotation_control", text="Control Rotation")
389             col.active = active
390             col = split.column()
391             col.prop(pchan, "ik_rotation_weight", text="Weight", slider=True)
392             col.active = active
393             # not supported yet
394             #row = layout.row()
395             #row.prop(pchan, "use_ik_linear_control", text="Joint Size")
396             #row.prop(pchan, "ik_linear_weight", text="Weight", slider=True)
397
398
399 class BONE_PT_deform(BoneButtonsPanel, Panel):
400     bl_label = "Deform"
401     bl_options = {'DEFAULT_CLOSED'}
402
403     def draw_header(self, context):
404         bone = context.bone
405
406         if not bone:
407             bone = context.edit_bone
408
409         self.layout.prop(bone, "use_deform", text="")
410
411     def draw(self, context):
412         layout = self.layout
413
414         bone = context.bone
415
416         if not bone:
417             bone = context.edit_bone
418
419         layout.active = bone.use_deform
420
421         row = layout.row()
422
423         col = row.column(align=True)
424         col.label(text="Envelope:")
425         col.prop(bone, "envelope_distance", text="Distance")
426         col.prop(bone, "envelope_weight", text="Weight")
427         col.prop(bone, "use_envelope_multiply", text="Multiply")
428
429         col = row.column(align=True)
430         col.label(text="Envelope Radius:")
431         col.prop(bone, "head_radius", text="Head")
432         col.prop(bone, "tail_radius", text="Tail")
433
434
435 class BONE_PT_custom_props(BoneButtonsPanel, PropertyPanel, Panel):
436     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME', 'BLENDER_CLAY', 'BLENDER_EEVEE'}
437     _property_type = bpy.types.Bone, bpy.types.EditBone, bpy.types.PoseBone
438
439     @property
440     def _context_path(self):
441         obj = bpy.context.object
442         if obj and obj.mode == 'POSE':
443             return "active_pose_bone"
444         else:
445             return "active_bone"
446
447
448 classes = (
449     BONE_PT_context_bone,
450     BONE_PT_transform,
451     BONE_PT_transform_locks,
452     BONE_PT_curved,
453     BONE_PT_relations,
454     BONE_PT_display,
455     BONE_PT_inverse_kinematics,
456     BONE_PT_deform,
457     BONE_PT_custom_props,
458 )
459
460 if __name__ == "__main__":  # only for live edit.
461     from bpy.utils import register_class
462     for cls in classes:
463         register_class(cls)