a8954a1c33ed82f17e0acdc0d21d2d88041bb3ee
[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.row()
131         sub = col.row()
132         sub.active = not (bone.parent and bone.use_connect)
133         sub.column().prop(pchan, "lock_location", text="Location")
134         col.column().prop(pchan, "lock_rotation", text="Rotation")
135         col.column().prop(pchan, "lock_scale", text="Scale")
136
137         if pchan.rotation_mode in {'QUATERNION', 'AXIS_ANGLE'}:
138             row = layout.row()
139             row.prop(pchan, "lock_rotations_4d", text="Lock Rotation")
140
141             sub = row.row()
142             sub.active = pchan.lock_rotations_4d
143             sub.prop(pchan, "lock_rotation_w", text="W")
144
145
146 class BONE_PT_relations(BoneButtonsPanel, Panel):
147     bl_label = "Relations"
148
149     def draw(self, context):
150         layout = self.layout
151
152         ob = context.object
153         bone = context.bone
154         arm = context.armature
155         pchan = None
156
157         if ob and bone:
158             pchan = ob.pose.bones[bone.name]
159         elif bone is None:
160             bone = context.edit_bone
161
162         split = layout.split()
163
164         col = split.column()
165         col.label(text="Layers:")
166         col.prop(bone, "layers", text="")
167
168         col.separator()
169
170         if ob and pchan:
171             col.label(text="Bone Group:")
172             col.prop_search(pchan, "bone_group", ob.pose, "bone_groups", text="")
173             col.label(text="Object Children:")
174             col.prop(bone, "use_relative_parent")
175
176         col = split.column()
177         col.label(text="Parent:")
178         if context.bone:
179             col.prop(bone, "parent", text="")
180         else:
181             col.prop_search(bone, "parent", arm, "edit_bones", text="")
182
183         sub = col.column()
184         sub.active = (bone.parent is not None)
185         sub.prop(bone, "use_connect")
186         sub.prop(bone, "use_inherit_rotation")
187         sub.prop(bone, "use_inherit_scale")
188         sub = col.column()
189         sub.active = (not bone.parent or not bone.use_connect)
190         sub.prop(bone, "use_local_location")
191
192
193 class BONE_PT_display(BoneButtonsPanel, Panel):
194     bl_label = "Display"
195
196     @classmethod
197     def poll(cls, context):
198         return context.bone
199
200     def draw(self, context):
201         # note. this works ok in edit-mode but isn't
202         # all that useful so disabling for now.
203         layout = self.layout
204
205         ob = context.object
206         bone = context.bone
207         pchan = None
208
209         if ob and bone:
210             pchan = ob.pose.bones[bone.name]
211         elif bone is None:
212             bone = context.edit_bone
213
214         if bone:
215             split = layout.split()
216
217             col = split.column()
218             col.prop(bone, "hide", text="Hide")
219             sub = col.column()
220             sub.active = bool(pchan.custom_shape)
221             sub.prop(bone, "show_wire", text="Wireframe")
222
223             if pchan:
224                 col = split.column()
225
226                 col.label(text="Custom Shape:")
227                 col.prop(pchan, "custom_shape", text="")
228                 if pchan.custom_shape:
229                     col.prop_search(pchan, "custom_shape_transform", ob.pose, "bones", text="At")
230
231
232 class BONE_PT_inverse_kinematics(BoneButtonsPanel, Panel):
233     bl_label = "Inverse Kinematics"
234     bl_options = {'DEFAULT_CLOSED'}
235
236     @classmethod
237     def poll(cls, context):
238         ob = context.object
239         return ob and ob.mode == 'POSE' and context.bone
240
241     def draw(self, context):
242         layout = self.layout
243
244         ob = context.object
245         bone = context.bone
246         pchan = ob.pose.bones[bone.name]
247
248         row = layout.row()
249
250         active = pchan.is_in_ik_chain
251
252         split = layout.split(percentage=0.25)
253         split.prop(pchan, "lock_ik_x", icon='LOCKED' if pchan.lock_ik_x else 'UNLOCKED', text="X")
254         split.active = active
255         row = split.row()
256         row.prop(pchan, "ik_stiffness_x", text="Stiffness", slider=True)
257         row.active = pchan.lock_ik_x is False and active
258
259         split = layout.split(percentage=0.25)
260         sub = split.row()
261
262         sub.prop(pchan, "use_ik_limit_x", text="Limit")
263         sub.active = pchan.lock_ik_x is False and active
264         sub = split.row(align=True)
265         sub.prop(pchan, "ik_min_x", text="")
266         sub.prop(pchan, "ik_max_x", text="")
267         sub.active = pchan.lock_ik_x is False and pchan.use_ik_limit_x and active
268
269         split = layout.split(percentage=0.25)
270         split.prop(pchan, "lock_ik_y", icon='LOCKED' if pchan.lock_ik_y else 'UNLOCKED', text="Y")
271         split.active = active
272         row = split.row()
273         row.prop(pchan, "ik_stiffness_y", text="Stiffness", slider=True)
274         row.active = pchan.lock_ik_y is False and active
275
276         split = layout.split(percentage=0.25)
277         sub = split.row()
278
279         sub.prop(pchan, "use_ik_limit_y", text="Limit")
280         sub.active = pchan.lock_ik_y is False and active
281
282         sub = split.row(align=True)
283         sub.prop(pchan, "ik_min_y", text="")
284         sub.prop(pchan, "ik_max_y", text="")
285         sub.active = pchan.lock_ik_y is False and pchan.use_ik_limit_y and active
286
287         split = layout.split(percentage=0.25)
288         split.prop(pchan, "lock_ik_z", icon='LOCKED' if pchan.lock_ik_z else 'UNLOCKED', text="Z")
289         split.active = active
290         sub = split.row()
291         sub.prop(pchan, "ik_stiffness_z", text="Stiffness", slider=True)
292         sub.active = pchan.lock_ik_z is False and active
293
294         split = layout.split(percentage=0.25)
295         sub = split.row()
296
297         sub.prop(pchan, "use_ik_limit_z", text="Limit")
298         sub.active = pchan.lock_ik_z is False and active
299         sub = split.row(align=True)
300         sub.prop(pchan, "ik_min_z", text="")
301         sub.prop(pchan, "ik_max_z", text="")
302         sub.active = pchan.lock_ik_z is False and pchan.use_ik_limit_z and active
303
304         split = layout.split(percentage=0.25)
305         split.label(text="Stretch:")
306         sub = split.row()
307         sub.prop(pchan, "ik_stretch", text="", slider=True)
308         sub.active = active
309
310         if ob.pose.ik_solver == 'ITASC':
311             split = layout.split()
312             col = split.column()
313             col.prop(pchan, "use_ik_rotation_control", text="Control Rotation")
314             col.active = active
315             col = split.column()
316             col.prop(pchan, "ik_rotation_weight", text="Weight", slider=True)
317             col.active = active
318             # not supported yet
319             #row = layout.row()
320             #row.prop(pchan, "use_ik_linear_control", text="Joint Size")
321             #row.prop(pchan, "ik_linear_weight", text="Weight", slider=True)
322
323
324 class BONE_PT_deform(BoneButtonsPanel, Panel):
325     bl_label = "Deform"
326     bl_options = {'DEFAULT_CLOSED'}
327
328     def draw_header(self, context):
329         bone = context.bone
330
331         if not bone:
332             bone = context.edit_bone
333
334         self.layout.prop(bone, "use_deform", text="")
335
336     def draw(self, context):
337         layout = self.layout
338
339         bone = context.bone
340
341         if not bone:
342             bone = context.edit_bone
343
344         layout.active = bone.use_deform
345
346         split = layout.split()
347
348         col = split.column()
349         col.label(text="Envelope:")
350
351         sub = col.column(align=True)
352         sub.prop(bone, "envelope_distance", text="Distance")
353         sub.prop(bone, "envelope_weight", text="Weight")
354         col.prop(bone, "use_envelope_multiply", text="Multiply")
355
356         sub = col.column(align=True)
357         sub.label(text="Radius:")
358         sub.prop(bone, "head_radius", text="Head")
359         sub.prop(bone, "tail_radius", text="Tail")
360
361         col = split.column()
362         col.label(text="Curved Bones:")
363
364         sub = col.column(align=True)
365         sub.prop(bone, "bbone_segments", text="Segments")
366         sub.prop(bone, "bbone_in", text="Ease In")
367         sub.prop(bone, "bbone_out", text="Ease Out")
368
369
370 class BONE_PT_custom_props(BoneButtonsPanel, PropertyPanel, Panel):
371     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
372     _property_type = bpy.types.Bone, bpy.types.EditBone, bpy.types.PoseBone
373
374     @property
375     def _context_path(self):
376         obj = bpy.context.object
377         if obj and obj.mode == 'POSE':
378             return "active_pose_bone"
379         else:
380             return "active_bone"
381
382 if __name__ == "__main__":  # only for live edit.
383     bpy.utils.register_module(__name__)