Welcome to mirror list, hosted at ThFree Co, Russian Federation.

buttons_object_constraint.py « ui « release - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ff3231a9d611aad6565be0c54168378f8624a646 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535

import bpy

class ConstraintButtonsPanel(bpy.types.Panel):
	__space_type__ = 'PROPERTIES'
	__region_type__ = 'WINDOW'
	__context__ = "constraint"

	def draw_constraint(self, con):
		layout = self.layout
		
		box = layout.template_constraint(con)

		if box:
			# match enum type to our functions, avoids a lookup table.
			getattr(self, con.type)(box, con)
	
			# show/key buttons here are most likely obsolete now, with
			# keyframing functionality being part of every button
			if con.type not in ('RIGID_BODY_JOINT', 'NULL'):
				box.itemR(con, "influence")
	
	def space_template(self, layout, con, target=True, owner=True):
		if target or owner:
			row = layout.row()

			row.itemL(text="Convert:")

			if target:
				row.itemR(con, "target_space", text="")

			if target and owner:
				row.itemL(icon='ICON_ARROW_LEFTRIGHT')

			if owner:
				row.itemR(con, "owner_space", text="")
			
	def target_template(self, layout, con, subtargets=True):
		layout.itemR(con, "target") # XXX limiting settings for only 'curves' or some type of object
		
		if con.target and subtargets:
			if con.target.type == 'ARMATURE':
				layout.item_pointerR(con, "subtarget", con.target.data, "bones", text="Bone")
				
				if con.type == 'COPY_LOCATION':
					row = layout.row()
					row.itemL(text="Head/Tail:")
					row.itemR(con, "head_tail", text="")
			elif con.target.type in ('MESH', 'LATTICE'):
				layout.item_pointerR(con, "subtarget", con.target, "vertex_groups", text="Vertex Group")
	
	def CHILD_OF(self, layout, con):
		self.target_template(layout, con)

		split = layout.split()
		
		col = split.column()
		col.itemL(text="Location:")
		col.itemR(con, "locationx", text="X")
		col.itemR(con, "locationy", text="Y")
		col.itemR(con, "locationz", text="Z")
		
		col = split.column()
		col.itemL(text="Rotation:")
		col.itemR(con, "rotationx", text="X")
		col.itemR(con, "rotationy", text="Y")
		col.itemR(con, "rotationz", text="Z")
		
		col = split.column()
		col.itemL(text="Scale:")
		col.itemR(con, "sizex", text="X")
		col.itemR(con, "sizey", text="Y")
		col.itemR(con, "sizez", text="Z")
		
		row = layout.row()
		row.itemO("constraint.childof_set_inverse")
		row.itemO("constraint.childof_clear_inverse")
		
	def TRACK_TO(self, layout, con):
		self.target_template(layout, con)
		
		row = layout.row()
		row.itemL(text="To:")
		row.itemR(con, "track", expand=True)
		
		row = layout.row()
		#row.itemR(con, "up", text="Up", expand=True) # XXX: up and expand don't play nice together
		row.itemR(con, "up", text="Up")
		row.itemR(con, "target_z")
		
		self.space_template(layout, con)
		
	def IK(self, layout, con):
		self.target_template(layout, con)
		
		layout.itemR(con, "pole_target")
	
		if con.pole_target and con.pole_target.type == 'ARMATURE':
			layout.item_pointerR(con, "pole_subtarget", con.pole_target.data, "bones", text="Bone")
		
		split = layout.split()
	
		col = split.column()
		col.itemR(con, "iterations")
		col.itemR(con, "chain_length")
		sub = col.column()
		sub.active = con.pole_target
		sub.itemR(con, "pole_angle")
		col.itemL(text="Weight:")
		col.itemR(con, "weight", text="Position", slider=True)
		sub = col.column()
		sub.active = con.rotation
		sub.itemR(con, "orient_weight", text="Rotation", slider=True)
		
		col = split.column()
		col.itemR(con, "tail")
		col.itemR(con, "rotation")
		col.itemR(con, "targetless")
		col.itemR(con, "stretch")
		
	def FOLLOW_PATH(self, layout, con):
		self.target_template(layout, con)
		
		split = layout.split()
		
		col = split.column()
		col.itemR(con, "curve_follow")
		
		col = split.column()
		col.itemR(con, "fixed_position")
		if con.fixed_position:
			col.itemR(con, "offset_percentage", text="Offset")
		else:
			col.itemR(con, "offset")
		
		row = layout.row()
		row.itemL(text="Forward:")
		row.itemR(con, "forward", expand=True)
		
		row = layout.row()
		row.itemR(con, "up", text="Up")
		row.itemL()
		
	def LIMIT_ROTATION(self, layout, con):
		
		split = layout.split()
		
		col = split.column()
		col.itemR(con, "use_limit_x")
		sub = col.column()
		sub.active = con.use_limit_x
		sub.itemR(con, "minimum_x", text="Min")
		sub.itemR(con, "maximum_x", text="Max")
		
		col = split.column()
		col.itemR(con, "use_limit_y")
		sub = col.column()
		sub.active = con.use_limit_y
		sub.itemR(con, "minimum_y", text="Min")
		sub.itemR(con, "maximum_y", text="Max")
		
		col = split.column()
		col.itemR(con, "use_limit_z")
		sub = col.column()
		sub.active = con.use_limit_z
		sub.itemR(con, "minimum_z", text="Min")
		sub.itemR(con, "maximum_z", text="Max")
		
		row = layout.row()
		row.itemR(con, "limit_transform")
		row.itemL()
		
		row = layout.row()
		row.itemL(text="Convert:")
		row.itemR(con, "owner_space", text="")
		
	def LIMIT_LOCATION(self, layout, con):
		split = layout.split()
		
		col = split.column()
		col.itemR(con, "use_minimum_x")
		sub = col.column()
		sub.active = con.use_minimum_x
		sub.itemR(con, "minimum_x", text="")
		col.itemR(con, "use_maximum_x")
		sub = col.column()
		sub.active = con.use_maximum_x
		sub.itemR(con, "maximum_x", text="")
		
		col = split.column()
		col.itemR(con, "use_minimum_y")
		sub = col.column()
		sub.active = con.use_minimum_y
		sub.itemR(con, "minimum_y", text="")
		col.itemR(con, "use_maximum_y")
		sub = col.column()
		sub.active = con.use_maximum_y
		sub.itemR(con, "maximum_y", text="")
		
		col = split.column()
		col.itemR(con, "use_minimum_z")
		sub = col.column()
		sub.active = con.use_minimum_z
		sub.itemR(con, "minimum_z", text="")
		col.itemR(con, "use_maximum_z")
		sub = col.column()
		sub.active = con.use_maximum_z
		sub.itemR(con, "maximum_z", text="")
	
		row = layout.row()
		row.itemR(con, "limit_transform")
		row.itemL()
		
		row = layout.row()
		row.itemL(text="Convert:")
		row.itemR(con, "owner_space", text="")
		
	def LIMIT_SCALE(self, layout, con):
		split = layout.split()

		col = split.column()
		col.itemR(con, "use_minimum_x")
		sub = col.column()
		sub.active = con.use_minimum_x
		sub.itemR(con, "minimum_x", text="")
		col.itemR(con, "use_maximum_x")
		sub = col.column()
		sub.active = con.use_maximum_x
		sub.itemR(con, "maximum_x", text="")
		
		col = split.column()
		col.itemR(con, "use_minimum_y")
		sub = col.column()
		sub.active = con.use_minimum_y
		sub.itemR(con, "minimum_y", text="")
		col.itemR(con, "use_maximum_y")
		sub = col.column()
		sub.active = con.use_maximum_y
		sub.itemR(con, "maximum_y", text="")
		
		col = split.column()
		col.itemR(con, "use_minimum_z")
		sub = col.column()
		sub.active = con.use_minimum_z
		sub.itemR(con, "minimum_z", text="")
		col.itemR(con, "use_maximum_z")
		sub = col.column()
		sub.active = con.use_maximum_z
		sub.itemR(con, "maximum_z", text="")
		
		row = layout.row()
		row.itemR(con, "limit_transform")
		row.itemL()
		
		row = layout.row()
		row.itemL(text="Convert:")
		row.itemR(con, "owner_space", text="")
	
	def COPY_ROTATION(self, layout, con):
		self.target_template(layout, con)
		
		split = layout.split()
		
		col = split.column()
		col.itemR(con, "rotate_like_x", text="X")
		sub = col.column()
		sub.active = con.rotate_like_x
		sub.itemR(con, "invert_x", text="Invert")
		
		col = split.column()
		col.itemR(con, "rotate_like_y", text="Y")
		sub = col.column()
		sub.active = con.rotate_like_y
		sub.itemR(con, "invert_y", text="Invert")
		
		col = split.column()
		col.itemR(con, "rotate_like_z", text="Z")
		sub = col.column()
		sub.active = con.rotate_like_z
		sub.itemR(con, "invert_z", text="Invert")

		layout.itemR(con, "offset")
		
		self.space_template(layout, con)
		
	def COPY_LOCATION(self, layout, con):
		self.target_template(layout, con)
		
		split = layout.split()
		
		col = split.column()
		col.itemR(con, "locate_like_x", text="X")
		sub = col.column()
		sub.active = con.locate_like_x
		sub.itemR(con, "invert_x", text="Invert")
		
		col = split.column()
		col.itemR(con, "locate_like_y", text="Y")
		sub = col.column()
		sub.active = con.locate_like_y
		sub.itemR(con, "invert_y", text="Invert")
		
		col = split.column()
		col.itemR(con, "locate_like_z", text="Z")
		sub = col.column()
		sub.active = con.locate_like_z
		sub.itemR(con, "invert_z", text="Invert")

		layout.itemR(con, "offset")
			
		self.space_template(layout, con)
		
	def COPY_SCALE(self, layout, con):
		self.target_template(layout, con)
		
		row = layout.row(align=True)
		row.itemR(con, "size_like_x", text="X")
		row.itemR(con, "size_like_y", text="Y")
		row.itemR(con, "size_like_z", text="Z")

		layout.itemR(con, "offset")
		
		self.space_template(layout, con)
		
	#def SCRIPT(self, layout, con):
	
	def ACTION(self, layout, con):
		self.target_template(layout, con)
		
		layout.itemR(con, "action")
		layout.itemR(con, "transform_channel")

		split = layout.split()
	
		col = split.column(align=True)
		col.itemR(con, "start_frame", text="Start")
		col.itemR(con, "end_frame", text="End")
		
		col = split.column(align=True)
		col.itemR(con, "minimum", text="Min")
		col.itemR(con, "maximum", text="Max")
		
		row = layout.row()
		row.itemL(text="Convert:")
		row.itemR(con, "owner_space", text="")
	
	def LOCKED_TRACK(self, layout, con):
		self.target_template(layout, con)
		
		row = layout.row()
		row.itemL(text="To:")
		row.itemR(con, "track", expand=True)
		
		row = layout.row()
		row.itemL(text="Lock:")
		row.itemR(con, "locked", expand=True)
		
	def LIMIT_DISTANCE(self, layout, con):
		self.target_template(layout, con)
		
		col = layout.column(align=True);
		col.itemR(con, "distance")
		col.itemO("constraint.limitdistance_reset")
		
		row = layout.row()
		row.itemL(text="Clamp Region:")
		row.itemR(con, "limit_mode", text="")
		
	def STRETCH_TO(self, layout, con):
		self.target_template(layout, con)
		
		row = layout.row()
		row.itemR(con, "original_length", text="Rest Length")
		row.itemO("constraint.stretchto_reset", text="Reset")
		
		col = layout.column()
		col.itemR(con, "bulge", text="Volume Variation")
		
		row = layout.row()
		row.itemL(text="Volume:")
		row.itemR(con, "volume", expand=True)
		row.itemL(text="Plane:")
		row.itemR(con, "keep_axis", expand=True)
		
	def FLOOR(self, layout, con):
		self.target_template(layout, con)
		
		row = layout.row()
		row.itemR(con, "sticky")
		row.itemR(con, "use_rotation")
		
		layout.itemR(con, "offset")
		
		row = layout.row()
		row.itemL(text="Min/Max:")
		row.itemR(con, "floor_location", expand=True)
		
	def RIGID_BODY_JOINT(self, layout, con):
		self.target_template(layout, con)
		
		layout.itemR(con, "pivot_type")
		layout.itemR(con, "child")
		
		row = layout.row()
		row.itemR(con, "disable_linked_collision", text="No Collision")
		row.itemR(con, "draw_pivot", text="Display Pivot")
		
		split = layout.split()
		
		col = split.column(align=True)
		col.itemL(text="Pivot:")
		col.itemR(con, "pivot_x", text="X")
		col.itemR(con, "pivot_y", text="Y")
		col.itemR(con, "pivot_z", text="Z")
		
		col = split.column(align=True)
		col.itemL(text="Axis:")
		col.itemR(con, "axis_x", text="X")
		col.itemR(con, "axis_y", text="Y")
		col.itemR(con, "axis_z", text="Z")
		
		#Missing: Limit arrays (not wrapped in RNA yet) 
	
	def CLAMP_TO(self, layout, con):
		self.target_template(layout, con)
		
		row = layout.row()
		row.itemL(text="Main Axis:")
		row.itemR(con, "main_axis", expand=True)
		
		row = layout.row()
		row.itemR(con, "cyclic")
		
	def TRANSFORM(self, layout, con):
		self.target_template(layout, con)
		
		layout.itemR(con, "extrapolate_motion", text="Extrapolate")
		
		split = layout.split()
		
		col = split.column()
		col.itemL(text="Source:")
		col.row().itemR(con, "map_from", expand=True)
		
		sub = col.row(align=True)
		sub.itemL(text="X:")
		sub.itemR(con, "from_min_x", text="")
		sub.itemR(con, "from_max_x", text="")
		
		sub = col.row(align=True)
		sub.itemL(text="Y:")
		sub.itemR(con, "from_min_y", text="")
		sub.itemR(con, "from_max_y", text="")
		
		sub = col.row(align=True)
		sub.itemL(text="Z:")
		sub.itemR(con, "from_min_z", text="")
		sub.itemR(con, "from_max_z", text="")
		
		split = layout.split()
		
		col = split.column()
		col.itemL(text="Destination:")
		col.row().itemR(con, "map_to", expand=True)

		sub = col.row(align=True)
		sub.itemR(con, "map_to_x_from", text="")
		sub.itemR(con, "to_min_x", text="")
		sub.itemR(con, "to_max_x", text="")
		
		sub = col.row(align=True)
		sub.itemR(con, "map_to_y_from", text="")
		sub.itemR(con, "to_min_y", text="")
		sub.itemR(con, "to_max_y", text="")
		
		sub = col.row(align=True)
		sub.itemR(con, "map_to_z_from", text="")
		sub.itemR(con, "to_min_z", text="")
		sub.itemR(con, "to_max_z", text="")
		
		self.space_template(layout, con)
		
	def SHRINKWRAP (self, layout, con):
		self.target_template(layout, con)
		
		layout.itemR(con, "distance")
		layout.itemR(con, "shrinkwrap_type")
		
		if con.shrinkwrap_type == 'PROJECT':
			row = layout.row(align=True)
			row.itemR(con, "axis_x")
			row.itemR(con, "axis_y")
			row.itemR(con, "axis_z")
		
class OBJECT_PT_constraints(ConstraintButtonsPanel):
	__label__ = "Constraints"
	__context__ = "constraint"

	def poll(self, context):
		return (context.object)
		
	def draw(self, context):
		layout = self.layout
		ob = context.object

		row = layout.row()
		row.item_menu_enumO("object.constraint_add", "type")
		row.itemL();

		for con in ob.constraints:
			self.draw_constraint(con)

class BONE_PT_constraints(ConstraintButtonsPanel):
	__label__ = "Constraints"
	__context__ = "bone"

	def poll(self, context):
		ob = context.object
		return (ob and ob.type == 'ARMATURE' and context.bone)
		
	def draw(self, context):
		layout = self.layout
		
		ob = context.object
		pchan = ob.pose.pose_channels[context.bone.name]

		row = layout.row()
		row.item_menu_enumO("pose.constraint_add", "type")
		row.itemL();

		for con in pchan.constraints:
			self.draw_constraint(con)

bpy.types.register(OBJECT_PT_constraints)
bpy.types.register(BONE_PT_constraints)