-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproperties.py
More file actions
542 lines (432 loc) · 18.3 KB
/
Copy pathproperties.py
File metadata and controls
542 lines (432 loc) · 18.3 KB
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
536
537
538
539
540
541
542
from bpy.types import AddonPreferences
import bpy
# Selection order tracking
_last_select_state = {}
_last_tracked_counter = 0
@bpy.app.handlers.persistent
def _festivity_flow_track_selection(scene, depsgraph):
global _last_select_state, _last_tracked_counter
if bpy.context.mode != 'POSE':
return
arm_obj = bpy.context.view_layer.objects.active
if arm_obj is None or arm_obj.type != 'ARMATURE':
return
stored_counter = arm_obj.get('_festivity_flow_sel_counter', 0)
if stored_counter != _last_tracked_counter:
_last_select_state.clear()
_last_tracked_counter = stored_counter
counter = stored_counter
changed = False
for pb in arm_obj.pose.bones:
is_sel = pb.select
was_sel = _last_select_state.get(pb.name, False)
if is_sel and not was_sel:
counter += 1
pb.festivity_flow_selection_order = counter
changed = True
_last_select_state[pb.name] = is_sel
if changed:
try:
arm_obj['_festivity_flow_sel_counter'] = counter
_last_tracked_counter = counter
except:
pass
#
# SWAY CHAIN UPDATE FUNCTIONS
#
def update_sw_prop(self, attr_name, attr_value):
prefs = bpy.context.preferences.addons[__package__].preferences
if self.festivity_flow_update:
active_chain_id = self.festivity_flow_chain_id
chains, bones = [], []
for pb in bpy.context.selected_pose_bones:
if pb.festivity_flow_has_sway == False:
continue
if prefs.apply_to_all_chains == False and pb.festivity_flow_chain_id != active_chain_id:
continue
if pb.festivity_flow_chain_id not in chains:
chains.append(pb.festivity_flow_chain_id)
bones.append(pb)
skip_rigs = []
for p, pb in enumerate(bones):
if pb.id_data in skip_rigs:
continue
else:
skip_rigs.append(pb.id_data)
for c_pb in pb.id_data.pose.bones:
if c_pb.festivity_flow_chain_id in chains and c_pb.festivity_flow_has_sway:
c_pb.festivity_flow_update = False
setattr(c_pb, attr_name, attr_value)
c_pb.festivity_flow_update = True
return
def update_sw_amplitude(self, context):
update_sw_prop(self, "festivity_flow_sw_amplitude", self.festivity_flow_sw_amplitude)
return
def update_sw_frequency(self, context):
update_sw_prop(self, "festivity_flow_sw_frequency", self.festivity_flow_sw_frequency)
return
def update_sw_delay(self, context):
update_sw_prop(self, "festivity_flow_sw_delay", self.festivity_flow_sw_delay)
return
def update_sw_delay_opposite(self, context):
update_sw_prop(self, "festivity_flow_sw_delay_opposite", self.festivity_flow_sw_delay_opposite)
from .functions import rebuild_sway_drivers
rebuild_sway_drivers(self)
return
def update_sw_offset(self, context):
update_sw_prop(self, "festivity_flow_sw_offset", self.festivity_flow_sw_offset)
return
def update_sw_falloff_start(self, context):
update_sw_prop(self, "festivity_flow_sw_falloff_start", self.festivity_flow_sw_falloff_start)
return
def update_sw_speed(self, context):
update_sw_prop(self, "festivity_flow_sw_speed", self.festivity_flow_sw_speed)
return
def update_sw_random_seed(self, context):
update_sw_prop(self, "festivity_flow_sw_random_seed", self.festivity_flow_sw_random_seed)
return
def update_sw_roll(self, context):
update_sw_prop(self, "festivity_flow_sw_roll", self.festivity_flow_sw_roll)
return
def update_sw_sub_amplitude(self, context):
update_sw_prop(self, "festivity_flow_sw_sub_amplitude", self.festivity_flow_sw_sub_amplitude)
return
def update_sw_sub_frequency(self, context):
update_sw_prop(self, "festivity_flow_sw_sub_frequency", self.festivity_flow_sw_sub_frequency)
return
def update_sw_sub_delay(self, context):
update_sw_prop(self, "festivity_flow_sw_sub_delay", self.festivity_flow_sw_sub_delay)
return
def update_sw_sub_delay_opposite(self, context):
update_sw_prop(self, "festivity_flow_sw_sub_delay_opposite", self.festivity_flow_sw_sub_delay_opposite)
from .functions import rebuild_sway_drivers
rebuild_sway_drivers(self)
return
def update_sw_sub_offset(self, context):
update_sw_prop(self, "festivity_flow_sw_sub_offset", self.festivity_flow_sw_sub_offset)
return
def update_sw_sub_falloff_start(self, context):
update_sw_prop(self, "festivity_flow_sw_sub_falloff_start", self.festivity_flow_sw_sub_falloff_start)
return
def update_sw_bias(self, context):
update_sw_prop(self, "festivity_flow_sw_bias", self.festivity_flow_sw_bias)
return
def update_sw_sub_bias(self, context):
update_sw_prop(self, "festivity_flow_sw_sub_bias", self.festivity_flow_sw_sub_bias)
return
def update_sw_limit_pos(self, context):
update_sw_prop(self, "festivity_flow_sw_limit_pos", self.festivity_flow_sw_limit_pos)
def update_sw_limit_neg(self, context):
update_sw_prop(self, "festivity_flow_sw_limit_neg", self.festivity_flow_sw_limit_neg)
def update_sw_sub_limit_pos(self, context):
update_sw_prop(self, "festivity_flow_sw_sub_limit_pos", self.festivity_flow_sw_sub_limit_pos)
def update_sw_sub_limit_neg(self, context):
update_sw_prop(self, "festivity_flow_sw_sub_limit_neg", self.festivity_flow_sw_sub_limit_neg)
def update_sway_visualizer(self, context):
from .visualizer import enable_sway_visualizer, disable_sway_visualizer
if self.festivity_flow_show_sway_visualizer:
enable_sway_visualizer()
else:
disable_sway_visualizer()
if context.screen:
for area in context.screen.areas:
if area.type == 'VIEW_3D':
area.tag_redraw()
return
#
# PREFERENCES
#
class FlowPreferences(AddonPreferences):
bl_idname = __package__
apply_to_all_chains: bpy.props.BoolProperty(
default=True,
name="Auto Update All Selected Chains",
description="Any settings change for the active chain will apply to all selected bone chains",
)
keep_existing_settings: bpy.props.BoolProperty(
default=True,
name="Keep Existing Settings",
description="When readding a physics type to bones it will keep the previously set settings. Otherwise it will load in the active preset"
)
sw_general_menu: bpy.props.BoolProperty(
default=True,
)
sw_subwave_menu: bpy.props.BoolProperty(
default=True,
)
sw_global_menu: bpy.props.BoolProperty(
default=True,
)
festivity_flow_batch_offset_increment: bpy.props.FloatProperty(
default=24.0,
min=0.0,
max=100.0,
name="Increment (frames)",
description="Incremental offset value applied to each selected chain when using batch offset",
)
festivity_flow_offset_adjust_value: bpy.props.FloatProperty(
default=12.0,
min=-100.0,
max=100.0,
name="Adjust (frames)",
description="Value to add, subtract, or set the offset of selected sway chains",
)
festivity_flow_roll_adjust_value: bpy.props.FloatProperty(
default=45.0,
min=-360.0,
max=360.0,
name="Roll Adjust",
description="Degrees to add, subtract, or set the y-axis roll of selected sway chains",
)
festivity_flow_show_sway_visualizer: bpy.props.BoolProperty(
default=False,
name="Show Sway Direction",
description="Show arrows in the 3D viewport indicating the sway direction for each bone",
update=update_sway_visualizer,
)
def draw(self, context):
layout = self.layout
column = layout.column(align=True)
row = column.row(align=True)
row.prop(self, "apply_to_all_chains")
row = column.row(align=True)
row.prop(self, "keep_existing_settings")
#
# PROPERTY REGISTRATION
#
_classes = [
FlowPreferences,
]
_register, _unregister = bpy.utils.register_classes_factory(_classes)
def register():
_register()
bpy.types.PoseBone.festivity_flow_has_sway = bpy.props.BoolProperty(
default=False, options={"LIBRARY_EDITABLE"}, override={"LIBRARY_OVERRIDABLE"}
)
bpy.types.PoseBone.festivity_flow_chain_id = bpy.props.StringProperty(
default="", options={"LIBRARY_EDITABLE"}, override={"LIBRARY_OVERRIDABLE"}
)
bpy.types.PoseBone.festivity_flow_end_of_chain = bpy.props.BoolProperty(
default=False, options={"LIBRARY_EDITABLE"}, override={"LIBRARY_OVERRIDABLE"}
)
bpy.types.PoseBone.festivity_flow_update = bpy.props.BoolProperty(
default=True, options={"LIBRARY_EDITABLE"}, override={"LIBRARY_OVERRIDABLE"}
)
# Sway Chain Properties
bpy.types.PoseBone.festivity_flow_sw_amplitude = bpy.props.FloatProperty(
default=5.0,
min=0.0,
max=90.0,
description="Maximum rotation angle in degrees for the main axis sway wave",
update=update_sw_amplitude,
options={"LIBRARY_EDITABLE", "ANIMATABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_sw_frequency = bpy.props.FloatProperty(
default=1.0,
min=0.01,
max=20.0,
description="Number of complete wave cycles per second",
update=update_sw_frequency,
options={"LIBRARY_EDITABLE", "ANIMATABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_sw_delay = bpy.props.FloatProperty(
default=10.0,
min=0.0,
max=1000.0,
soft_max=100.0,
subtype="PERCENTAGE",
description="Lag between the ends of the chain as a percentage of one wave cycle, creating the cascading sway effect. Independent of frequency, speed, fps and chain length (100% = the trailing bone is a full cycle behind the leading one)",
update=update_sw_delay,
options={"LIBRARY_EDITABLE", "ANIMATABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_sw_delay_opposite = bpy.props.BoolProperty(
default=False,
description="Reverse the wave cascade direction so the root leads and the tip trails",
update=update_sw_delay_opposite,
options={"LIBRARY_EDITABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_sw_offset = bpy.props.FloatProperty(
default=0.0,
min=-1000.0,
max=1000.0,
description="Frame offset for the chain's starting position in the wave cycle",
update=update_sw_offset,
options={"LIBRARY_EDITABLE", "ANIMATABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_sw_falloff_start = bpy.props.FloatProperty(
default=0.2,
min=0.0,
max=1.0,
description="Amplitude factor at the chain root (0 = no motion at root, 1 = full motion everywhere)",
update=update_sw_falloff_start,
options={"LIBRARY_EDITABLE", "ANIMATABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_sw_speed = bpy.props.FloatProperty(
default=1.0,
min=0.01,
max=5.0,
description="Global speed multiplier for the sway animation",
update=update_sw_speed,
options={"LIBRARY_EDITABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_sw_random_seed = bpy.props.FloatProperty(
default=0.0,
min=-10.0,
max=10.0,
description="Random time offset for this chain to prevent all chains from syncing",
update=update_sw_random_seed,
options={"LIBRARY_EDITABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_sw_roll = bpy.props.FloatProperty(
default=0.0,
min=-360.0,
max=360.0,
description="Per-bone phase offset in degrees to curve the sway direction along the chain",
update=update_sw_roll,
options={"LIBRARY_EDITABLE", "ANIMATABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_sw_sub_amplitude = bpy.props.FloatProperty(
default=0.0,
min=0.0,
max=90.0,
description="Maximum rotation angle in degrees for the sub axis sway wave",
update=update_sw_sub_amplitude,
options={"LIBRARY_EDITABLE", "ANIMATABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_sw_sub_frequency = bpy.props.FloatProperty(
default=1.0,
min=0.01,
max=20.0,
description="Number of complete Z-axis wave cycles per second",
update=update_sw_sub_frequency,
options={"LIBRARY_EDITABLE", "ANIMATABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_sw_sub_delay = bpy.props.FloatProperty(
default=10.0,
min=0.0,
max=1000.0,
soft_max=100.0,
subtype="PERCENTAGE",
description="Lag between the ends of the chain for the Z-axis wave cascade, as a percentage of one sub wave cycle. Independent of frequency, speed, fps and chain length",
update=update_sw_sub_delay,
options={"LIBRARY_EDITABLE", "ANIMATABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_sw_sub_delay_opposite = bpy.props.BoolProperty(
default=False,
description="Reverse the sub-axis wave cascade direction so the root leads and the tip trails",
update=update_sw_sub_delay_opposite,
options={"LIBRARY_EDITABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_sw_sub_offset = bpy.props.FloatProperty(
default=0.0,
min=-1000.0,
max=1000.0,
description="Frame offset for the Z-axis wave starting position",
update=update_sw_sub_offset,
options={"LIBRARY_EDITABLE", "ANIMATABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_sw_sub_falloff_start = bpy.props.FloatProperty(
default=0.2,
min=0.0,
max=1.0,
description="Z-axis wave amplitude factor at the chain root",
update=update_sw_sub_falloff_start,
options={"LIBRARY_EDITABLE", "ANIMATABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_sw_bias = bpy.props.FloatProperty(
default=0.0,
min=-90.0,
max=90.0,
description="Constant angular offset in the main sway direction (positive = toward arrow, negative = against arrow)",
update=update_sw_bias,
options={"LIBRARY_EDITABLE", "ANIMATABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_sw_sub_bias = bpy.props.FloatProperty(
default=0.0,
min=-90.0,
max=90.0,
description="Constant angular offset in the sub sway direction (positive = toward arrow, negative = against arrow)",
update=update_sw_sub_bias,
options={"LIBRARY_EDITABLE", "ANIMATABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_sw_limit_pos = bpy.props.FloatProperty(
default=360.0, min=0.0, max=360.0,
description="Maximum positive rotation (in rest space) on the main sway axis. Acts like a soft collision wall.",
update=update_sw_limit_pos,
options={"LIBRARY_EDITABLE", "ANIMATABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_sw_limit_neg = bpy.props.FloatProperty(
default=-360.0, min=-360.0, max=0.0,
description="Minimum (most negative) rotation (in rest space) on the main sway axis.",
update=update_sw_limit_neg,
options={"LIBRARY_EDITABLE", "ANIMATABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_sw_sub_limit_pos = bpy.props.FloatProperty(
default=360.0, min=0.0, max=360.0,
description="Maximum positive rotation (in rest space) on the sub sway axis.",
update=update_sw_sub_limit_pos,
options={"LIBRARY_EDITABLE", "ANIMATABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_sw_sub_limit_neg = bpy.props.FloatProperty(
default=-360.0, min=-360.0, max=0.0,
description="Minimum (most negative) rotation (in rest space) on the sub sway axis.",
update=update_sw_sub_limit_neg,
options={"LIBRARY_EDITABLE", "ANIMATABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.types.PoseBone.festivity_flow_selection_order = bpy.props.IntProperty(
default=0,
options={"LIBRARY_EDITABLE"},
override={"LIBRARY_OVERRIDABLE"},
)
bpy.app.handlers.depsgraph_update_post.append(_festivity_flow_track_selection)
def unregister():
_unregister()
if _festivity_flow_track_selection in bpy.app.handlers.depsgraph_update_post:
bpy.app.handlers.depsgraph_update_post.remove(_festivity_flow_track_selection)
del bpy.types.PoseBone.festivity_flow_selection_order
del bpy.types.PoseBone.festivity_flow_sw_sub_limit_neg
del bpy.types.PoseBone.festivity_flow_sw_sub_limit_pos
del bpy.types.PoseBone.festivity_flow_sw_limit_neg
del bpy.types.PoseBone.festivity_flow_sw_limit_pos
del bpy.types.PoseBone.festivity_flow_sw_sub_bias
del bpy.types.PoseBone.festivity_flow_sw_bias
del bpy.types.PoseBone.festivity_flow_sw_sub_falloff_start
del bpy.types.PoseBone.festivity_flow_sw_sub_offset
del bpy.types.PoseBone.festivity_flow_sw_sub_delay_opposite
del bpy.types.PoseBone.festivity_flow_sw_sub_delay
del bpy.types.PoseBone.festivity_flow_sw_sub_frequency
del bpy.types.PoseBone.festivity_flow_sw_sub_amplitude
del bpy.types.PoseBone.festivity_flow_sw_random_seed
del bpy.types.PoseBone.festivity_flow_sw_roll
del bpy.types.PoseBone.festivity_flow_sw_speed
del bpy.types.PoseBone.festivity_flow_sw_falloff_start
del bpy.types.PoseBone.festivity_flow_sw_offset
del bpy.types.PoseBone.festivity_flow_sw_delay_opposite
del bpy.types.PoseBone.festivity_flow_sw_delay
del bpy.types.PoseBone.festivity_flow_sw_frequency
del bpy.types.PoseBone.festivity_flow_sw_amplitude
del bpy.types.PoseBone.festivity_flow_update
del bpy.types.PoseBone.festivity_flow_end_of_chain
del bpy.types.PoseBone.festivity_flow_chain_id
del bpy.types.PoseBone.festivity_flow_has_sway