-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
ui.py
6230 lines (5081 loc) · 257 KB
/
ui.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
import bpy, re, time, os
from bpy.props import *
from bpy.app.handlers import persistent
from bpy.app.translations import pgettext_iface
from . import lib, Modifier, MaskModifier, UDIM
from .common import *
RGBA_CHANNEL_PREFIX = {
'ALPHA' : 'alpha_',
'R' : 'r_',
'G' : 'g_',
'B' : 'b_',
}
def update_yp_ui():
# Get active yp node
node = get_active_ypaint_node()
if not node or node.type != 'GROUP': return
tree = node.node_tree
yp = tree.yp
ypui = bpy.context.window_manager.ypui
# Check layer channel ui consistency
if len(yp.layers) > 0:
if len(ypui.layer_ui.channels) != len(yp.channels):
ypui.need_update = True
# Update UI
if (ypui.tree_name != tree.name or
ypui.layer_idx != yp.active_layer_index or
ypui.channel_idx != yp.active_channel_index or
ypui.bake_target_idx != yp.active_bake_target_index or
ypui.need_update
):
ypui.tree_name = tree.name
ypui.layer_idx = yp.active_layer_index
ypui.channel_idx = yp.active_channel_index
ypui.bake_target_idx = yp.active_bake_target_index
ypui.need_update = False
ypui.halt_prop_update = True
if len(yp.bake_targets) > 0:
bt = yp.bake_targets[yp.active_bake_target_index]
ypui.bake_target_ui.expand_content = bt.expand_content
ypui.bake_target_ui.expand_r = bt.expand_r
ypui.bake_target_ui.expand_g = bt.expand_g
ypui.bake_target_ui.expand_b = bt.expand_b
ypui.bake_target_ui.expand_a = bt.expand_a
if len(yp.channels) > 0:
# Get channel
channel = yp.channels[yp.active_channel_index]
ypui.channel_ui.expand_content = channel.expand_content
ypui.channel_ui.expand_base_vector = channel.expand_base_vector
ypui.channel_ui.expand_subdiv_settings = channel.expand_subdiv_settings
ypui.channel_ui.expand_parallax_settings = channel.expand_parallax_settings
ypui.channel_ui.expand_alpha_settings = channel.expand_alpha_settings
ypui.channel_ui.expand_bake_to_vcol_settings = channel.expand_bake_to_vcol_settings
ypui.channel_ui.expand_input_bump_settings = channel.expand_input_bump_settings
ypui.channel_ui.expand_smooth_bump_settings = channel.expand_smooth_bump_settings
ypui.channel_ui.modifiers.clear()
# Construct channel UI objects
for i, mod in enumerate(channel.modifiers):
m = ypui.channel_ui.modifiers.add()
m.expand_content = mod.expand_content
if len(yp.layers) > 0:
# Get layer
layer = yp.layers[yp.active_layer_index]
ypui.layer_ui.expand_content = layer.expand_content
ypui.layer_ui.expand_vector = layer.expand_vector
ypui.layer_ui.expand_source = layer.expand_source
ypui.layer_ui.expand_masks = layer.expand_masks
ypui.layer_ui.expand_channels = layer.expand_channels
ypui.layer_ui.channels.clear()
ypui.layer_ui.masks.clear()
ypui.layer_ui.modifiers.clear()
# Construct layer modifier UI objects
for mod in layer.modifiers:
m = ypui.layer_ui.modifiers.add()
m.expand_content = mod.expand_content
# Construct layer channel UI objects
for i, ch in enumerate(layer.channels):
c = ypui.layer_ui.channels.add()
c.expand_bump_settings = ch.expand_bump_settings
c.expand_intensity_settings = ch.expand_intensity_settings
c.expand_transition_bump_settings = ch.expand_transition_bump_settings
c.expand_transition_ramp_settings = ch.expand_transition_ramp_settings
c.expand_transition_ao_settings = ch.expand_transition_ao_settings
c.expand_input_settings = ch.expand_input_settings
c.expand_source = ch.expand_source
c.expand_source_1 = ch.expand_source_1
c.expand_content = ch.expand_content
for mod in ch.modifiers:
m = c.modifiers.add()
m.expand_content = mod.expand_content
for mod in ch.modifiers_1:
m = c.modifiers_1.add()
m.expand_content = mod.expand_content
# Construct layer masks UI objects
for i, mask in enumerate(layer.masks):
m = ypui.layer_ui.masks.add()
m.expand_content = mask.expand_content
m.expand_channels = mask.expand_channels
m.expand_source = mask.expand_source
m.expand_vector = mask.expand_vector
for mch in mask.channels:
mc = m.channels.add()
mc.expand_content = mch.expand_content
for mod in mask.modifiers:
mm = m.modifiers.add()
mm.expand_content = mod.expand_content
ypui.halt_prop_update = False
def draw_bake_info(bake_info, layout, entity):
yp = entity.id_data.yp
bi = bake_info
if len(bi.other_objects) > 0:
layout.label(text='List of Objects:')
box = layout.box()
bcol = box.column()
for oo in bi.other_objects:
brow = bcol.row()
brow.context_pointer_set('other_object', oo)
brow.context_pointer_set('bake_info', bi)
if is_bl_newer_than(2, 79):
brow.label(text=oo.object.name, icon_value=lib.get_icon('object_index'))
else: brow.label(text=oo.object_name, icon_value=lib.get_icon('object_index'))
brow.operator('node.y_remove_bake_info_other_object', text='', icon_value=lib.get_icon('close'))
m1 = re.match(r'^yp\.layers\[(\d+)\]$', entity.path_from_id())
m2 = re.match(r'^yp\.layers\[(\d+)\]\.masks\[(\d+)\]$', entity.path_from_id())
m3 = re.match(r'^yp\.layers\[(\d+)\]\.channels\[(\d+)\]$', entity.path_from_id())
if m3:
layer = yp.layers[int(m3.group(1))]
layout.context_pointer_set('entity', layer)
else: layout.context_pointer_set('entity', entity)
layout.context_pointer_set('bake_info', bi)
if bi.bake_type == 'SELECTED_VERTICES':
c = layout.operator("node.y_try_to_select_baked_vertex", text='Try to Reselect Vertices', icon='GROUP_VERTEX')
c = layout.operator("node.y_bake_to_layer", text='Rebake', icon_value=lib.get_icon('bake'))
c.type = bi.bake_type
if m1 or m3: c.target_type = 'LAYER'
else: c.target_type = 'MASK'
c.overwrite_current = True
def draw_image_props(context, source, layout, entity=None, show_flip_y=False):
image = source.image
col = layout.column()
unlink_op = 'node.y_remove_layer'
if entity:
yp = entity.id_data.yp
m1 = re.match(r'^yp\.layers\[(\d+)\]\.masks\[(\d+)\]$', entity.path_from_id())
m2 = re.match(r'^yp\.layers\[(\d+)\]\.channels\[(\d+)\]$', entity.path_from_id())
if m1:
layer = yp.layers[int(m1.group(1))]
col.context_pointer_set('layer', layer)
col.context_pointer_set('mask', entity)
unlink_op = 'node.y_remove_layer_mask'
elif m2:
layer = yp.layers[int(m2.group(1))]
col.context_pointer_set('layer', layer)
col.context_pointer_set('channel', entity)
if show_flip_y:
unlink_op = 'node.y_remove_channel_override_1_source'
else: unlink_op = 'node.y_remove_channel_override_source'
if image.y_bake_info.is_baked and not image.y_bake_info.is_baked_channel:
bi = image.y_bake_info
if image.yia.is_image_atlas or image.yua.is_udim_atlas:
col.label(text=image.name + ' (Baked)', icon_value=lib.get_icon('image'))
else: col.template_ID(source, "image", unlink=unlink_op)
col.label(text='Type: ' + bake_type_labels[bi.bake_type], icon_value=lib.get_icon('bake'))
draw_bake_info(bi, col, entity)
return
if image.yia.is_image_atlas or image.yua.is_udim_atlas:
if image.yia.is_image_atlas:
segment = image.yia.segments.get(entity.segment_name)
else: segment = image.yua.segments.get(entity.segment_name)
if segment and segment.bake_info.is_baked:
bi = segment.bake_info
col.label(text=image.name + ' (Baked)', icon_value=lib.get_icon('image'))
col.label(text='Type: ' + bake_type_labels[bi.bake_type], icon_value=lib.get_icon('bake'))
else: col.label(text=image.name, icon_value=lib.get_icon('image'))
if segment:
if image.yia.is_image_atlas:
row = col.row()
row.label(text='Tile X: ' + str(segment.tile_x))
row.label(text='Tile Y: ' + str(segment.tile_y))
row = col.row()
row.label(text='Width: ' + str(segment.width))
row.label(text='Height: ' + str(segment.height))
else:
split = split_layout(col, 0.4)
split.label(text='Tile Numbers: ')
row = split.row(align=True)
segment_tilenums = UDIM.get_udim_segment_tilenums(segment)
for tilenum in segment_tilenums:
row.label(text=str(tilenum))
if segment.bake_info.is_baked:
draw_bake_info(segment.bake_info, col, entity)
split = split_layout(col, 0.4)
scol = split.column()
scol.label(text='Interpolation:')
scol = split.column()
scol.prop(source, 'interpolation', text='')
return
col.template_ID(source, "image", unlink=unlink_op)
if image.source == 'GENERATED':
col.label(text='Generated image settings:')
row = col.row()
col1 = row.column(align=True)
col1.prop(image, 'generated_width', text='X')
col1.prop(image, 'generated_height', text='Y')
col1.prop(image, 'use_generated_float', text='Float Buffer')
col2 = row.column(align=True)
col2.prop(image, 'generated_type', expand=True)
row = col.row()
row.label(text='Color:')
row.prop(image, 'generated_color', text='')
elif image.source == 'FILE':
if not image.filepath:
col.label(text='Image Path: -')
else:
col.label(text='Path: ' + image.filepath)
image_format = 'RGBA'
image_bit = int(image.depth / 4)
if image.depth in {24, 48, 96}:
image_format = 'RGB'
image_bit = int(image.depth / 3)
col.label(
text='Info: ' + str(image.size[0]) + ' x ' + str(image.size[1]) +
' ' + image_format + ' ' + str(image_bit) + '-bit'
)
split = split_layout(col, 0.4)
scol = split.column()
if not image.is_dirty:
scol.label(text='Color Space:')
if hasattr(image, 'use_alpha'):
scol.label(text='Use Alpha:')
scol.label(text='Alpha Mode:')
scol.label(text='Interpolation:')
scol.label(text='Extension:')
#scol.label(text='Projection:')
#if source.projection == 'BOX':
# scol.label(text='Blend:')
scol = split.column()
if not image.is_dirty:
scol.prop(image.colorspace_settings, "name", text='')
if hasattr(image, 'use_alpha'):
scol.prop(image, 'use_alpha', text='')
scol.prop(image, 'alpha_mode', text='')
scol.prop(source, 'interpolation', text='')
scol.prop(source, 'extension', text='')
#scol.prop(source, 'projection', text='')
#if source.projection == 'BOX':
# scol.prop(entity, 'projection_blend', text='')
if entity and hasattr(entity, 'image_flip_y') and show_flip_y:
row = col.row(align=True)
row.label(text='Flip G:')
row.prop(entity, 'image_flip_y', text='')
def draw_object_index_props(entity, layout):
col = layout.column()
col.prop(entity, 'object_index')
def draw_hemi_props(entity, source, layout):
col = layout.column()
col.prop(entity, 'hemi_space', text='Space')
col.label(text='Light Direction:')
# Get light direction
norm = source.node_tree.nodes.get('Normal')
col.prop(norm.outputs[0], 'default_value', text='')
col.prop(entity, 'hemi_use_prev_normal', text='Use Previous Normal')
col.prop(entity, 'hemi_camera_ray_mask', text='Camera Ray Mask')
def draw_vcol_props(layout, vcol=None, entity=None):
if hasattr(entity, 'divide_rgb_by_alpha'):
row = layout.row(align=True)
row.label(text='Divide RGB by Alpha:')
row.prop(entity, 'divide_rgb_by_alpha', text='')
else:
layout.label(text='You can also edit vertex color in edit mode')
def is_input_skipped(inp):
if is_bl_newer_than(2, 81):
return inp.name == 'Vector' or not inp.enabled
return inp.name == 'Vector'
def draw_tex_props(source, layout, entity=None):
title = source.bl_idname.replace('ShaderNodeTex', '')
col = layout.column()
#col.label(text=title + ' Properties:')
#col.separator()
if title == 'Brick':
separator_needed = {'Mortar'}
row = col.row()
col = row.column(align=True)
col.label(text='Offset:')
col.label(text='Frequency:')
col.separator()
col.label(text='Squash:')
col.label(text='Frequency:')
col.separator()
for inp in source.inputs:
if is_input_skipped(inp): continue
col.label(text=inp.name + ':')
if inp.name in separator_needed:
col.separator()
col = row.column(align=True)
col.prop(source, 'offset', text='')
col.prop(source, 'offset_frequency', text='')
col.separator()
col.prop(source, 'squash', text='')
col.prop(source, 'squash_frequency', text='')
col.separator()
for inp in source.inputs:
if is_input_skipped(inp): continue
col.prop(inp, 'default_value', text='')
if inp.name in separator_needed:
col.separator()
elif title == 'Checker':
separator_needed = {'Color2'}
row = col.row()
col = row.column(align=True)
for inp in source.inputs:
if is_input_skipped(inp): continue
col.label(text=inp.name + ':')
if inp.name in separator_needed:
col.separator()
col = row.column(align=True)
for inp in source.inputs:
if is_input_skipped(inp): continue
col.prop(inp, 'default_value', text='')
if inp.name in separator_needed:
col.separator()
elif title == 'Gradient':
row = col.row()
col = row.column(align=True)
col.label(text='Type:')
col = row.column(align=True)
col.prop(source, 'gradient_type', text='')
elif title == 'Magic':
row = col.row()
col = row.column(align=True)
col.label(text='Depth:')
for inp in source.inputs:
if is_input_skipped(inp): continue
col.label(text=inp.name + ':')
col = row.column(align=True)
col.prop(source, 'turbulence_depth', text='')
for inp in source.inputs:
if is_input_skipped(inp): continue
col.prop(inp, 'default_value', text='')
elif title == 'Musgrave':
row = col.row()
col = row.column(align=True)
if is_bl_newer_than(2, 81):
col.label(text='Dimensions:')
col.label(text='Type:')
col.separator()
for inp in source.inputs:
if is_input_skipped(inp): continue
col.label(text=inp.name + ':')
col = row.column(align=True)
if is_bl_newer_than(2, 81):
col.prop(source, 'musgrave_dimensions', text='')
col.prop(source, 'musgrave_type', text='')
col.separator()
for inp in source.inputs:
if is_input_skipped(inp): continue
col.prop(inp, 'default_value', text='')
elif title == 'Noise':
row = col.row()
col = row.column(align=True)
if is_bl_newer_than(2, 81):
col.label(text='Dimensions:')
if hasattr(source, 'noise_type'):
col.label(text='Type:')
if is_bl_newer_than(4):
col.label(text='Normalize:')
else:
col.separator()
for inp in source.inputs:
if is_input_skipped(inp): continue
col.label(text=inp.name + ':')
col = row.column(align=True)
if is_bl_newer_than(2, 81):
col.prop(source, 'noise_dimensions', text='')
if hasattr(source, 'noise_type'):
col.prop(source, 'noise_type', text='')
if is_bl_newer_than(4):
col.prop(source, 'normalize', text='')
else:
col.separator()
for inp in source.inputs:
if is_input_skipped(inp): continue
col.prop(inp, 'default_value', text='')
elif title == 'Gabor':
row = col.row()
col = row.column(align=True)
col.label(text='Gabor Type:')
for inp in source.inputs:
if is_input_skipped(inp): continue
col.label(text=inp.name + ':')
col = row.column(align=True)
col.prop(source, 'gabor_type', text='')
for inp in source.inputs:
if is_input_skipped(inp): continue
col.prop(inp, 'default_value', text='')
elif title == 'Voronoi':
row = col.row()
col = row.column(align=True)
if is_bl_newer_than(2, 81):
col.label(text='Dimensions:')
else: col.label(text='Coloring:')
if is_bl_newer_than(2, 80):
col.label(text='Feature:')
if source.feature not in {'DISTANCE_TO_EDGE', 'N_SPHERE_RADIUS'}:
col.label(text='Distance:')
if is_bl_newer_than(4) and source.feature != 'N_SPHERE_RADIUS':
col.label(text='Normalize:')
else:
col.separator()
for inp in source.inputs:
if is_input_skipped(inp): continue
col.label(text=inp.name + ':')
col = row.column(align=True)
if is_bl_newer_than(2, 81):
col.prop(source, 'voronoi_dimensions', text='')
else: col.prop(source, 'coloring', text='')
if is_bl_newer_than(2, 80):
if entity and is_bl_newer_than(2, 81):
col.prop(entity, 'voronoi_feature', text='')
else: col.prop(source, 'feature', text='')
if source.feature not in {'DISTANCE_TO_EDGE', 'N_SPHERE_RADIUS'}:
col.prop(source, 'distance', text='')
if is_bl_newer_than(4) and source.feature not in {'N_SPHERE_RADIUS'}:
col.prop(source, 'normalize', text='')
else:
col.separator()
for inp in source.inputs:
if is_input_skipped(inp): continue
col.prop(inp, 'default_value', text='')
elif title == 'Wave':
row = col.row()
col = row.column(align=True)
col.label(text='Type:')
if hasattr(source, 'bands_direction'):
col.label(text='Band Direction:')
col.label(text='Profile:')
col.separator()
for inp in source.inputs:
if is_input_skipped(inp): continue
col.label(text=inp.name + ':')
col = row.column(align=True)
col.prop(source, 'wave_type', text='')
if hasattr(source, 'bands_direction'):
col.prop(source, 'bands_direction', text='')
if hasattr(source, 'wave_profile'):
col.prop(source, 'wave_profile', text='')
col.separator()
for inp in source.inputs:
if is_input_skipped(inp): continue
col.prop(inp, 'default_value', text='')
def draw_colorid_props(layer, source, layout):
col = layout.column()
row = col.row()
row.label(text='Color ID:')
draw_input_prop(row, layer, 'color_id')
def draw_solid_color_props(layer, source, layout):
col = layout.column()
row = col.row()
row.label(text='Color:')
row.prop(source.outputs[0], 'default_value', text='')
def draw_edge_detect_props(layer, source, layout):
col = layout.column()
row = col.row()
row.label(text='Radius:')
draw_input_prop(row, layer, 'edge_detect_radius')
def draw_inbetween_modifier_mask_props(layer, source, layout):
col = layout.column()
if layer.modifier_type == 'CURVE':
source.draw_buttons_ext(bpy.context, col)
elif layer.modifier_type == 'RAMP':
col.template_color_ramp(source, "color_ramp", expand=True)
def draw_input_prop(layout, entity, prop_name, emboss=None, text=''):
inp = get_entity_prop_input(entity, prop_name)
if emboss != None:
if inp: layout.prop(inp, 'default_value', text=text, emboss=emboss)
else: layout.prop(entity, prop_name, text=text, emboss=emboss)
else:
if inp: layout.prop(inp, 'default_value', text=text)
else: layout.prop(entity, prop_name, text=text)
def draw_mask_modifier_stack(layer, mask, layout, ui):
ypui = bpy.context.window_manager.ypui
tree = get_mask_tree(mask)
for i, m in enumerate(mask.modifiers):
try: modui = ui.modifiers[i]
except:
ypui.need_update = True
return
can_be_expanded = m.type in MaskModifier.can_be_expanded
row = layout.row(align=True)
if can_be_expanded:
if modui.expand_content:
icon_value = lib.get_icon('uncollapsed_modifier')
else: icon_value = lib.get_icon('collapsed_modifier')
row.prop(modui, 'expand_content', text='', emboss=False, icon_value=icon_value)
else:
row.label(text='', icon_value=lib.get_icon('modifier'))
row.label(text=m.name)
row.context_pointer_set('layer', layer)
row.context_pointer_set('mask', mask)
row.context_pointer_set('modifier', m)
icon = 'PREFERENCES' if is_bl_newer_than(2, 80) else 'SCRIPTWIN'
row.menu("NODE_MT_y_mask_modifier_menu", text='', icon=icon)
row.prop(m, 'enable', text='')
if modui.expand_content and can_be_expanded:
row = layout.row(align=True)
row.label(text='', icon='BLANK1')
box = row.box()
box.active = m.enable
MaskModifier.draw_modifier_properties(tree, m, box)
def draw_modifier_stack(context, parent, channel_type, layout, ui, layer=None, extra_blank=False, use_modifier_1=False, layout_active=True):
ypui = context.window_manager.ypui
modifiers = parent.modifiers
if use_modifier_1:
modifiers = parent.modifiers_1
# Check if parent is layer channel
match = re.match(r'yp\.layers\[(\d+)\]\.channels\[(\d+)\]', parent.path_from_id())
if match:
yp = parent.id_data.yp
layer = yp.layers[int(match.group(1))]
root_ch = yp.channels[int(match.group(2))]
ch = layer.channels[int(match.group(2))]
for i, m in enumerate(modifiers):
try:
if use_modifier_1:
modui = ui.modifiers_1[i]
else: modui = ui.modifiers[i]
except:
ypui.need_update = True
return
mod_tree = get_mod_tree(m)
can_be_expanded = m.type in Modifier.can_be_expanded
row = layout.row(align=True)
row.active = layout_active
if can_be_expanded:
if modui.expand_content:
icon_value = lib.get_icon('uncollapsed_modifier')
else: icon_value = lib.get_icon('collapsed_modifier')
row.prop(modui, 'expand_content', text='', emboss=False, icon_value=icon_value)
else:
row.label(text='', icon_value=lib.get_icon('modifier'))
label = m.name
# If parent is layer channel
if match:
if root_ch.type == 'NORMAL' and ch.normal_map_type == 'BUMP_NORMAL_MAP':
if use_modifier_1:
label += ' (Normal)'
else: label += ' (Bump)'
#if m.type == 'MATH' and not modui.expand_content:
# method_name = [mt[1] for mt in math_method_items if mt[0] == m.math_meth][0]
# label += ' (' + method_name + ')'
row.label(text=label)
if not modui.expand_content:
if m.type == 'RGB_TO_INTENSITY':
row.prop(m, 'rgb2i_col', text='', icon='COLOR')
row.separator()
#if m.type == 'INVERT':
# if channel_type == 'VALUE':
# row.prop(m, 'invert_r_enable', text='Value', toggle=True)
# row.prop(m, 'invert_a_enable', text='Alpha', toggle=True)
# else:
# row.prop(m, 'invert_r_enable', text='R', toggle=True)
# row.prop(m, 'invert_g_enable', text='G', toggle=True)
# row.prop(m, 'invert_b_enable', text='B', toggle=True)
# row.prop(m, 'invert_a_enable', text='A', toggle=True)
# row.separator()
#if m.type == 'MATH':
# row.prop(m, 'math_r_val', text='')
# if channel_type != 'VALUE':
# row.prop(m, 'math_g_val', text='')
# row.prop(m, 'math_b_val', text='')
# if m.affect_alpha :
# row.prop(m, 'math_a_val', text='')
# row.separator()
if m.type == 'OVERRIDE_COLOR': # and not m.oc_use_normal_base:
if channel_type == 'VALUE':
row.prop(m, 'oc_val', text='')
else:
row.prop(m, 'oc_col', text='', icon='COLOR')
row.separator()
row.context_pointer_set('layer', layer)
row.context_pointer_set('parent', parent)
row.context_pointer_set('modifier', m)
if use_modifier_1:
icon = 'PREFERENCES' if is_bl_newer_than(2, 80) else 'SCRIPTWIN'
row.menu("NODE_MT_y_modifier1_menu", text='', icon=icon)
else:
icon = 'PREFERENCES' if is_bl_newer_than(2, 80) else 'SCRIPTWIN'
row.menu("NODE_MT_y_modifier_menu", text='', icon=icon)
row.prop(m, 'enable', text='')
if modui.expand_content and can_be_expanded:
row = layout.row(align=True)
row.active = layout_active
#row.label(text='', icon='BLANK1')
row.label(text='', icon='BLANK1')
box = row.box()
box.active = m.enable
Modifier.draw_modifier_properties(bpy.context, channel_type, mod_tree.nodes, m, box, False)
#row.label(text='', icon='BLANK1')
def draw_bake_target_channel(context, layout, bt, letter='r'):
yp = bt.id_data.yp
ypui = context.window_manager.ypui
btui = ypui.bake_target_ui
btc = getattr(bt, letter)
ch = yp.channels.get(btc.channel_name) if btc.channel_name != '' else None
row = layout.row(align=True)
if ch:
icon_name = letter
if getattr(btui, 'expand_' + letter):
icon_name = 'uncollapsed_' + icon_name
else: icon_name = 'collapsed_' + icon_name
icon_value = lib.get_icon(icon_name)
row.prop(btui, 'expand_' + letter, text='', emboss=False, icon_value=icon_value)
else:
row.label(text='', icon_value=lib.get_icon(letter))
if btc.channel_name == '':
split = split_layout(row, 0.65, align=True)
split.prop_search(btc, "channel_name", yp, "channels", text='')
split.prop(btc, 'default_value', text='')
else:
if ch and (ch.type == 'RGB' or (ch.type == 'NORMAL' and btc.normal_type != 'DISPLACEMENT')):
split = split_layout(row, 0.75, align=True)
split.prop_search(btc, "channel_name", yp, "channels", text='')
split.prop(btc, 'subchannel_index', text='')
else:
row.prop_search(btc, "channel_name", yp, "channels", text='')
if ch and getattr(btui, 'expand_' + letter):
row = layout.row(align=True)
row.label(text='', icon='BLANK1')
box = row.box()
bcol = box.column()
if ch.type == 'NORMAL':
brow = split_layout(bcol, 0.3, align=True)
brow.label(text='Source:')
brow.prop(btc, 'normal_type', text='')
brow = bcol.row(align=True)
brow.label(text='Invert Value:')
brow.prop(btc, 'invert_value', text='')
def draw_bake_targets_ui(context, layout, node):
group_tree = node.node_tree
nodes = group_tree.nodes
yp = group_tree.yp
ypui = context.window_manager.ypui
btui = ypui.bake_target_ui
box = layout.box()
col = box.column()
row = col.row()
rcol = row.column()
rcol.template_list(
"NODE_UL_YPaint_bake_targets", "", yp, "bake_targets", yp,
"active_bake_target_index", rows=2, maxrows=5
)
rcol = row.column(align=True)
#rcol.context_pointer_set('node', node)
if is_bl_newer_than(2, 80):
rcol.operator("node.y_new_bake_target", icon='ADD', text='')
rcol.operator("node.y_remove_bake_target", icon='REMOVE', text='')
else:
rcol.operator("node.y_new_bake_target", icon='ZOOMIN', text='')
rcol.operator("node.y_remove_bake_target", icon='ZOOMOUT', text='')
if len(yp.bake_targets) > 0:
bt = yp.bake_targets[yp.active_bake_target_index]
image_node = nodes.get(bt.image_node)
image = image_node.image if image_node and image_node.image else None
icon_name = 'bake'
if btui.expand_content:
icon_name = 'uncollapsed_' + icon_name
else: icon_name = 'collapsed_' + icon_name
icon_value = lib.get_icon(icon_name)
row = col.row(align=True)
row.prop(btui, 'expand_content', text='', emboss=False, icon_value=icon_value)
if image:
bt_label = image.name
if image.is_float: bt_label += ' (Float)'
else:
bt_label = bt.name
if bt.use_float: bt_label += ' (Float)'
row.label(text=bt_label)
if btui.expand_content:
row = col.row(align=True)
row.label(text='', icon='BLANK1')
bcol = row.column()
for letter in rgba_letters:
draw_bake_target_channel(context, bcol, bt, letter)
row = col.row(align=True)
image_name = image.name if image else '-'
row.label(text='Image: ' + image_name, icon_value=lib.get_icon('image'))
icon = 'PREFERENCES' if is_bl_newer_than(2, 80) else 'SCRIPTWIN'
row.context_pointer_set('image', image)
row.menu("NODE_MT_y_bake_target_menu", text='', icon=icon)
if not image:
row = col.row(align=True)
row.label(text="Do 'Bake All Channels' to get the image!", icon='ERROR')
def draw_root_channels_ui(context, layout, node):
scene = bpy.context.scene
obj = bpy.context.object
engine = scene.render.engine
mat = get_active_material()
group_tree = node.node_tree
nodes = group_tree.nodes
yp = group_tree.yp
ypui = context.window_manager.ypui
ypup = get_user_preferences()
box = layout.box()
col = box.column()
row = col.row()
rcol = row.column()
if len(yp.channels) > 0:
pcol = rcol.column()
if yp.preview_mode: pcol.alert = True
if not is_bl_newer_than(2, 80):
pcol.prop(yp, 'preview_mode', text='Preview Mode', icon='RESTRICT_VIEW_OFF')
else: pcol.prop(yp, 'preview_mode', text='Preview Mode', icon='HIDE_OFF')
rcol.template_list("NODE_UL_YPaint_channels", "", yp,
"channels", yp, "active_channel_index", rows=3, maxrows=5)
rcol = row.column(align=True)
#rcol.context_pointer_set('node', node)
if is_bl_newer_than(2, 80):
rcol.menu("NODE_MT_y_new_channel_menu", text='', icon='ADD')
#rcol.operator_menu_enum("node.y_add_new_ypaint_channel", 'type', icon='ADD', text='')
rcol.operator("node.y_remove_ypaint_channel", icon='REMOVE', text='')
else:
rcol.menu("NODE_MT_y_new_channel_menu", text='', icon='ZOOMIN')
#rcol.operator_menu_enum("node.y_add_new_ypaint_channel", 'type', icon='ZOOMIN', text='')
rcol.operator("node.y_remove_ypaint_channel", icon='ZOOMOUT', text='')
rcol.operator("node.y_move_ypaint_channel", text='', icon='TRIA_UP').direction = 'UP'
rcol.operator("node.y_move_ypaint_channel", text='', icon='TRIA_DOWN').direction = 'DOWN'
if len(yp.channels) > 0:
mcol = col.column(align=False)
channel = yp.channels[yp.active_channel_index]
mcol.context_pointer_set('channel', channel)
chui = ypui.channel_ui
# Check if channel output is connected or not
inputs = node.inputs
outputs = node.outputs
output_index = get_output_index(channel)
if group_tree.users == 1:
# Optimize normal process button if normal input is disconnected
root_normal_ch = get_root_height_channel(yp)
if root_normal_ch:
if is_height_input_unconnected_but_has_start_process(node, root_normal_ch):
row = mcol.row(align=True)
row.alert = True
row.operator('node.y_optimize_normal_process', icon='ERROR', text='Fix Height Process')
elif is_height_input_connected_but_has_no_start_process(node, root_normal_ch):
row = mcol.row(align=True)
row.alert = True
row.operator('node.y_optimize_normal_process', icon='ERROR', text='Fix Height Input')
if is_output_unconnected(node, output_index, channel):
row = mcol.row(align=True)
row.alert = True
row.operator('node.y_connect_ypaint_channel', icon='ERROR', text='Fix Unconnected Channel Output')
# Fix for alpha channel missing connection
elif channel.type == 'RGB' and channel.enable_alpha and is_output_unconnected(node, output_index + 1, channel):
row = mcol.row(align=True)
row.alert = True
row.operator('node.y_connect_ypaint_channel_alpha', icon='ERROR', text='Fix Unconnected Alpha Output')
row = mcol.row(align=True)
icon_name = lib.channel_custom_icon_dict[channel.type]
if chui.expand_content:
icon_name = 'uncollapsed_' + icon_name
else: icon_name = 'collapsed_' + icon_name
icon_value = lib.get_icon(icon_name)
row.prop(chui, 'expand_content', text='', emboss=False, icon_value=icon_value)
row.label(text=channel.name + ' ' + pgettext_iface('Channel'))
#if channel.type != 'NORMAL':
row.context_pointer_set('parent', channel)
row.context_pointer_set('channel_ui', chui)
icon = 'PREFERENCES' if is_bl_newer_than(2, 80) else 'SCRIPTWIN'
row.menu("NODE_MT_y_channel_special_menu", icon=icon, text='')
if chui.expand_content:
row = mcol.row(align=True)
row.label(text='', icon='BLANK1')
bcol = row.column()
# Modifier stack ui will only active when use_baked is off
baked = nodes.get(channel.baked)
layout_active = not yp.use_baked or not baked
draw_modifier_stack(context, channel, channel.type, bcol, chui, layout_active=layout_active)
inp = node.inputs[channel.io_index]
if channel.type in {'RGB', 'VALUE'}:
brow = bcol.row(align=True)
brow.label(text='', icon_value=lib.get_icon('input'))
if channel.type == 'RGB':
brow.label(text='Background:')
elif channel.type == 'VALUE':
brow.label(text='Base Value:')
if not yp.use_baked or (channel.no_layer_using and len(inp.links) == 0):
brow.prop(inp,'default_value', text='')
if yp.use_baked and not channel.no_layer_using:
brow.label(text='', icon_value=lib.get_icon('texture'))
elif len(inp.links) > 0:
brow.label(text='', icon='LINKED')
#if len(channel.modifiers) > 0:
# brow.label(text='', icon='BLANK1')
# Alpha settings will only visible on color channel without developer mode