e089cff264fe86dc459223c5ef421712fc7e9deb
[blender-staging.git] / release / scripts / ui / buttons_object_constraint.py
1
2 import bpy
3
4 class ConstraintButtonsPanel(bpy.types.Panel):
5         __space_type__ = 'PROPERTIES'
6         __region_type__ = 'WINDOW'
7         __context__ = "constraint"
8
9         def draw_constraint(self, context, con):
10                 layout = self.layout
11                 
12                 box = layout.template_constraint(con)
13
14                 if box:
15                         # match enum type to our functions, avoids a lookup table.
16                         getattr(self, con.type)(context, box, con)
17         
18                         # show/key buttons here are most likely obsolete now, with
19                         # keyframing functionality being part of every button
20                         if con.type not in ('RIGID_BODY_JOINT', 'NULL'):
21                                 box.itemR(con, "influence")
22         
23         def space_template(self, layout, con, target=True, owner=True):
24                 if target or owner:
25                         row = layout.row()
26
27                         row.itemL(text="Convert:")
28
29                         if target:
30                                 row.itemR(con, "target_space", text="")
31
32                         if target and owner:
33                                 row.itemL(icon='ICON_ARROW_LEFTRIGHT')
34
35                         if owner:
36                                 row.itemR(con, "owner_space", text="")
37                         
38         def target_template(self, layout, con, subtargets=True):
39                 layout.itemR(con, "target") # XXX limiting settings for only 'curves' or some type of object
40                 
41                 if con.target and subtargets:
42                         if con.target.type == 'ARMATURE':
43                                 layout.item_pointerR(con, "subtarget", con.target.data, "bones", text="Bone")
44                                 
45                                 if con.type == 'COPY_LOCATION':
46                                         row = layout.row()
47                                         row.itemL(text="Head/Tail:")
48                                         row.itemR(con, "head_tail", text="")
49                         elif con.target.type in ('MESH', 'LATTICE'):
50                                 layout.item_pointerR(con, "subtarget", con.target, "vertex_groups", text="Vertex Group")
51
52         def ik_template(self, layout, con):
53                 layout.itemR(con, "pole_target")
54         
55                 if con.pole_target and con.pole_target.type == 'ARMATURE':
56                         layout.item_pointerR(con, "pole_subtarget", con.pole_target.data, "bones", text="Bone")
57                 
58                 if con.pole_target:
59                         row = layout.row()
60                         row.itemL()
61                         row.itemR(con, "pole_angle")
62                 
63                 split = layout.split()
64                 col = split.column()
65                 col.itemR(con, "tail")
66                 col.itemR(con, "stretch")
67
68                 col = split.column()
69                 col.itemR(con, "iterations")
70                 col.itemR(con, "chain_length")
71
72         def CHILD_OF(self, context, layout, con):
73                 self.target_template(layout, con)
74
75                 split = layout.split()
76                 
77                 col = split.column()
78                 col.itemL(text="Location:")
79                 col.itemR(con, "locationx", text="X")
80                 col.itemR(con, "locationy", text="Y")
81                 col.itemR(con, "locationz", text="Z")
82                 
83                 col = split.column()
84                 col.itemL(text="Rotation:")
85                 col.itemR(con, "rotationx", text="X")
86                 col.itemR(con, "rotationy", text="Y")
87                 col.itemR(con, "rotationz", text="Z")
88                 
89                 col = split.column()
90                 col.itemL(text="Scale:")
91                 col.itemR(con, "sizex", text="X")
92                 col.itemR(con, "sizey", text="Y")
93                 col.itemR(con, "sizez", text="Z")
94                 
95                 row = layout.row()
96                 row.itemO("constraint.childof_set_inverse")
97                 row.itemO("constraint.childof_clear_inverse")
98                 
99         def TRACK_TO(self, context, layout, con):
100                 self.target_template(layout, con)
101                 
102                 row = layout.row()
103                 row.itemL(text="To:")
104                 row.itemR(con, "track", expand=True)
105                 
106                 row = layout.row()
107                 #row.itemR(con, "up", text="Up", expand=True) # XXX: up and expand don't play nice together
108                 row.itemR(con, "up", text="Up")
109                 row.itemR(con, "target_z")
110                 
111                 self.space_template(layout, con)
112                 
113         def IK(self, context, layout, con):
114                 if context.object.pose.ik_solver == "ITASC":
115                         layout.itemR(con, "ik_type")
116                         getattr(self, "IK_"+con.ik_type)(context, layout, con)
117                 else:
118                         self.IK_COPY_POSE(context, layout, con)
119
120         def IK_COPY_POSE(self, context, layout, con):
121                 self.target_template(layout, con)
122                 self.ik_template(layout, con)
123
124                 split = layout.split()
125                 col = split.column()
126                 col.itemL()
127                 col.itemR(con, "targetless")
128                 col.itemR(con, "rotation")
129
130                 col = split.column()
131                 col.itemL(text="Weight:")
132                 col.itemR(con, "weight", text="Position", slider=True)
133                 sub = col.column()
134                 sub.active = con.rotation
135                 sub.itemR(con, "orient_weight", text="Rotation", slider=True)
136                 
137         def IK_DISTANCE(self, context, layout, con):
138                 self.target_template(layout, con)
139                 self.ik_template(layout, con)
140
141                 layout.itemR(con, "limit_mode")
142                 row = layout.row()
143                 row.itemR(con, "weight", text="Weight", slider=True)
144                 row.itemR(con, "distance", text="Distance", slider=True)
145
146         def FOLLOW_PATH(self, context, layout, con):
147                 self.target_template(layout, con)
148                 
149                 split = layout.split()
150                 
151                 col = split.column()
152                 col.itemR(con, "use_curve_follow")
153                 col.itemR(con, "use_curve_radius")
154                 
155                 col = split.column()
156                 col.itemR(con, "use_fixed_position")
157                 if con.use_fixed_position:
158                         col.itemR(con, "offset_factor", text="Offset")
159                 else:
160                         col.itemR(con, "offset")
161                 
162                 row = layout.row()
163                 row.itemL(text="Forward:")
164                 row.itemR(con, "forward", expand=True)
165                 
166                 row = layout.row()
167                 row.itemR(con, "up", text="Up")
168                 row.itemL()
169                 
170         def LIMIT_ROTATION(self, context, layout, con):
171                 
172                 split = layout.split()
173                 
174                 col = split.column()
175                 col.itemR(con, "use_limit_x")
176                 sub = col.column()
177                 sub.active = con.use_limit_x
178                 sub.itemR(con, "minimum_x", text="Min")
179                 sub.itemR(con, "maximum_x", text="Max")
180                 
181                 col = split.column()
182                 col.itemR(con, "use_limit_y")
183                 sub = col.column()
184                 sub.active = con.use_limit_y
185                 sub.itemR(con, "minimum_y", text="Min")
186                 sub.itemR(con, "maximum_y", text="Max")
187                 
188                 col = split.column()
189                 col.itemR(con, "use_limit_z")
190                 sub = col.column()
191                 sub.active = con.use_limit_z
192                 sub.itemR(con, "minimum_z", text="Min")
193                 sub.itemR(con, "maximum_z", text="Max")
194                 
195                 row = layout.row()
196                 row.itemR(con, "limit_transform")
197                 row.itemL()
198                 
199                 row = layout.row()
200                 row.itemL(text="Convert:")
201                 row.itemR(con, "owner_space", text="")
202                 
203         def LIMIT_LOCATION(self, context, layout, con):
204                 split = layout.split()
205                 
206                 col = split.column()
207                 col.itemR(con, "use_minimum_x")
208                 sub = col.column()
209                 sub.active = con.use_minimum_x
210                 sub.itemR(con, "minimum_x", text="")
211                 col.itemR(con, "use_maximum_x")
212                 sub = col.column()
213                 sub.active = con.use_maximum_x
214                 sub.itemR(con, "maximum_x", text="")
215                 
216                 col = split.column()
217                 col.itemR(con, "use_minimum_y")
218                 sub = col.column()
219                 sub.active = con.use_minimum_y
220                 sub.itemR(con, "minimum_y", text="")
221                 col.itemR(con, "use_maximum_y")
222                 sub = col.column()
223                 sub.active = con.use_maximum_y
224                 sub.itemR(con, "maximum_y", text="")
225                 
226                 col = split.column()
227                 col.itemR(con, "use_minimum_z")
228                 sub = col.column()
229                 sub.active = con.use_minimum_z
230                 sub.itemR(con, "minimum_z", text="")
231                 col.itemR(con, "use_maximum_z")
232                 sub = col.column()
233                 sub.active = con.use_maximum_z
234                 sub.itemR(con, "maximum_z", text="")
235         
236                 row = layout.row()
237                 row.itemR(con, "limit_transform")
238                 row.itemL()
239                 
240                 row = layout.row()
241                 row.itemL(text="Convert:")
242                 row.itemR(con, "owner_space", text="")
243                 
244         def LIMIT_SCALE(self, context, layout, con):
245                 split = layout.split()
246
247                 col = split.column()
248                 col.itemR(con, "use_minimum_x")
249                 sub = col.column()
250                 sub.active = con.use_minimum_x
251                 sub.itemR(con, "minimum_x", text="")
252                 col.itemR(con, "use_maximum_x")
253                 sub = col.column()
254                 sub.active = con.use_maximum_x
255                 sub.itemR(con, "maximum_x", text="")
256                 
257                 col = split.column()
258                 col.itemR(con, "use_minimum_y")
259                 sub = col.column()
260                 sub.active = con.use_minimum_y
261                 sub.itemR(con, "minimum_y", text="")
262                 col.itemR(con, "use_maximum_y")
263                 sub = col.column()
264                 sub.active = con.use_maximum_y
265                 sub.itemR(con, "maximum_y", text="")
266                 
267                 col = split.column()
268                 col.itemR(con, "use_minimum_z")
269                 sub = col.column()
270                 sub.active = con.use_minimum_z
271                 sub.itemR(con, "minimum_z", text="")
272                 col.itemR(con, "use_maximum_z")
273                 sub = col.column()
274                 sub.active = con.use_maximum_z
275                 sub.itemR(con, "maximum_z", text="")
276                 
277                 row = layout.row()
278                 row.itemR(con, "limit_transform")
279                 row.itemL()
280                 
281                 row = layout.row()
282                 row.itemL(text="Convert:")
283                 row.itemR(con, "owner_space", text="")
284         
285         def COPY_ROTATION(self, context, layout, con):
286                 self.target_template(layout, con)
287                 
288                 split = layout.split()
289                 
290                 col = split.column()
291                 col.itemR(con, "rotate_like_x", text="X")
292                 sub = col.column()
293                 sub.active = con.rotate_like_x
294                 sub.itemR(con, "invert_x", text="Invert")
295                 
296                 col = split.column()
297                 col.itemR(con, "rotate_like_y", text="Y")
298                 sub = col.column()
299                 sub.active = con.rotate_like_y
300                 sub.itemR(con, "invert_y", text="Invert")
301                 
302                 col = split.column()
303                 col.itemR(con, "rotate_like_z", text="Z")
304                 sub = col.column()
305                 sub.active = con.rotate_like_z
306                 sub.itemR(con, "invert_z", text="Invert")
307
308                 layout.itemR(con, "offset")
309                 
310                 self.space_template(layout, con)
311                 
312         def COPY_LOCATION(self, context, layout, con):
313                 self.target_template(layout, con)
314                 
315                 split = layout.split()
316                 
317                 col = split.column()
318                 col.itemR(con, "locate_like_x", text="X")
319                 sub = col.column()
320                 sub.active = con.locate_like_x
321                 sub.itemR(con, "invert_x", text="Invert")
322                 
323                 col = split.column()
324                 col.itemR(con, "locate_like_y", text="Y")
325                 sub = col.column()
326                 sub.active = con.locate_like_y
327                 sub.itemR(con, "invert_y", text="Invert")
328                 
329                 col = split.column()
330                 col.itemR(con, "locate_like_z", text="Z")
331                 sub = col.column()
332                 sub.active = con.locate_like_z
333                 sub.itemR(con, "invert_z", text="Invert")
334
335                 layout.itemR(con, "offset")
336                         
337                 self.space_template(layout, con)
338                 
339         def COPY_SCALE(self, context, layout, con):
340                 self.target_template(layout, con)
341                 
342                 row = layout.row(align=True)
343                 row.itemR(con, "size_like_x", text="X")
344                 row.itemR(con, "size_like_y", text="Y")
345                 row.itemR(con, "size_like_z", text="Z")
346
347                 layout.itemR(con, "offset")
348                 
349                 self.space_template(layout, con)
350                 
351         #def SCRIPT(self, context, layout, con):
352         
353         def ACTION(self, context, layout, con):
354                 self.target_template(layout, con)
355                 
356                 layout.itemR(con, "action")
357                 layout.itemR(con, "transform_channel")
358
359                 split = layout.split()
360         
361                 col = split.column(align=True)
362                 col.itemR(con, "start_frame", text="Start")
363                 col.itemR(con, "end_frame", text="End")
364                 
365                 col = split.column(align=True)
366                 col.itemR(con, "minimum", text="Min")
367                 col.itemR(con, "maximum", text="Max")
368                 
369                 row = layout.row()
370                 row.itemL(text="Convert:")
371                 row.itemR(con, "owner_space", text="")
372         
373         def LOCKED_TRACK(self, context, layout, con):
374                 self.target_template(layout, con)
375                 
376                 row = layout.row()
377                 row.itemL(text="To:")
378                 row.itemR(con, "track", expand=True)
379                 
380                 row = layout.row()
381                 row.itemL(text="Lock:")
382                 row.itemR(con, "locked", expand=True)
383                 
384         def LIMIT_DISTANCE(self, context, layout, con):
385                 self.target_template(layout, con)
386                 
387                 col = layout.column(align=True);
388                 col.itemR(con, "distance")
389                 col.itemO("constraint.limitdistance_reset")
390                 
391                 row = layout.row()
392                 row.itemL(text="Clamp Region:")
393                 row.itemR(con, "limit_mode", text="")
394                 
395         def STRETCH_TO(self, context, layout, con):
396                 self.target_template(layout, con)
397                 
398                 row = layout.row()
399                 row.itemR(con, "original_length", text="Rest Length")
400                 row.itemO("constraint.stretchto_reset", text="Reset")
401                 
402                 col = layout.column()
403                 col.itemR(con, "bulge", text="Volume Variation")
404                 
405                 row = layout.row()
406                 row.itemL(text="Volume:")
407                 row.itemR(con, "volume", expand=True)
408                 row.itemL(text="Plane:")
409                 row.itemR(con, "keep_axis", expand=True)
410                 
411         def FLOOR(self, context, layout, con):
412                 self.target_template(layout, con)
413                 
414                 row = layout.row()
415                 row.itemR(con, "sticky")
416                 row.itemR(con, "use_rotation")
417                 
418                 layout.itemR(con, "offset")
419                 
420                 row = layout.row()
421                 row.itemL(text="Min/Max:")
422                 row.itemR(con, "floor_location", expand=True)
423                 
424         def RIGID_BODY_JOINT(self, context, layout, con):
425                 self.target_template(layout, con)
426                 
427                 layout.itemR(con, "pivot_type")
428                 layout.itemR(con, "child")
429                 
430                 row = layout.row()
431                 row.itemR(con, "disable_linked_collision", text="No Collision")
432                 row.itemR(con, "draw_pivot", text="Display Pivot")
433                 
434                 split = layout.split()
435                 
436                 col = split.column(align=True)
437                 col.itemL(text="Pivot:")
438                 col.itemR(con, "pivot_x", text="X")
439                 col.itemR(con, "pivot_y", text="Y")
440                 col.itemR(con, "pivot_z", text="Z")
441                 
442                 col = split.column(align=True)
443                 col.itemL(text="Axis:")
444                 col.itemR(con, "axis_x", text="X")
445                 col.itemR(con, "axis_y", text="Y")
446                 col.itemR(con, "axis_z", text="Z")
447                 
448                 #Missing: Limit arrays (not wrapped in RNA yet) 
449         
450         def CLAMP_TO(self, context, layout, con):
451                 self.target_template(layout, con)
452                 
453                 row = layout.row()
454                 row.itemL(text="Main Axis:")
455                 row.itemR(con, "main_axis", expand=True)
456                 
457                 row = layout.row()
458                 row.itemR(con, "cyclic")
459                 
460         def TRANSFORM(self, context, layout, con):
461                 self.target_template(layout, con)
462                 
463                 layout.itemR(con, "extrapolate_motion", text="Extrapolate")
464                 
465                 split = layout.split()
466                 
467                 col = split.column()
468                 col.itemL(text="Source:")
469                 col.row().itemR(con, "map_from", expand=True)
470                 
471                 sub = col.row(align=True)
472                 sub.itemL(text="X:")
473                 sub.itemR(con, "from_min_x", text="")
474                 sub.itemR(con, "from_max_x", text="")
475                 
476                 sub = col.row(align=True)
477                 sub.itemL(text="Y:")
478                 sub.itemR(con, "from_min_y", text="")
479                 sub.itemR(con, "from_max_y", text="")
480                 
481                 sub = col.row(align=True)
482                 sub.itemL(text="Z:")
483                 sub.itemR(con, "from_min_z", text="")
484                 sub.itemR(con, "from_max_z", text="")
485                 
486                 split = layout.split()
487                 
488                 col = split.column()
489                 col.itemL(text="Destination:")
490                 col.row().itemR(con, "map_to", expand=True)
491
492                 sub = col.row(align=True)
493                 sub.itemR(con, "map_to_x_from", text="")
494                 sub.itemR(con, "to_min_x", text="")
495                 sub.itemR(con, "to_max_x", text="")
496                 
497                 sub = col.row(align=True)
498                 sub.itemR(con, "map_to_y_from", text="")
499                 sub.itemR(con, "to_min_y", text="")
500                 sub.itemR(con, "to_max_y", text="")
501                 
502                 sub = col.row(align=True)
503                 sub.itemR(con, "map_to_z_from", text="")
504                 sub.itemR(con, "to_min_z", text="")
505                 sub.itemR(con, "to_max_z", text="")
506                 
507                 self.space_template(layout, con)
508                 
509         def SHRINKWRAP (self, context, layout, con):
510                 self.target_template(layout, con)
511                 
512                 layout.itemR(con, "distance")
513                 layout.itemR(con, "shrinkwrap_type")
514                 
515                 if con.shrinkwrap_type == 'PROJECT':
516                         row = layout.row(align=True)
517                         row.itemR(con, "axis_x")
518                         row.itemR(con, "axis_y")
519                         row.itemR(con, "axis_z")
520                 
521 class OBJECT_PT_constraints(ConstraintButtonsPanel):
522         __label__ = "Constraints"
523         __context__ = "constraint"
524
525         def poll(self, context):
526                 return (context.object)
527                 
528         def draw(self, context):
529                 layout = self.layout
530                 ob = context.object
531
532                 row = layout.row()
533                 row.item_menu_enumO("object.constraint_add", "type")
534                 row.itemL();
535
536                 for con in ob.constraints:
537                         self.draw_constraint(context, con)
538
539 class BONE_PT_constraints(ConstraintButtonsPanel):
540         __label__ = "Constraints"
541         __context__ = "bone_constraint"
542
543         def poll(self, context):
544                 ob = context.object
545                 return (ob and ob.type == 'ARMATURE' and context.bone)
546                 
547         def draw(self, context):
548                 layout = self.layout
549                 
550                 ob = context.object
551                 pchan = ob.pose.pose_channels[context.bone.name]
552
553                 row = layout.row()
554                 row.item_menu_enumO("pose.constraint_add", "type")
555                 row.itemL();
556
557                 for con in pchan.constraints:
558                         self.draw_constraint(context, con)
559
560 bpy.types.register(OBJECT_PT_constraints)
561 bpy.types.register(BONE_PT_constraints)