Armature drawing: custom shape scale options
[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(pchan, "use_custom_shape_bone_size", text="Bone Size")
233                     col.prop(pchan, "custom_shape_scale", text="Scale")
234                     col.prop_search(pchan, "custom_shape_transform", ob.pose, "bones", text="At")
235
236
237 class BONE_PT_inverse_kinematics(BoneButtonsPanel, Panel):
238     bl_label = "Inverse Kinematics"
239     bl_options = {'DEFAULT_CLOSED'}
240
241     @classmethod
242     def poll(cls, context):
243         ob = context.object
244         return ob and ob.mode == 'POSE' and context.bone
245
246     def draw(self, context):
247         layout = self.layout
248
249         ob = context.object
250         bone = context.bone
251         pchan = ob.pose.bones[bone.name]
252
253         row = layout.row()
254
255         active = pchan.is_in_ik_chain
256
257         split = layout.split(percentage=0.25)
258         split.prop(pchan, "lock_ik_x", text="X")
259         split.active = active
260         row = split.row()
261         row.prop(pchan, "ik_stiffness_x", text="Stiffness", slider=True)
262         row.active = pchan.lock_ik_x is False and active
263
264         split = layout.split(percentage=0.25)
265         sub = split.row()
266
267         sub.prop(pchan, "use_ik_limit_x", text="Limit")
268         sub.active = pchan.lock_ik_x is False and active
269         sub = split.row(align=True)
270         sub.prop(pchan, "ik_min_x", text="")
271         sub.prop(pchan, "ik_max_x", text="")
272         sub.active = pchan.lock_ik_x is False and pchan.use_ik_limit_x and active
273
274         split = layout.split(percentage=0.25)
275         split.prop(pchan, "lock_ik_y", text="Y")
276         split.active = active
277         row = split.row()
278         row.prop(pchan, "ik_stiffness_y", text="Stiffness", slider=True)
279         row.active = pchan.lock_ik_y is False and active
280
281         split = layout.split(percentage=0.25)
282         sub = split.row()
283
284         sub.prop(pchan, "use_ik_limit_y", text="Limit")
285         sub.active = pchan.lock_ik_y is False and active
286
287         sub = split.row(align=True)
288         sub.prop(pchan, "ik_min_y", text="")
289         sub.prop(pchan, "ik_max_y", text="")
290         sub.active = pchan.lock_ik_y is False and pchan.use_ik_limit_y and active
291
292         split = layout.split(percentage=0.25)
293         split.prop(pchan, "lock_ik_z", text="Z")
294         split.active = active
295         sub = split.row()
296         sub.prop(pchan, "ik_stiffness_z", text="Stiffness", slider=True)
297         sub.active = pchan.lock_ik_z is False and active
298
299         split = layout.split(percentage=0.25)
300         sub = split.row()
301
302         sub.prop(pchan, "use_ik_limit_z", text="Limit")
303         sub.active = pchan.lock_ik_z is False and active
304         sub = split.row(align=True)
305         sub.prop(pchan, "ik_min_z", text="")
306         sub.prop(pchan, "ik_max_z", text="")
307         sub.active = pchan.lock_ik_z is False and pchan.use_ik_limit_z and active
308
309         split = layout.split(percentage=0.25)
310         split.label(text="Stretch:")
311         sub = split.row()
312         sub.prop(pchan, "ik_stretch", text="", slider=True)
313         sub.active = active
314
315         if ob.pose.ik_solver == 'ITASC':
316             split = layout.split()
317             col = split.column()
318             col.prop(pchan, "use_ik_rotation_control", text="Control Rotation")
319             col.active = active
320             col = split.column()
321             col.prop(pchan, "ik_rotation_weight", text="Weight", slider=True)
322             col.active = active
323             # not supported yet
324             #row = layout.row()
325             #row.prop(pchan, "use_ik_linear_control", text="Joint Size")
326             #row.prop(pchan, "ik_linear_weight", text="Weight", slider=True)
327
328
329 class BONE_PT_deform(BoneButtonsPanel, Panel):
330     bl_label = "Deform"
331     bl_options = {'DEFAULT_CLOSED'}
332
333     def draw_header(self, context):
334         bone = context.bone
335
336         if not bone:
337             bone = context.edit_bone
338
339         self.layout.prop(bone, "use_deform", text="")
340
341     def draw(self, context):
342         layout = self.layout
343
344         bone = context.bone
345
346         if not bone:
347             bone = context.edit_bone
348
349         layout.active = bone.use_deform
350
351         split = layout.split()
352
353         col = split.column()
354         col.label(text="Envelope:")
355
356         sub = col.column(align=True)
357         sub.prop(bone, "envelope_distance", text="Distance")
358         sub.prop(bone, "envelope_weight", text="Weight")
359         col.prop(bone, "use_envelope_multiply", text="Multiply")
360
361         sub = col.column(align=True)
362         sub.label(text="Radius:")
363         sub.prop(bone, "head_radius", text="Head")
364         sub.prop(bone, "tail_radius", text="Tail")
365
366         col = split.column()
367         col.label(text="Curved Bones:")
368
369         sub = col.column(align=True)
370         sub.prop(bone, "bbone_segments", text="Segments")
371         sub.prop(bone, "bbone_in", text="Ease In")
372         sub.prop(bone, "bbone_out", text="Ease Out")
373
374
375 class BONE_PT_custom_props(BoneButtonsPanel, PropertyPanel, Panel):
376     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
377     _property_type = bpy.types.Bone, bpy.types.EditBone, bpy.types.PoseBone
378
379     @property
380     def _context_path(self):
381         obj = bpy.context.object
382         if obj and obj.mode == 'POSE':
383             return "active_pose_bone"
384         else:
385             return "active_bone"
386
387 if __name__ == "__main__":  # only for live edit.
388     bpy.utils.register_module(__name__)