2.5 - Assorted Bugfixes for Animation Editing
[blender.git] / release / 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", text="Rotation")
61                         else:
62                                 col.itemR(pchan, "euler_rotation", text="Rotation")
63
64                         row.column().itemR(pchan, "scale")
65
66                         if pchan.rotation_mode == 'QUATERNION':
67                                 col = layout.column(align=True)
68                                 col.itemL(text="Euler:")
69                                 col.row().itemR(pchan, "euler_rotation", text="")
70
71 class BONE_PT_bone(BoneButtonsPanel):
72         __label__ = "Bone"
73
74         def draw(self, context):
75                 layout = self.layout
76                 
77                 ob = context.object
78                 bone = context.bone
79                 arm = context.armature
80                 if not bone:
81                         bone = context.edit_bone
82                 else:
83                         pchan = ob.pose.pose_channels[context.bone.name]
84
85                 split = layout.split()
86
87                 col = split.column()
88                 col.itemL(text="Parent:")
89                 if context.bone:
90                         col.itemR(bone, "parent", text="")
91                 else:
92                         col.item_pointerR(bone, "parent", arm, "edit_bones", text="")
93                 
94                 row = col.row()
95                 row.active = bone.parent != None
96                 row.itemR(bone, "connected")
97                 
98                 col.itemL(text="Layers:")
99                 col.template_layers(bone, "layer")
100                 
101                 col = split.column()
102                 col.itemL(text="Inherit:")
103                 col.itemR(bone, "hinge", text="Rotation")
104                 col.itemR(bone, "inherit_scale", text="Scale")
105                 col.itemL(text="Display:")
106                 col.itemR(bone, "draw_wire", text="Wireframe")
107                 col.itemR(bone, "hidden", text="Hide")
108                 
109                 if ob and pchan:
110                         split = layout.split()
111                         
112                         col = split.column()
113                         col.itemL(text="Bone Group:")
114                         col.item_pointerR(pchan, "bone_group", ob.pose, "bone_groups", text="")
115                         
116                         col = split.column()
117                         col.itemL(text="Custom Shape:")
118                         col.itemR(pchan, "custom_shape", text="")
119
120 class BONE_PT_inverse_kinematics(BoneButtonsPanel):
121         __label__ = "Inverse Kinematics"
122         __default_closed__ = True
123         
124         def poll(self, context):
125                 ob = context.object
126                 bone = context.bone
127
128                 if ob and context.bone:
129                         pchan = ob.pose.pose_channels[context.bone.name]
130                         return pchan.has_ik
131                 
132                 return False
133
134         def draw(self, context):
135                 layout = self.layout
136                 
137                 ob = context.object
138                 bone = context.bone
139                 pchan = ob.pose.pose_channels[context.bone.name]
140
141                 split = layout.split(percentage=0.25)
142                 split.itemR(pchan, "ik_dof_x", text="X")
143                 row = split.row()
144                 row.itemR(pchan, "ik_stiffness_x", text="Stiffness")
145                 row.active = pchan.ik_dof_x
146
147                 split = layout.split(percentage=0.25)
148                 row = split.row()
149                 row.itemR(pchan, "ik_limit_x", text="Limit")
150                 row.active = pchan.ik_dof_x
151                 row = split.row(align=True)
152                 row.itemR(pchan, "ik_min_x", text="")
153                 row.itemR(pchan, "ik_max_x", text="")
154                 row.active = pchan.ik_dof_x and pchan.ik_limit_x
155
156                 split = layout.split(percentage=0.25)
157                 split.itemR(pchan, "ik_dof_y", text="Y")
158                 row = split.row()
159                 row.itemR(pchan, "ik_stiffness_y", text="Stiffness")
160                 row.active = pchan.ik_dof_y
161
162                 split = layout.split(percentage=0.25)
163                 row = split.row()
164                 row.itemR(pchan, "ik_limit_y", text="Limit")
165                 row.active = pchan.ik_dof_y
166                 row = split.row(align=True)
167                 row.itemR(pchan, "ik_min_y", text="")
168                 row.itemR(pchan, "ik_max_y", text="")
169                 row.active = pchan.ik_dof_y and pchan.ik_limit_y
170
171                 split = layout.split(percentage=0.25)
172                 split.itemR(pchan, "ik_dof_z", text="Z")
173                 row = split.row()
174                 row.itemR(pchan, "ik_stiffness_z", text="Stiffness")
175                 row.active = pchan.ik_dof_z
176
177                 split = layout.split(percentage=0.25)
178                 row = split.row()
179                 row.itemR(pchan, "ik_limit_z", text="Limit")
180                 row.active = pchan.ik_dof_z
181                 row = split.row(align=True)
182                 row.itemR(pchan, "ik_min_z", text="")
183                 row.itemR(pchan, "ik_max_z", text="")
184                 row.active = pchan.ik_dof_z and pchan.ik_limit_z
185
186                 split = layout.split()
187                 split.itemR(pchan, "ik_stretch", text="Stretch")
188                 split.itemL()
189
190 class BONE_PT_deform(BoneButtonsPanel):
191         __label__ = "Deform"
192         __default_closed__ = True
193
194         def draw_header(self, context):
195                 layout = self.layout
196                 
197                 bone = context.bone
198                 if not bone:
199                         bone = context.edit_bone
200                         
201                 layout.itemR(bone, "deform", text="")
202
203         def draw(self, context):
204                 layout = self.layout
205                 
206                 bone = context.bone
207                 if not bone:
208                         bone = context.edit_bone
209         
210                 layout.active = bone.deform
211                         
212                 split = layout.split()
213
214                 col = split.column()
215                 col.itemL(text="Envelope:")
216                 
217                 sub = col.column(align=True)
218                 sub.itemR(bone, "envelope_distance", text="Distance")
219                 sub.itemR(bone, "envelope_weight", text="Weight")
220                 col.itemR(bone, "multiply_vertexgroup_with_envelope", text="Multiply")
221
222                 sub = col.column(align=True)
223                 sub.itemL(text="Radius:")
224                 sub.itemR(bone, "head_radius", text="Head")
225                 sub.itemR(bone, "tail_radius", text="Tail")
226
227                 col = split.column()
228                 col.itemL(text="Curved Bones:")
229                 
230                 sub = col.column(align=True)
231                 sub.itemR(bone, "bbone_segments", text="Segments")
232                 sub.itemR(bone, "bbone_in", text="Ease In")
233                 sub.itemR(bone, "bbone_out", text="Ease Out")
234                 
235                 col.itemL(text="Offset:")
236                 col.itemR(bone, "cyclic_offset")
237
238 bpy.types.register(BONE_PT_context_bone)
239 bpy.types.register(BONE_PT_transform)
240 bpy.types.register(BONE_PT_bone)
241 bpy.types.register(BONE_PT_deform)
242 bpy.types.register(BONE_PT_inverse_kinematics)