forked from tingjoybits/Mesh_Onion_Skins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mesh_Onion_Skins.py
4404 lines (3799 loc) · 150 KB
/
Mesh_Onion_Skins.py
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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENCE BLOCK #####
import bpy
import os
import json
import time
import gpu
if bpy.app.version < (3, 0, 0):
import bgl
import numpy as np
from bpy.props import *
from bpy.types import Menu, Panel, AddonPreferences, Operator
from gpu_extras.batch import batch_for_shader
from mathutils import Vector, Matrix
bl_info = {
'name': "Mesh Onion Skins",
'author': "TingJoyBits",
'version': (1, 1, 0),
'blender': (2, 80, 0),
'location': "View3D > Animation > Mesh Onion Skins",
'description': "Mesh Onion Skins for Blender Animations",
'wiki_url': "https://github.com/tingjoybits/Mesh_Onion_Skins",
'category': "Animation"}
OS_collection_name = "Mesh Onion Skins"
OS_empty_name = "Mesh_Onion_Skins"
MAT_PREFIX = "onion_skins_mat_"
SUFFIX_before = "before"
SUFFIX_after = "after"
SUFFIX_marker = "marker"
SUFFIX_own = "own"
OS_Selected_Object_Sets = {}
OS_Selected_Object_Collection = {}
SEPARATOR = "{|SEPARATOR|}"
CREATING = False
RENDERING = False
Active_Object = None
GPU_FRAMES = {}
GPU_MARKERS = {}
DRAW_TOGGLE = False
SHADER = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
Draw_Handler = None
Draw_Timer = None
def checkout_parent(obj):
if not obj:
return None
if obj.type == 'ARMATURE':
return obj
if obj.parent:
return obj.parent
return obj
def traverse_tree(t):
yield t
for child in t.children:
yield from traverse_tree(child)
def parent_lookup(coll):
parent_lookup = {}
for coll in traverse_tree(coll):
for c in coll.children.keys():
if parent_lookup.get(c):
parent_lookup[c].append(coll.name)
else:
parent_lookup[c] = [coll.name]
return parent_lookup
def list_to_str(input_list, seperator):
# Join all the strings in list
try:
final_str = seperator.join(input_list)
except TypeError:
final_str = ''
for items in input_list:
final_str = final_str + str(items[0]) + ', ' + str(items[1]) + seperator
return final_str
def childrens_lookup(obj, list_type='obj'):
objs = []
for ob in traverse_tree(obj):
for o in ob.children:
if o.name != ob.name:
if list_type == 'obj':
objs.append(o)
if list_type == 'name':
objs.append(o.name)
return objs
def text_lookup(find_string, source_text):
if source_text.find(find_string) != -1:
return True
else:
return False
def mesh_show_wire(self, context):
obj = context.active_object
wm = context.window_manager
children_list = [i.name for i in wm.os_childrens_collection]
childrens = childrens_lookup(obj, list_type='name') + children_list
childrens.append(obj.name)
for c in childrens:
ob = bpy.data.objects[c]
if ob.type != 'MESH':
continue
if self.mesh_wire:
if not ob.show_wire:
ob.show_wire = True
else:
if ob.show_wire:
ob.show_wire = False
def mesh_show_inFront(self, context):
obj = context.active_object
wm = context.window_manager
children_list = [i.name for i in wm.os_childrens_collection]
childrens = childrens_lookup(obj, list_type='name') + children_list
childrens.append(obj.name)
for c in childrens:
ob = bpy.data.objects[c]
if ob.type != 'MESH':
continue
if self.mesh_inFront:
if not ob.show_in_front:
ob.show_in_front = True
else:
if ob.show_in_front:
ob.show_in_front = False
def shading_color_type(self, context):
shading = bpy.context.space_data.shading
if self.color_type == 'MATERIAL' and shading.color_type != 'MATERIAL':
shading.color_type = 'MATERIAL'
if self.color_type == 'TEXTURE' and shading.color_type != 'TEXTURE':
shading.color_type = 'TEXTURE'
if self.color_type == 'OBJECT' and shading.color_type != 'OBJECT':
shading.color_type = 'OBJECT'
sc = bpy.context.scene.onion_skins_scene_props
if sc.view_range:
view_range_frames(context.scene)
else:
set_onion_colors('BEFORE')
set_onion_colors('AFTER')
set_onion_colors('MARKER')
def set_base_material_colors(skin_prefix):
mat_color = get_prefix_material_color(skin_prefix)
m = get_base_material(skin_prefix)
if not m:
create_skins_materials()
m = get_base_material(skin_prefix)
if m:
set_material_color(m, mat_color)
def update_color_bf(self, context):
tree = get_empty_objs_tree()
if not tree:
set_base_material_colors('before')
return None
set_onion_colors('BEFORE')
if self.view_range:
view_range_frames(context.scene)
def update_color_af(self, context):
tree = get_empty_objs_tree()
if not tree:
set_base_material_colors('after')
return None
set_onion_colors('AFTER')
if self.view_range:
view_range_frames(context.scene)
def update_color_m(self, context):
tree = get_empty_objs_tree(False, 'MARKER')
if not tree:
set_base_material_colors('marker')
return None
set_onion_colors('MARKER')
def update_colors(self, context):
set_onion_colors('BEFORE', fade=True)
set_onion_colors('AFTER', fade=True)
set_onion_colors('MARKER')
if self.fade_to_alpha is False:
update_fade_alpha(self, context)
if self.view_range:
view_range_frames(context.scene)
def update_color_alpha(self, context):
if self.color_alpha:
self.mat_color_bf[3] = self.color_alpha_value
self.mat_color_af[3] = self.color_alpha_value
self.mat_color_m[3] = self.color_alpha_value
else:
self.mat_color_bf[3] = 1.0
self.mat_color_af[3] = 1.0
self.mat_color_m[3] = 1.0
if self.fade_to_alpha:
self.fade_to_alpha = False
set_onion_colors('BEFORE')
set_onion_colors('AFTER')
set_onion_colors('MARKER')
if self.view_range:
view_range_frames(context.scene)
def update_fade_alpha(self, context):
tree = get_empty_objs_tree()
if not tree:
return None
if self.fade_to_alpha is False:
for s in tree.children:
try:
if self.onionsk_colors:
if s.name.split('_')[0] == 'before':
s.data.materials[0] = bpy.data.materials[MAT_PREFIX + SUFFIX_before]
if s.name.split('_')[0] == 'after':
s.data.materials[0] = bpy.data.materials[MAT_PREFIX + SUFFIX_after]
else:
s.data.materials[0] = bpy.data.materials[
MAT_PREFIX + list_to_str(s.name.split('_')[1:-1], '_') + '_' + SUFFIX_own]
except KeyError:
pass
if self.color_alpha is False and self.fade_to_alpha is True:
self.color_alpha = True
set_onion_colors('BEFORE')
set_onion_colors('AFTER')
if self.view_range:
view_range_frames(context.scene)
def update_os_prop_toggle(self, context, prop):
treeM = get_empty_objs_tree(False, 'MARKER')
treeOS = get_empty_objs_tree(False)
markers = []
oskins = []
if not treeOS and not treeM:
return None
if treeM:
markers = [s for s in treeM.children]
if treeOS:
oskins = [s for s in treeOS.children]
skins = markers + oskins
for s in skins:
if prop == 'wire':
if self.onionsk_wire:
s.show_wire = True
else:
s.show_wire = False
if prop == 'in_renders':
if self.show_in_render:
s.hide_render = False
else:
s.hide_render = True
if prop == 'selectable':
if self.os_selectable:
s.hide_select = False
else:
s.hide_select = True
if self.view_range and prop == 'in_renders':
view_range_frames(context.scene)
def update_os_prop_toggle_wire(self, context):
update_os_prop_toggle(self, context, 'wire')
def update_os_prop_toggle_in_renders(self, context):
update_os_prop_toggle(self, context, 'in_renders')
def update_os_prop_toggle_selectable(self, context):
update_os_prop_toggle(self, context, 'selectable')
def update_view_range(self, context):
if self.view_range:
view_range_frames(context.scene)
return None
tree = get_empty_objs_tree()
if not tree:
return None
for s in tree.children:
if self.show_in_render:
s.hide_render = True
if s.name.split('_')[0] == 'before':
if not self.hide_os_before:
s.hide_viewport = True
else:
s.hide_viewport = False
if s.name.split('_')[0] == 'after':
if not self.hide_os_after:
s.hide_viewport = True
else:
s.hide_viewport = False
if self.fade_to_alpha:
self.fade_to_alpha = True
else:
self.fade_to_alpha = False
def update_view_range_frame_type(self, context):
if not self.os_draw_mode == 'MESH':
return None
view_range_frames(context.scene)
def NoKeysError(self, context):
msg = "Mesh Onion Skins: Keyframes didn't found. Use Edit strip mode of the action if animation data is not empty."
print(msg)
self.layout.label(text=msg)
def update_mpath(self, context):
params = bpy.context.window_manager.onionSkinsParams
if not params.onion_skins_init:
return None
sc = bpy.context.scene.onion_skins_scene_props
if sc.onionsk_mpath is False:
remove_motion_paths(context, context.mode, only_selected=False)
return None
wm = context.window_manager
mode = context.mode
obj = context.active_object
global CREATING
CREATING = True
OSkins = Onion_Skins(obj=obj)
if sc.onionsk_method == 'FRAME':
fs, fe = OSkins.os_method_frame(dont_create=True)
create_update_motion_path(context, mode, obj, fs, fe, [], [])
if sc.onionsk_method == 'SCENE':
fs, fe = OSkins.os_method_range(context, dont_create=True)
if fs is False and fe is False:
CREATING = False
if not hasattr(self, 'onionsk_mpath'):
wm.popup_menu(NoKeysError, title="Error", icon="INFO")
return None
create_update_motion_path(context, mode, obj, fs, fe, [], [])
if sc.onionsk_method == 'KEYFRAME':
kfb_kfa = OSkins.os_method_keyframe(dont_create=True)
if not kfb_kfa:
CREATING = False
if not hasattr(self, 'onionsk_mpath'):
wm.popup_menu(NoKeysError, title="Error", icon="INFO")
return None
create_update_motion_path(context, mode, obj, 0, 0, kfb_kfa[0], kfb_kfa[1])
CREATING = False
def update_tmarker(self, context):
sc = context.scene.onion_skins_scene_props
if sc.onionsk_tmarker is False:
remove_time_markers()
return None
if sc.os_draw_mode == 'GPU':
objp = checkout_parent(context.active_object)
if not GPU_FRAMES.get(objp.name):
return None
frame_nums = list(set([int(float(f.split('|@|')[-1]))
for f in GPU_FRAMES[objp.name]]))
else:
tree = get_empty_objs_tree(False)
if not tree:
return None
frame_nums = [float(s.name.split('_')[-1]) for s in tree.children]
frame_nums = list(set(frame_nums))
tmarkers = context.scene.timeline_markers
for frame in frame_nums:
tmarkers.new("os", frame=frame)
def update_os_draw_technic(self, context):
sc = context.scene.onion_skins_scene_props
if sc.onionsk_tmarker:
remove_time_markers()
update_tmarker(self, context)
update_object_data_collection_items()
def get_empty_objs_tree(active_obj=False, skin_type='ONION'):
if not active_obj:
try:
active_obj = bpy.context.active_object
except AttributeError:
wm = bpy.context.window_manager
active_obj = bpy.data.objects[wm.active_os_set.split('|<@>|')[0]]
objp = checkout_parent(active_obj)
if not objp:
return False
try:
if skin_type == 'ONION':
tree = bpy.data.objects["onionsk_"+objp.name]
elif skin_type == 'MARKER':
tree = bpy.data.objects["onionsk_M_"+objp.name]
return tree
except KeyError:
return False
def hide_before_frames(self, context):
sc = bpy.context.scene.onion_skins_scene_props
tree = get_empty_objs_tree()
if tree:
for s in tree.children:
if s.name.split('_')[0] == 'before':
if sc.hide_os_before is False:
s.hide_viewport = True
else:
s.hide_viewport = False
if not sc.hide_os_before:
if sc.hide_os_all:
hide_all_os_frames(switch=True, value=False)
check_all_frames_flag()
if sc.view_range:
view_range_frames(context.scene)
def hide_after_frames(self, context):
sc = bpy.context.scene.onion_skins_scene_props
tree = get_empty_objs_tree()
if tree:
for s in tree.children:
if s.name.split('_')[0] == 'after':
if sc.hide_os_after is False:
s.hide_viewport = True
else:
s.hide_viewport = False
if not sc.hide_os_after:
if sc.hide_os_all:
hide_all_os_frames(switch=True, value=False)
check_all_frames_flag()
if sc.view_range:
view_range_frames(context.scene)
def hide_marker_frames(self, context):
sc = bpy.context.scene.onion_skins_scene_props
tree = get_empty_objs_tree(False, 'MARKER')
if tree:
for s in tree.children:
if sc.hide_os_marker is False:
s.hide_viewport = True
else:
s.hide_viewport = False
if not sc.hide_os_marker:
if sc.hide_os_all:
hide_all_os_frames(switch=True, value=False)
check_all_frames_flag()
switch_os_all_frames_flag = False
def check_all_frames_flag():
sc = bpy.context.scene.onion_skins_scene_props
if sc.hide_os_before and sc.hide_os_after and sc.hide_os_marker:
if not sc.hide_os_all:
sc.hide_os_all = True
def hide_all_os_frames(switch=False, value=False):
sc = bpy.context.scene.onion_skins_scene_props
if switch:
global switch_os_all_frames_flag
switch_os_all_frames_flag = True
if value:
if not sc.hide_os_all:
sc.hide_os_all = True
if not value:
if sc.hide_os_all:
sc.hide_os_all = False
return None
if sc.hide_os_all:
if not sc.hide_os_before:
sc.hide_os_before = True
if not sc.hide_os_after:
sc.hide_os_after = True
if not sc.hide_os_marker:
sc.hide_os_marker = True
if not sc.hide_os_all:
if sc.hide_os_before:
sc.hide_os_before = False
if sc.hide_os_after:
sc.hide_os_after = False
if sc.hide_os_marker:
sc.hide_os_marker = False
if sc.view_range:
view_range_frames(bpy.context.scene)
def hide_all_frames(self, context):
global switch_os_all_frames_flag
if switch_os_all_frames_flag:
switch_os_all_frames_flag = False
return None
hide_all_os_frames()
def actions_check(obj):
if not obj:
return False
if hasattr(obj.animation_data, 'action'):
return True
elif obj.parent:
if hasattr(obj.parent.animation_data, 'action'):
return True
return False
def apply_pref_settings():
prefs = bpy.context.preferences.addons[__name__].preferences
sc = bpy.context.scene.onion_skins_scene_props
for pr in prefs.__annotations__:
if pr == 'category' or pr == 'display_progress':
continue
exec("sc." + pr + " = prefs." + pr)
def handler_check(handler, function_name):
if len(handler) <= 0:
return False
for i, h in enumerate(handler):
func = str(handler[i]).split(' ')[1]
if func == function_name:
return True
return False
def check_handlers():
if not handler_check(bpy.app.handlers.load_post, "m_os_on_file_load"):
bpy.app.handlers.load_post.append(m_os_on_file_load)
if not handler_check(bpy.app.handlers.depsgraph_update_post, "m_os_post_dpgraph_update"):
bpy.app.handlers.depsgraph_update_post.append(m_os_post_dpgraph_update)
if not handler_check(bpy.app.handlers.save_pre, "m_os_pre_save"):
bpy.app.handlers.save_pre.append(m_os_pre_save)
if not handler_check(bpy.app.handlers.frame_change_post, "m_os_post_frames_handler"):
bpy.app.handlers.frame_change_post.append(m_os_post_frames_handler)
if not handler_check(bpy.app.handlers.render_pre, "m_os_pre_render_handler"):
bpy.app.handlers.render_pre.append(m_os_pre_render_handler)
if not handler_check(bpy.app.handlers.render_post, "m_os_post_render_handler"):
bpy.app.handlers.render_post.append(m_os_post_render_handler)
if not handler_check(bpy.app.handlers.render_cancel, "m_os_cancel_render_handler"):
bpy.app.handlers.render_cancel.append(m_os_cancel_render_handler)
def OS_Initialization():
params = bpy.context.window_manager.onionSkinsParams
if params.onion_skins_init:
return None
if 'onion_skins_scene_props' not in bpy.context.scene or\
not bpy.context.blend_data.filepath:
apply_pref_settings()
prefs = bpy.context.preferences.addons[__name__].preferences
sc = bpy.context.scene.onion_skins_scene_props
remove_handlers(bpy.context)
global GPU_FRAMES
global GPU_MARKERS
GPU_FRAMES.clear()
GPU_MARKERS.clear()
check_handlers()
if prefs.display_progress:
params.display_progress = True
shading = bpy.context.space_data.shading
if shading.color_type != 'MATERIAL' and shading.color_type != 'TEXTURE' and \
shading.color_type != 'OBJECT':
params.color_type = 'MATERIAL'
if shading.color_type == 'MATERIAL':
params.color_type = 'MATERIAL'
if shading.color_type == 'TEXTURE':
params.color_type = 'TEXTURE'
if shading.color_type == 'OBJECT':
params.color_type = 'OBJECT'
load_os_list_settings()
item_ob = get_active_index_obj(bpy.context)
if item_ob:
params.active_obj_index_list_name = item_ob.name
params.onion_skins_init = True
def poll_check(context):
if not context.active_object:
return False
if context.mode != 'OBJECT' and\
context.mode != 'POSE' and\
context.mode != 'SCULPT':
return False
if not hasattr(context.active_object, 'type'):
return False
if context.active_object.type == 'MESH' or\
context.active_object.type == 'ARMATURE':
return True
return False
def check_draw_gpu_toggle(scene):
global Active_Object
if Active_Object != bpy.context.active_object:
sc = scene.onion_skins_scene_props
global DRAW_TOGGLE
if sc.draw_gpu_toggle:
DRAW_TOGGLE = True
else:
DRAW_TOGGLE = False
else:
return None
if poll_check(bpy.context):
Active_Object = bpy.context.active_object
else:
return None
if not hasattr(Active_Object, 'is_onionsk') and\
not hasattr(Active_Object, 'is_os_marker'):
return None
if Active_Object.is_onionsk or Active_Object.is_os_marker:
if sc.onionsk_tmarker:
sc.onionsk_tmarker = False
sc.onionsk_tmarker = True
remove_handlers(bpy.context)
if DRAW_TOGGLE and sc.os_draw_mode == 'GPU':
sc.draw_gpu_toggle = True
class OS_PT_UI_Panel(Panel):
bl_label = "Mesh Onion Skins"
bl_space_type = 'VIEW_3D'
bl_region_type = "UI"
bl_category = "Animation"
def __init__(self):
OS_Initialization()
@classmethod
def poll(self, context):
return poll_check(context)
def draw(self, context):
layout = self.layout
params = bpy.context.window_manager.onionSkinsParams
obj = context.active_object
sc = bpy.context.scene.onion_skins_scene_props
Skins = sc.onionsk_Skins_count
onionsk = obj.is_onionsk
actions = actions_check(obj)
mp = obj.animation_visualization.motion_path
if context.mode == 'POSE':
mp = obj.pose.animation_visualization.motion_path
if not actions:
return None
row = layout.row(align=True)
row.prop(sc, 'os_draw_mode', text='')
row.operator('mos_op.show_pref_settings', text='', icon='PREFERENCES')
row = layout.row(align=True)
row.scale_y = 1.2
if sc.onionsk_mpath:
row.operator('mos_op.update_motion_path', text='', icon='IPO_ELASTIC')
if sc.onionsk_mpath and mp.has_motion_paths:
row.operator('mos_op.clear_motion_path', text='', icon='X')
if not onionsk:
row.operator('mos_op.make_skins', text='Create ', icon='ONIONSKIN_ON')
if sc.os_draw_mode == 'MESH':
row.prop(params, 'display_progress', text='', icon='TEMP')
if (sc.onionsk_Markers_count > 0 and obj.is_os_marker) and\
sc.os_draw_mode == 'GPU':
row.prop(sc, 'draw_gpu_toggle', text='', icon='RENDER_ANIMATION')
else:
row.operator('mos_op.make_skins', text='Update ', icon='ONIONSKIN_ON')
if sc.os_draw_mode == 'GPU':
row.prop(sc, 'draw_gpu_toggle', text='', icon='RENDER_ANIMATION')
else:
row.prop(params, 'display_progress', text='', icon='TEMP')
if Skins:
row.operator('mos_op.remove_skins', text='', icon='X')
row = layout.row(align=True)
row.operator('mos_op.add_marker', icon='ADD')
if (sc.onionsk_Markers_count > 0 and obj.is_os_marker is True):
row.operator('mos_wm.delete_selected_markers', text='', icon='LONGDISPLAY')
row.operator('mos_op.remove_marker', text='', icon='X')
class OS_PT_Frames_Panel(Panel):
bl_label = "Frames"
bl_space_type = 'VIEW_3D'
bl_region_type = "UI"
bl_parent_id = "OS_PT_UI_Panel"
@classmethod
def poll(self, context):
if poll_check(context):
if actions_check(context.active_object):
return True
return False
def draw(self, context):
obj = context.active_object
sc = bpy.context.scene.onion_skins_scene_props
actions = actions_check(obj)
if not actions:
return {'FINISHED'}
layout = self.layout
row = layout.row()
row.prop(sc, "onionsk_method", text="Method")
if sc.onionsk_method == 'FRAME':
col = layout.column(align=True)
split = layout.split()
row = layout.row()
row = split.row(align=True)
row.prop(sc, "onionsk_fr_before", text="Before")
row.prop(sc, "onionsk_fr_after", text="After")
row.prop(sc, "onionsk_frame_step", text="Step")
if sc.onionsk_method == 'KEYFRAME':
row = layout.row()
row.prop(sc, "use_all_keyframes")
col = layout.column(align=True)
split = layout.split()
row = layout.row()
row = split.row(align=True)
row.enabled = not sc.use_all_keyframes
row.prop(sc, "onionsk_kfr_before", text="Before")
row.prop(sc, "onionsk_kfr_after", text="After")
if sc.onionsk_method == 'SCENE':
row = layout.row()
row.prop(sc, "onionsk_fr_sc", toggle=True)
# text="Playback range (" + str(bpy.context.scene.frame_start) + "-" + str(bpy.context.scene.frame_end) + ")"
row.prop(sc, "onionsk_action_range", toggle=True)
col = layout.column(align=True)
split = layout.split()
row = layout.row()
if sc.onionsk_fr_sc or sc.onionsk_action_range:
row = split.row(align=True)
row.prop(sc, "onionsk_skip", text="Frame Step")
else:
row = split.row(align=True)
row.prop(sc, "onionsk_fr_start", text="Start")
row.prop(sc, "onionsk_fr_end", text="End")
row.prop(sc, "onionsk_skip", text="Step")
class OS_PT_Options_Panel(Panel):
bl_label = "Options"
bl_space_type = 'VIEW_3D'
bl_region_type = "UI"
bl_parent_id = "OS_PT_UI_Panel"
bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(self, context):
if poll_check(context):
if actions_check(context.active_object):
return True
return False
def draw(self, context):
layout = self.layout
params = bpy.context.window_manager.onionSkinsParams
obj = context.active_object
sc = bpy.context.scene.onion_skins_scene_props
actions = actions_check(obj)
if not actions:
return {'FINISHED'}
box = layout.box()
col = box.column(align=True)
row = box.row()
col.label(text="Onion Skins Settings:")
if sc.os_draw_mode == 'MESH':
row.prop(sc, "show_in_render")
row.prop(sc, "os_selectable")
row = box.row()
row.prop(sc, "onionsk_colors", text="Colors")
row.prop(sc, "onionsk_wire", text="Wireframe")
elif sc.os_draw_mode == 'GPU':
row.prop(sc, "gpu_flat_colors")
row.prop(sc, "gpu_colors_in_front")
row = box.row()
row.prop(sc, "gpu_mask_oskins")
row.prop(sc, "gpu_mask_markers")
row = box.row()
row.prop(sc, "onionsk_tmarker", text="Time Marker")
row.prop(sc, "onionsk_mpath", text="Motion Path")
box = layout.box()
col = box.column(align=True)
col.label(text="Selected Object Properties:")
row = box.row()
if obj.type == 'MESH':
if obj.show_in_front is True and params.mesh_inFront is False:
params.mesh_inFront = True
if obj.show_in_front is False and params.mesh_inFront is True:
params.mesh_inFront = False
if obj.show_wire is True and params.mesh_wire is False:
params.mesh_wire = True
if obj.show_wire is False and params.mesh_wire is True:
params.mesh_wire = False
row.prop(params, "mesh_inFront", text="In Front")
row.prop(params, "mesh_wire", text="Wireframe")
class OS_PT_Colors_Panel(Panel):
bl_label = "Colors"
bl_space_type = 'VIEW_3D'
bl_region_type = "UI"
bl_parent_id = "OS_PT_UI_Panel"
bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(self, context):
if poll_check(context):
return True
return False
def draw(self, context):
layout = self.layout
params = bpy.context.window_manager.onionSkinsParams
obj = context.active_object
sc = bpy.context.scene.onion_skins_scene_props
onionsk = obj.is_onionsk
actions = actions_check(obj)
try:
mat1 = bpy.data.materials[MAT_PREFIX + SUFFIX_before]
mat2 = bpy.data.materials[MAT_PREFIX + SUFFIX_after]
mat3 = bpy.data.materials[MAT_PREFIX + SUFFIX_marker]
except KeyError:
pass
shading = bpy.context.space_data.shading
if params.color_type != 'MATERIAL' and shading.color_type == 'MATERIAL':
params.color_type = 'MATERIAL'
if params.color_type != 'TEXTURE' and shading.color_type == 'TEXTURE':
params.color_type = 'TEXTURE'
if params.color_type != 'OBJECT' and shading.color_type == 'OBJECT':
params.color_type = 'OBJECT'
box = layout.box()
box.grid_flow(columns=3, align=True).prop(params, "color_type", expand=True)
flow = box.grid_flow(row_major=True, columns=2, even_columns=True, even_rows=False, align=True)
col = flow.column(align=True)
col.label(text="Before")
col.prop(sc, 'mat_color_bf', text='') # , text="Before"
col = flow.column(align=True)
col.label(text="After")
col.prop(sc, 'mat_color_af', text='') # , text="After"
col = flow.column(align=True)
col.label(text="Marker")
col.prop(sc, 'mat_color_m', text='')
col = flow.column(align=True)
col.prop(bpy.context.space_data.shading, "show_object_outline", text="Outline")
col.prop(bpy.context.space_data.shading, "object_outline_color", text="")
flow = box.grid_flow(row_major=True, columns=2, even_columns=True, even_rows=False, align=True)
col = flow.column(align=True)
col.prop(sc, 'color_alpha', text='Alpha', toggle=True)
col.prop(sc, 'color_alpha_value', text='')
col = flow.column(align=True)
col.prop(sc, 'fade_to_alpha', text='Fade', toggle=True)
col.prop(sc, 'fade_to_value', text='')
class OS_PT_Selection_Panel(Panel):
bl_label = "Selection"
bl_space_type = 'VIEW_3D'
bl_region_type = "UI"
bl_parent_id = "OS_PT_UI_Panel"
# bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(self, context):
if poll_check(context):
set_object_data_collection_items()
return True
return False
def draw(self, context):
layout = self.layout
params = bpy.context.window_manager.onionSkinsParams
# obj = bpy.context.selected_objects[0]
obj = context.active_object
sc = bpy.context.scene.onion_skins_scene_props
Skins = sc.onionsk_Skins_count
onionsk = obj.is_onionsk
actions = actions_check(obj)
box = layout.box()
row = box.row(align=True)
row.prop(sc, "selection_sets", expand=True)
col = box.column().split()
col.label(icon='RESTRICT_SELECT_OFF', text="Selected: " + str(obj.type) + ": " + str(obj.name))
if sc.selection_sets == "COLLECTION":
row = box.row(align=True)
row.prop(sc, "show_parent_users_collection", text='', icon='FILE_PARENT')
row.prop(params, "active_obj_users_collection", text='', expand=False)
if obj.type == 'ARMATURE' and sc.selection_sets == "PARENT":
col = box.column().split()
obj_child = len(get_selected_os_set_childrens())
if obj_child > 0:
col.label(icon='LINKED', text="Parented: " + str(obj_child) + " skinnable meshes")
else:
col.label(icon='UNLINKED', text="Parented: None of skinnable meshes")
elif sc.selection_sets == "PARENT":
col = box.column().split()
if obj.parent:
col.label(icon='LINKED', text="Parent: " + str(obj.parent.type) + ": " + str(obj.parent.name))
else:
col.label(icon='UNLINKED', text="Parent: None")
wm = bpy.context.window_manager
row = box.row()
row.template_list("OBJECT_UL_Childrens", "", wm, "os_childrens_collection", wm, "active_os_object_list")
col = row.column()
col.menu("WM_MT_List_ops_menu", icon='DOWNARROW_HLT', text="")
col.operator("wm.os_update_childrens_list", text='', icon='FILE_REFRESH')
col.operator("wm.os_uncheck_all_children_list", text='', icon='CHECKBOX_DEHLT')
col.operator("wm.os_check_all_children_list", text='', icon='CHECKMARK') # CHECKBOX_HLT
row = box.row()
row.prop(params, "highlight_active_os_object_list", toggle=True)
box = layout.box()
if not actions:
col = box.column().split()
col.label(icon="CANCEL", text="Not Animated")
else:
col = box.column().split()
col.label(icon='FCURVE', text="Is Animated")
if actions and not onionsk:
col.label(icon="X", text="Not Using")
if actions and onionsk:
col.label(icon='ONIONSKIN_ON', text="Using Skins")
box = layout.box()
row = box.row(align=True)
try:
row.label(icon="NONE", text="Onion Objects: " + str(Skins))
row.label(icon="NONE", text="Marker Objects: " + str(sc.onionsk_Markers_count))
except AttributeError:
pass
class OBJECT_UL_Childrens(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
if self.layout_type in {'DEFAULT', 'COMPACT'}:
if item:
layout.prop(item, "name", text="", emboss=False)
if item.flag:
layout.prop(item, "flag", text="", emboss=False, icon='CHECKBOX_HLT')
else:
layout.prop(item, "flag", text="", emboss=False, icon='CHECKBOX_DEHLT')
else:
layout.label(text="", translate=False)
elif self.layout_type in {'GRID'}:
layout.alignment = 'CENTER'
layout.label(text="") # icon_value=icon