b31cac15425b2d475f38bad785604246159505ab
[blender.git] / release / ui / buttons_data_bone.py
1
2 import bpy
3  
4 class BoneButtonsPanel(bpy.types.Panel):
5         __space_type__ = "BUTTONS_WINDOW"
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         __idname__ = "BONE_PT_context_bone"
14         __no_header__ = True
15
16         def draw(self, context):
17                 layout = self.layout
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         __idname__ = "BONE_PT_transform"
28         __label__ = "Transform"
29
30         def draw(self, context):
31                 layout = self.layout
32                 ob = context.object
33                 bone = context.bone
34
35                 if not bone:
36                         bone = context.edit_bone
37
38                         row = layout.row()
39                         row.column().itemR(bone, "head")
40                         row.column().itemR(bone, "tail")
41
42                         col = row.column()
43                         sub = col.column(align=True)
44                         sub.itemL(text="Roll:")
45                         sub.itemR(bone, "roll", text="")
46                         sub.itemL()
47                         sub.itemR(bone, "locked")
48                         sub.itemS()
49                 else:
50                         pchan = ob.pose.pose_channels[context.bone.name]
51
52                         layout.itemR(pchan, "rotation_mode")
53
54                         row = layout.row()
55                         col = row.column()
56                         col.itemR(pchan, "location")
57                         col.active = not (bone.parent and bone.connected)
58
59                         col = row.column()
60                         if pchan.rotation_mode == 'QUATERNION':
61                                 col.itemR(pchan, "rotation", text="Rotation")
62                         else:
63                                 col.itemR(pchan, "euler_rotation", text="Rotation")
64
65                         row.column().itemR(pchan, "scale")
66
67                         if pchan.rotation_mode == 'QUATERNION':
68                                 col = layout.column(align=True)
69                                 col.itemL(text="Euler:")
70                                 col.row().itemR(pchan, "euler_rotation", text="")
71
72 class BONE_PT_bone(BoneButtonsPanel):
73         __idname__ = "BONE_PT_bone"
74         __label__ = "Bone"
75
76
77         def draw(self, context):
78                 layout = self.layout
79                 bone = context.bone
80                 arm = context.armature
81                 if not bone:
82                         bone = context.edit_bone
83
84                 split = layout.split()
85
86                 sub = split.column()
87                 sub.itemL(text="Parent:")
88                 if context.bone:
89                         sub.itemR(bone, "parent", text="")
90                 else:
91                         sub.item_pointerR(bone, "parent", arm, "edit_bones", text="")
92                 row = sub.row()
93                 row.itemR(bone, "connected")
94                 row.active = bone.parent != None
95
96                 sub.itemL(text="Layers:")
97                 sub.template_layers(bone, "layer")
98
99                 sub = split.column()
100
101                 sub.itemL(text="Inherit:")
102                 sub.itemR(bone, "hinge", text="Rotation")
103                 sub.itemR(bone, "inherit_scale", text="Scale")
104                 
105                 sub.itemL(text="Display:")
106                 sub.itemR(bone, "draw_wire", text="Wireframe")
107                 sub.itemR(bone, "hidden", text="Hide")
108
109 class BONE_PT_inverse_kinematics(BoneButtonsPanel):
110         __idname__ = "BONE_PT_inverse_kinematics"
111         __label__ = "Inverse Kinematics"
112         __default_closed__ = True
113         
114         def poll(self, context):
115                 ob = context.object
116                 bone = context.bone
117
118                 if ob and context.bone:
119                         pchan = ob.pose.pose_channels[context.bone.name]
120                         return pchan.has_ik
121                 
122                 return False
123
124         def draw(self, context):
125                 layout = self.layout
126                 ob = context.object
127                 bone = context.bone
128                 pchan = ob.pose.pose_channels[context.bone.name]
129
130                 split = layout.split(percentage=0.25)
131                 split.itemR(pchan, "ik_dof_x", text="X")
132                 row = split.row()
133                 row.itemR(pchan, "ik_stiffness_x", text="Stiffness")
134                 row.active = pchan.ik_dof_x
135
136                 split = layout.split(percentage=0.25)
137                 row = split.row()
138                 row.itemR(pchan, "ik_limit_x", text="Limit")
139                 row.active = pchan.ik_dof_x
140                 row = split.row(align=True)
141                 row.itemR(pchan, "ik_min_x", text="")
142                 row.itemR(pchan, "ik_max_x", text="")
143                 row.active = pchan.ik_dof_x and pchan.ik_limit_x
144
145                 split = layout.split(percentage=0.25)
146                 split.itemR(pchan, "ik_dof_y", text="Y")
147                 row = split.row()
148                 row.itemR(pchan, "ik_stiffness_y", text="Stiffness")
149                 row.active = pchan.ik_dof_y
150
151                 split = layout.split(percentage=0.25)
152                 row = split.row()
153                 row.itemR(pchan, "ik_limit_y", text="Limit")
154                 row.active = pchan.ik_dof_y
155                 row = split.row(align=True)
156                 row.itemR(pchan, "ik_min_y", text="")
157                 row.itemR(pchan, "ik_max_y", text="")
158                 row.active = pchan.ik_dof_y and pchan.ik_limit_y
159
160                 split = layout.split(percentage=0.25)
161                 split.itemR(pchan, "ik_dof_z", text="Z")
162                 row = split.row()
163                 row.itemR(pchan, "ik_stiffness_z", text="Stiffness")
164                 row.active = pchan.ik_dof_z
165
166                 split = layout.split(percentage=0.25)
167                 row = split.row()
168                 row.itemR(pchan, "ik_limit_z", text="Limit")
169                 row.active = pchan.ik_dof_z
170                 row = split.row(align=True)
171                 row.itemR(pchan, "ik_min_z", text="")
172                 row.itemR(pchan, "ik_max_z", text="")
173                 row.active = pchan.ik_dof_z and pchan.ik_limit_z
174
175                 split = layout.split()
176                 split.itemR(pchan, "ik_stretch", text="Stretch")
177                 split.itemL()
178
179 class BONE_PT_deform(BoneButtonsPanel):
180         __idname__ = "BONE_PT_deform"
181         __label__ = "Deform"
182         __default_closed__ = True
183
184         def draw_header(self, context):
185                 layout = self.layout
186                 bone = context.bone
187                 if not bone:
188                         bone = context.edit_bone
189                         
190                 layout.itemR(bone, "deform", text="")
191
192         def draw(self, context):
193                 layout = self.layout
194                 bone = context.bone
195                 if not bone:
196                         bone = context.edit_bone
197         
198                 layout.active = bone.deform
199                         
200                 split = layout.split()
201
202                 col = split.column()
203                 col.itemL(text="Envelope:")
204                 sub = col.column(align=True)
205                 sub.itemR(bone, "envelope_distance", text="Distance")
206                 sub.itemR(bone, "envelope_weight", text="Weight")
207                 col.itemR(bone, "multiply_vertexgroup_with_envelope", text="Multiply")
208
209                 sub = col.column(align=True)
210                 sub.itemL(text="Radius:")
211                 sub.itemR(bone, "head_radius", text="Head")
212                 sub.itemR(bone, "tail_radius", text="Tail")
213
214                 col = split.column()
215                 col.itemL(text="Curved Bones:")
216                 sub = col.column(align=True)
217                 sub.itemR(bone, "bbone_segments", text="Segments")
218                 sub.itemR(bone, "bbone_in", text="Ease In")
219                 sub.itemR(bone, "bbone_out", text="Ease Out")
220                 
221                 col.itemL(text="Offset:")
222                 col.itemR(bone, "cyclic_offset")
223
224 bpy.types.register(BONE_PT_context_bone)
225 bpy.types.register(BONE_PT_transform)
226 bpy.types.register(BONE_PT_bone)
227 bpy.types.register(BONE_PT_deform)
228 bpy.types.register(BONE_PT_inverse_kinematics)
229