forked from franMarz/TexTools-Blender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
1882 lines (1563 loc) · 66.6 KB
/
__init__.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
bl_info = {
"name": "TexTools",
"description": "Professional UV and Texture tools for Blender.",
"author": "renderhjs, franMarz, Sav Martin",
"version": (1, 6, 1),
"blender": (2, 80, 0),
"category": "UV",
"location": "UV Image Editor > Tools > 'TexTools' panel"
}
# import local modules
# More info: https://wiki.blender.org/index.php/Dev:Py/Scripts/Cookbook/Code_snippets/Multi-File_packages
if "bpy" in locals():
from importlib import reload
reload(utilities_ui)
reload(settings)
reload(utilities_bake)
reload(utilities_color)
reload(utilities_texel)
reload(utilities_bbox)
reload(utilities_uv)
reload(utilities_meshtex)
reload(op_align)
reload(op_bake)
reload(op_bake_explode)
reload(op_bake_organize_names)
reload(op_texture_preview)
reload(op_texture_preview_cleanup)
reload(op_color_assign)
reload(op_color_clear)
reload(op_color_convert_texture)
reload(op_color_convert_vertex_colors)
reload(op_edge_split_bevel)
reload(op_color_from_elements)
reload(op_color_from_materials)
reload(op_color_from_directions)
reload(op_color_io_export)
reload(op_color_io_import)
reload(op_color_select)
reload(op_color_select_vertex)
reload(op_island_align_edge)
reload(op_island_align_sort)
reload(op_island_align_world)
reload(op_island_mirror)
reload(op_island_rotate_90)
reload(op_island_straighten_edge_loops)
reload(op_island_centralize)
reload(op_randomize)
reload(op_rectify)
reload(op_select_islands_identical)
reload(op_select_islands_outline)
reload(op_select_islands_overlap)
reload(op_select_islands_flipped)
reload(op_select_zero)
reload(op_relax)
reload(op_smoothing_uv_islands)
reload(op_meshtex_create)
reload(op_meshtex_wrap)
reload(op_meshtex_trim)
reload(op_meshtex_trim_collapse)
reload(op_meshtex_pattern)
reload(op_texel_checker_map)
reload(op_texel_checker_map_cleanup)
reload(op_texel_density_get)
reload(op_texel_density_set)
reload(op_texture_reload_all)
reload(op_texture_save)
reload(op_texture_open)
reload(op_texture_select)
reload(op_texture_remove)
reload(op_unwrap_faces_iron)
reload(op_stitch)
reload(op_unwrap_edge_peel)
reload(op_uv_channel_add)
reload(op_uv_channel_remove)
reload(op_uv_channel_swap)
reload(op_uv_crop)
reload(op_uv_fill)
reload(op_uv_resize)
reload(op_uv_unwrap)
reload(op_uv_size_get)
else:
from . import settings
from . import utilities_ui
from . import utilities_bake
from . import utilities_color
from . import utilities_texel
from . import utilities_bbox
from . import utilities_uv
from . import utilities_meshtex
from . import op_align
from . import op_bake
from . import op_bake_explode
from . import op_bake_organize_names
from . import op_texture_preview
from . import op_texture_preview_cleanup
from . import op_color_assign
from . import op_color_clear
from . import op_color_convert_texture
from . import op_color_convert_vertex_colors
from . import op_color_from_elements
from . import op_color_from_materials
from . import op_color_from_directions
from . import op_edge_split_bevel
from . import op_color_io_export
from . import op_color_io_import
from . import op_color_select
from . import op_color_select_vertex
from . import op_island_align_edge
from . import op_island_align_sort
from . import op_island_align_world
from . import op_island_mirror
from . import op_island_rotate_90
from . import op_island_straighten_edge_loops
from . import op_island_centralize
from . import op_randomize
from . import op_rectify
from . import op_select_islands_identical
from . import op_select_islands_outline
from . import op_select_islands_overlap
from . import op_select_islands_flipped
from . import op_select_zero
from . import op_relax
from . import op_smoothing_uv_islands
from . import op_meshtex_create
from . import op_meshtex_wrap
from . import op_meshtex_trim
from . import op_meshtex_trim_collapse
from . import op_meshtex_pattern
from . import op_texel_checker_map
from . import op_texel_checker_map_cleanup
from . import op_texel_density_get
from . import op_texel_density_set
from . import op_texture_reload_all
from . import op_texture_save
from . import op_texture_open
from . import op_texture_select
from . import op_texture_remove
from . import op_unwrap_faces_iron
from . import op_stitch
from . import op_unwrap_edge_peel
from . import op_uv_channel_add
from . import op_uv_channel_remove
from . import op_uv_channel_swap
from . import op_uv_crop
from . import op_uv_fill
from . import op_uv_resize
from . import op_uv_size_get
from . import op_uv_unwrap
# Import general modules. Important: must be placed here and not on top
import bpy
import math
from bpy.types import Menu, Operator, Panel, AddonPreferences, PropertyGroup
from bpy.props import (
StringProperty,
BoolProperty,
IntProperty,
IntVectorProperty,
FloatProperty,
FloatVectorProperty,
EnumProperty,
PointerProperty,
)
def on_bake_def_back_color_set(self, context):
if self.bool_bake_back_color:
bpy.context.scene.texToolsSettings.bake_back_color = self.bake_back_color_def
def on_bake_color_space_set(self, context):
if utilities_ui.set_bake_color_space_int(utilities_ui.get_bake_mode()) == 1:
bpy.context.scene.texToolsSettings.bake_color_space = 'Non-Color'
elif utilities_ui.set_bake_color_space_int(utilities_ui.get_bake_mode()) == 0:
bpy.context.scene.texToolsSettings.bake_color_space = 'sRGB'
elif utilities_ui.set_bake_color_space_int(utilities_ui.get_bake_mode()) == 3:
bpy.context.scene.texToolsSettings.bake_color_space = 'Utility - Linear - sRGB'
else:
bpy.context.scene.texToolsSettings.bake_color_space = 'Utility - sRGB - Texture'
class Panel_Preferences(AddonPreferences):
bl_idname = __package__
# Addon Preferences https://docs.blender.org/api/blender_python_api_2_67_release/bpy.types.AddonPreferences.html
swizzle_y_coordinate : EnumProperty(items=
[
('Y+', 'Y+ OpenGL', 'Used in Blender, Maya, Modo, Toolbag, Unity'),
('Y-', 'Y- Direct X', 'Used in 3ds Max, CryENGINE, Source, Unreal Engine')
],
description="Color template",
name = "Swizzle Coordinates",
default = 'Y+'
)
bake_device : EnumProperty(items=
[
('DEFAULT', 'Default', 'Use the device specified in the Render Properties panel'),
('CPU', 'CPU', 'Always use the CPU when baking with Cycles'),
('GPU', 'GPU', 'Always use the GPU when baking with Cycles')
],
description="Temporary device override only for baking",
name = "Baking Device",
default = 'DEFAULT'
)
bake_32bit_float : EnumProperty(items=
[
('8', '8 Bit', ''),
('32', '32 Bit', '')
],
description="",
name = "Image depth",
default = '8'
)
bake_back_color_def : FloatVectorProperty(
name="Global custom baking background color",
subtype='COLOR',
size=4,
min=0, max=1,
default=(0.0, 0.0, 0.0, 1.0),
update = on_bake_def_back_color_set
)
bool_bake_back_color : EnumProperty(items=
[
('DEFAULT', 'Default', 'Use default TexTools background colors for baked textures'),
('CUSTOM', 'Custom', 'Set a global custom RGBA color for the background. Note that a transparent background can be specified')
],
description="Mode for baked textures background color and alpha",
name = "Bake background",
default = 'DEFAULT',
update = on_bake_def_back_color_set
)
bake_color_space_def : EnumProperty(items=
[
('STANDARD', 'Standard', 'Set sRGB as Color Space for all baked textures except for Normal maps'),
('PBR', 'PBR typical', 'Set Linear as Color Space for all baked maps except for Diffuse/Base Color, SSS/Emission color, colored Transmission, Environment, Combined or any custom Mode'),
('ASTANDARD', 'ACES standard', 'Set ACES sRGB Texture as Color Space for all baked textures except for Normal maps'),
('APBR', 'ACES PBR typical', 'Set ACES Linear sRGB as Color Space for all baked maps except for Diffuse/Base Color, SSS/Emission color, colored Transmission, Environment, Combined or any custom Mode')
],
description="Automatically set the Color Space of the baked images. Can be changed in the Baking panel",
name = "Bake Color Space",
default = 'STANDARD',
update = on_bake_color_space_set
)
bool_alpha_ignore : BoolProperty(
name="Ignore Alpha when baking other modes",
default=True
)
bool_emission_ignore : BoolProperty(
name="Ignore Emission Strength when baking Emission",
default=True
)
bool_clean_transmission : BoolProperty(
name="Ignore other channels when baking Transmission",
default=False
)
bool_color_id_vertex_color_gamma : BoolProperty(
name="Apply gamma to ID Colors in Vextex Color mode for visual consistency",
default=False
)
bool_modifier_auto_high : BoolProperty(
name="Detect Objects with Subdiv or Bevel Mods as a Highpoly pair for baking",
default=True
)
bake_mode_panel_scale : FloatProperty(
name="Bake Mode Panel Scale",
description="Scale of the bake mode selector panel icons",
default=3.6,
min=2,
max=10
)
texel_density_scale: FloatProperty(
name="Texel Density Unit Scale",
description="Multiplier for scaling the System Units when working with Texel Density values",
default=1,
min=0.00000000001
)
bool_help : BoolProperty(
name="Show help buttons on panels",
default=True
)
def draw(self, context):
layout = self.layout
box = layout.box()
col = box.column(align=True)
col.prop(self, "bake_device", icon='PREFERENCES')
if self.bake_device == 'DEFAULT':
col.label(text="Use the device specified in the Render Properties panel.")
elif self.bake_device == 'CPU':
col.label(text="Always use the CPU when baking in TexTools with Cycles.")
elif self.bake_device == 'GPU':
col.label(text="Always use the GPU when baking in TexTools with Cycles.")
box.separator()
col = box.column(align=True)
col.prop(self, "swizzle_y_coordinate", icon='ORIENTATION_GLOBAL')
if self.swizzle_y_coordinate == 'Y+':
col.label(text="Y+ used in: Blender, Maya, Modo, Toolbag, Unity")
elif self.swizzle_y_coordinate == 'Y-':
col.label(text="Y- used in: 3ds Max, CryENGINE, Source, Unreal Engine")
box.separator()
col = box.column(align=True)
col.prop(self, "bake_32bit_float", icon='IMAGE_RGB')
if self.bake_32bit_float == '8':
col.label(text="8 Bit images are used. Banding may appear in normal maps.")
elif self.bake_32bit_float == '32':
col.label(text="32 Bit images are used. Images may require dithering to 8 bit.")
box.separator()
col = box.column(align=True)
col.prop(self, "bake_color_space_def", icon='IMAGE_ZDEPTH')
if self.bake_device == 'STANDARD':
col.label(text="Set sRGB as Color Space for all baked textures except for Normal maps.")
elif self.bake_device == 'PBR':
col.label(text="Set Linear as Color Space for all baked maps except for Diffuse/Base Color, SSS/Emission color, colored Transmission, Environment, Combined or any custom Mode.")
elif self.bake_device == 'ASTANDARD':
col.label(text="Set ACES sRGB Texture as Color Space for all baked textures except for Normal maps.")
elif self.bake_device == 'APBR':
col.label(text="Set ACES Linear sRGB as Color Space for all baked maps except for Diffuse/Base Color, SSS/Emission color, colored Transmission, Environment, Combined or any custom Mode.")
box.separator()
col = box.column(align=True)
col.prop(self, "bool_bake_back_color", icon='IMAGE_RGB_ALPHA')
if self.bool_bake_back_color == 'CUSTOM':
col.prop(self, "bake_back_color_def", text ="")
box.separator()
col = box.column(align=True)
col.prop(self, "bool_modifier_auto_high", icon='MESH_MONKEY')
box.separator()
col = box.column(align=True)
col.prop(self, "bool_alpha_ignore", icon='ANIM')
col.prop(self, "bool_clean_transmission", icon='ANIM')
col.prop(self, "bool_emission_ignore", icon='ANIM')
col.prop(self, "bake_mode_panel_scale")
box.separator()
col = box.column(align=True)
col.prop(self, "texel_density_scale")
box.separator()
col = box.column(align=True)
col.prop(self, "bool_color_id_vertex_color_gamma", icon='INDIRECT_ONLY_ON')
box.separator()
col = box.column(align=True)
col.prop(self, "bool_help", icon='INFO')
if not hasattr(bpy.types,"ShaderNodeBevel"):
box.separator()
col = box.column(align=True)
col.label(text="Unlock Bevel Shader", icon='ERROR')
col.operator("wm.url_open", text="Get Blender with Bevel Shader", icon='BLENDER').url = "https://builder.blender.org/download/"
col.label(text="Use nightly builds of Blender 2.79 or 2.8 to access Bevel baking")
box = layout.box()
box.label(text="Additional Links")
col = box.column(align=True)
col.operator("wm.url_open", text="Donate", icon='HELP').url = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=ZC9X4LE7CPQN6"
col.operator("wm.url_open", text="GIT Code", icon='WORDWRAP_ON').url = "https://github.com/SavMartin/TexTools-Blender"
col.label(text="Discussions")
row = col.row(align=True)
row.operator("wm.url_open", text="BlenderArtists", icon='BLENDER').url = "https://blenderartists.org/forum/showthread.php?443182-TexTools-for-Blender"
row.operator("wm.url_open", text="Polycount").url = "http://polycount.com/discussion/197226/textools-for-blender"
row.operator("wm.url_open", text="Twitter").url = "https://twitter.com/search?q=%23textools"
class UV_OT_op_debug(Operator):
bl_idname = "uv.op_debug"
bl_label = "Debug"
bl_description = "Open console and enable debug mode"
@classmethod
def poll(cls, context):
return True
def execute(self, context):
bpy.app.debug = True # Debug Vertex indexies
bpy.context.object.data.show_extra_indices = True
bpy.app.debug_value = 1 #Set to Non '0
return {'FINISHED'}
class UV_OT_op_select_bake_set(Operator):
bl_idname = "uv.op_select_bake_set"
bl_label = "Select"
bl_description = "Select this bake set in scene"
select_set : StringProperty(default="")
@classmethod
def poll(cls, context):
return True
def execute(self, context):
premode = bpy.context.active_object.mode
if self.select_set != "":
for bset in settings.sets:
if bset.name == self.select_set:
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
bpy.ops.object.select_all(action='DESELECT')
for obj in bset.objects_low:
obj.select_set( state = True, view_layer = None)
for obj in bset.objects_high:
obj.select_set( state = True, view_layer = None)
for obj in bset.objects_cage:
obj.select_set( state = True, view_layer = None)
# Set active object to low poly to better visualize high and low wireframe color
if bset.objects_low:
bpy.context.view_layer.objects.active = bset.objects_low[0]
break
bpy.ops.object.mode_set(mode=premode)
return {'FINISHED'}
class UV_OT_op_select_bake_type(Operator):
bl_idname = "uv.op_select_bake_type"
bl_label = "Select"
bl_description = "Select bake objects of this type"
select_type : StringProperty(default='low')
@classmethod
def poll(cls, context):
return True
def execute(self, context):
objects = []
for bset in settings.sets:
if self.select_type == 'low':
objects += bset.objects_low
elif self.select_type == 'high':
objects += bset.objects_high
elif self.select_type == 'cage':
objects += bset.objects_cage
elif self.select_type == 'float':
objects += bset.objects_float
elif self.select_type == 'issue' and bset.has_issues:
objects += bset.objects_low
objects += bset.objects_high
objects += bset.objects_cage
objects += bset.objects_float
if objects:
premode = bpy.context.active_object.mode
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
bpy.ops.object.select_all(action='DESELECT')
for obj in objects:
obj.select_set( state = True, view_layer = None)
bpy.ops.object.mode_set(mode=premode)
return {'FINISHED'}
def on_dropdown_size(self, context):
# Help: http://elfnor.com/drop-down-and-button-select-menus-for-blender-operator-add-ons.html
size = int(bpy.context.scene.texToolsSettings.size_dropdown)
bpy.context.scene.texToolsSettings.size[0] = size
bpy.context.scene.texToolsSettings.size[1] = size
if size <= 256:
bpy.context.scene.texToolsSettings.padding = 2
else:
bpy.context.scene.texToolsSettings.padding = 4
def on_dropdown_uv_channel(self, context):
selected_obs = [ob for ob in bpy.context.selected_objects if ob.type == 'MESH']
if selected_obs:
for ob in selected_obs:
if ob.data.uv_layers:
# Change Mesh UV Channel
index = int(bpy.context.scene.texToolsSettings.uv_channel)
if index < len(ob.data.uv_layers):
ob.data.uv_layers.active_index = index
#bpy.context.object.data.uv_layers[index].active_render = True
ob.data.uv_layers[0].active_render = True
def on_color_changed(self, context):
if bpy.context.scene.texToolsSettings.color_assign_mode == 'MATERIALS':
for i in range(0, context.scene.texToolsSettings.color_ID_count):
utilities_color.assign_color(i)
def on_color_dropdown_template(self, context):
hex_colors = bpy.context.scene.texToolsSettings.color_ID_templates.split(',')
bpy.context.scene.texToolsSettings.color_ID_count = len(hex_colors)
for i in range(0, len(hex_colors)):
color = utilities_color.hex_to_color("#"+hex_colors[i])
utilities_color.set_color(i, color)
if bpy.context.scene.texToolsSettings.color_assign_mode == 'MATERIALS':
utilities_color.assign_color(i)
def on_color_count_changed(self, context):
if bpy.context.active_object is not None and bpy.context.scene.texToolsSettings.color_assign_mode == 'MATERIALS':
utilities_color.validate_face_colors(bpy.context.active_object)
def on_color_mode_change(self, context):
if bpy.context.scene.texToolsSettings.color_assign_mode == 'MATERIALS':
# Refresh color palette of existing colored materials
for i in range(0, context.scene.texToolsSettings.color_ID_count):
utilities_color.assign_color(i)
if bpy.context.active_object is not None:
if bpy.context.active_object.mode != 'EDIT' and bpy.context.active_object.mode != 'OBJECT':
bpy.ops.object.mode_set(mode='OBJECT')
utilities_color.update_properties_tab()
utilities_color.update_view_mode()
def get_dropdown_uv_values(self, context):
options = []
obj = bpy.context.active_object
if obj and obj.type == 'MESH' and obj.data.uv_layers:
step = 0
for uvLoop in obj.data.uv_layers:
options.append((str(step), "UV {}".format(step+1), "Change active UV Channel of all selected Objects to '{}' where possible".format(uvLoop.name), step))
step += 1
return options
def on_slider_meshtexture_wrap(self, context):
value = bpy.context.scene.texToolsSettings.meshtexture_wrap
obj_uv = utilities_meshtex.find_uv_mesh(bpy.context.selected_objects)
if obj_uv:
obj_uv.data.shape_keys.key_blocks["uv"].value = value
class TexToolsSettings(PropertyGroup):
def get_bake_back_color(self):
return self.get("bake_back_color", bpy.context.preferences.addons[__package__].preferences.bake_back_color_def)
def set_bake_back_color(self, value):
if value is not None:
self["bake_back_color"] = value
def get_bake_color_space(self):
return self.get("bake_color_space", utilities_ui.set_bake_color_space_int(utilities_ui.get_bake_mode()))
def set_bake_color_space(self, value):
if value is not None:
self["bake_color_space"] = value
#Width and Height
size : IntVectorProperty(
name = "Size",
size=2,
description="Texture & UV size in pixels",
default = (512,512),
subtype = "XYZ"
)
size_dropdown : EnumProperty(
items = utilities_ui.size_textures,
name = "Texture Size",
update = on_dropdown_size,
default = '512'
)
uv_channel : EnumProperty(
items = get_dropdown_uv_values,
name = "UV",
update = on_dropdown_uv_channel
)
UDIMs_source : EnumProperty(items=
[('OBJECT', 'From Object', 'Work on the first detected Tiled UDIM Image in the Active Object Materials'),
('EDITOR', 'Editor Image', 'Work on the UV Editor Linked Image')],
name = "UDIM Tiles Source",
default = 'OBJECT'
)
padding : IntProperty(
name = "Padding",
description = "Padding size in pixels",
default = 4,
min = 0,
max = 256
)
bake_samples : IntProperty(
name = "Samples",
description = "Samples in Cycles for baking. The higher, the less noise. Use with caution with high values",
default = 8,
min = 1,
max = 4000
)
bake_curvature_size : IntProperty(
name = "Curvature",
description = "Curvature offset in pixels to process",
default = 1,
min = 1,
max = 64
)
bake_wireframe_size : FloatProperty(
name = "Thickness",
description = "Wireframe thickness in pixels",
default = 1,
min = 0.1,
max = 4.0
)
bake_bevel_size : FloatProperty(
name = "Radius",
description = "Bevel radius",
default = 0.05,
min = 0.0,
max = 16
)
bake_bevel_samples : IntProperty(
name = "Bevel Samples",
description = "Bevel samples. The higher, the less noise. Use with caution with values higher than 64",
default = 16,
min = 1,
max = 256
)
bake_thickness_distance : FloatProperty(
name = "Distance",
description = "AO distance",
default = 1.0,
min = 0.0,
max = 16.0
)
bake_thickness_contrast : FloatProperty(
name = "Contrast",
description = "AO contrast",
default = 1.0,
min = 0.0,
max = 2.0
)
bake_thickness_local : BoolProperty(
name = "Only Local",
description = "Only detect occlusion from the object itself, and not others",
default = True
)
bake_ray_distance : FloatProperty(
name = "Ray Distance",
description = "The maximum ray distance for matching points between the active and selected objects. If zero, there is no limit",
default = 0.00,
min = 0.000,
max = 100.00
)
bake_cage_extrusion : FloatProperty(
name = "Cage Extrusion",
description = "Cage Extrusion, Inflate the cage object by the specified distance for baking",
default = 0.00,
min = 0.000,
max = 100.00
)
bake_force : EnumProperty(items=
[('None', 'Normal', 'Use the default TexTools baking behaviour'),
('Single', 'Single', 'Force a single texture bake across all selected Objects'),
('Multi', 'Multi', 'Force a texture bake for each selected Mesh Object by disabling automatic pairing by name')], name = "Force", default = 'None'
)
bake_sampling : EnumProperty(items=
[('1', 'None', 'No Anti Aliasing (Fast)'),
('2', '2x', 'Render 2x and downsample'),
('4', '4x', 'Render 2x and downsample')], name = "AA", default = '1'
)
# Default Color Space have to be Linear as the first bake mode loaded in the UI before refreshing the bake mode is Tangent Normal
bake_color_space : EnumProperty(items=
[('sRGB', 'sRGB', 'Standard RGB output color space for the baked texture'),
('Non-Color', 'Linear', 'Linear or Non-Color output color space for the baked texture'),
('Utility - sRGB - Texture', 'Utility - sRGB - Texture', 'ACES Standard RGB Texture output color space for the baked texture'),
('Utility - Linear - sRGB', 'Utility - Linear - sRGB', 'ACES Linear Standard RGB output color space for the baked texture')],
name = "CS",
default = 'Non-Color',
get = get_bake_color_space,
set = set_bake_color_space
)
bake_back_color : FloatVectorProperty(
description = "Baked texture background color",
name = "BK",
subtype = 'COLOR',
size = 4,
min = 0,
max = 1,
default = (0.0, 0.0, 0.0, 1.0),
get = get_bake_back_color,
set = set_bake_back_color
)
bake_freeze_selection : BoolProperty(
name="Lock",
description="Lock baking sets, don't change with selection",
default = False
)
align_mode : EnumProperty(items=
[('SELECTION', 'Selection', 'Align selected islands to the selection limits'),
('CANVAS', 'Canvas', 'Align selected islands to the canvas margins'),
('CURSOR', 'Cursor', 'Align selected islands to the cursor position')],
name = "Mode",
default = 'SELECTION'
)
texel_get_mode : EnumProperty(items=
[('IMAGE', 'Image', 'Per object, get the resolution of the first image found in any used material'),
('SIZE', 'TexTools Size', 'Use the Size specified under the TexTools tab')] + utilities_ui.size_textures,
name = "Texture Size",
default = 'IMAGE'
)
texel_set_mode : EnumProperty(items=
[('ISLAND', 'Islands', 'Scale UV islands to match Texel Density'),
('ALL', 'Combined', 'Scale all UVs together to match Texel Density')],
name = "Set Mode",
default = 'ISLAND'
)
texel_density : FloatProperty(
name = "Texel",
description = "Texel size or Pixels per unit ratio",
default = 256,
min = 0.0
)
meshtexture_wrap : FloatProperty(
name = "Wrap",
description = "Transition of mesh texture wrap",
default = 1,
min = 0,
max = 1,
update = on_slider_meshtexture_wrap,
subtype = 'FACTOR'
)
vertex_color_threshold : FloatProperty(
name = "Vertex Color Threshold",
description = "Color threshold for vertex color selection",
default = .01,
min = 0.0,
max = 0.5,
precision=3,
step=1
)
def get_color(hex = "808080"):
return FloatVectorProperty(
name="Color1",
description="Set Color 1 for the Palette",
subtype="COLOR",
default=utilities_color.hex_to_color(hex),
size=3,
max=1.0, min=0.0,
update=on_color_changed
)
# 10 Color ID's
color_ID_color_0 : get_color(hex="#ff0000")
color_ID_color_1 : get_color(hex="#0000ff")
color_ID_color_2 : get_color(hex="#00ff00")
color_ID_color_3 : get_color(hex="#ffff00")
color_ID_color_4 : get_color(hex="#00ffff")
color_ID_color_5 : get_color()
color_ID_color_6 : get_color()
color_ID_color_7 : get_color()
color_ID_color_8 : get_color()
color_ID_color_9 : get_color()
color_ID_color_10 : get_color()
color_ID_color_11 : get_color()
color_ID_color_12 : get_color()
color_ID_color_13 : get_color()
color_ID_color_14 : get_color()
color_ID_color_15 : get_color()
color_ID_color_16 : get_color()
color_ID_color_17 : get_color()
color_ID_color_18 : get_color()
color_ID_color_19 : get_color()
color_ID_templates : EnumProperty(items=
[
('3d3d3d,7f7f7f,b8b8b8,ffffff', '4 Gray', '...'),
('003153,345d4b,688a42,9db63a,d1e231', '5 Greens', '...'),
('ff0000,0000ff,00ff00,ffff00,00ffff', '5 Code', '...'),
('3a4342,2e302f,242325,d5cc9e,d6412b', '5 Sea Wolf', '...'),
('7f87a0,2d3449,000000,ffffff,f99c21', '5 Mustang', '...'),
('143240,209d8c,fed761,ffab56,fb6941', '5 Sunset', '...'),
('0087ed,23ca7a,eceb1d,e37a29,da1c2c', '5 Heat', '...'),
('9e00af,7026b9,4f44b5,478bf4,39b7d5,229587,47b151,9dcf46,f7f235,f7b824,f95f1e,c5513c,78574a,4d4b4b,9d9d9d', '15 Rainbow', '...')
],
description="Color template",
name = "Preset",
update = on_color_dropdown_template,
default = 'ff0000,0000ff,00ff00,ffff00,00ffff'
)
color_ID_count : IntProperty(
name = "Count",
description="Number of color IDs",
default = 5,
update = on_color_count_changed,
min = 2,
max = 20
)
color_assign_mode : EnumProperty(items=
[('MATERIALS', 'Materials', 'Assign simple colored materials to objects or selected faces'),
('VERTEXCOLORS', 'Vertex Colors', 'Assign colors as Vertex Colors to objects or selected faces')],
name = "Assign Mode",
default = 'MATERIALS',
update = on_color_mode_change
)
# bake_do_save = BoolProperty(
# name="Save",
# description="Save the baked texture?",
# default = False)
class UI_PT_Panel_Units(Panel):
bl_label = " "
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'UI'
bl_category = "TexTools"
#bl_options = {'HIDE_HEADER'}
def draw_header(self, _):
layout = self.layout
row = layout.row(align=True)
row.label(text ="TexTools")
#layout.label(text="Size: {} x {}".format(bpy.context.scene.texToolsSettings.size[0], bpy.context.scene.texToolsSettings.size[1]))
def draw(self, context):
layout = self.layout
if bpy.app.debug_value != 0:
row = layout.row()
row.alert =True
row.operator("uv.op_debug", text="DEBUG", icon="CONSOLE")
#---------- Settings ------------
# row = layout.row()
col = layout.column(align=True)
r = col.row(align = True)
r.prop(context.scene.texToolsSettings, "size_dropdown", text="Size")
r.operator(op_uv_size_get.op.bl_idname, text="", icon = 'EYEDROPPER')
r = col.row(align = True)
r.prop(context.scene.texToolsSettings, "size", text="")
r = col.row(align = True)
r.prop(context.scene.texToolsSettings, "padding", text="Padding")
r.operator(op_uv_resize.op.bl_idname, text="Resize", icon_value = icon_get("op_extend_canvas_open"))
#col.operator(op_extend_canvas.op.bl_idname, text="Resize", icon_value = icon_get("op_extend_canvas"))
obj = bpy.context.active_object
if obj and (obj.mode == 'EDIT' or (bpy.context.selected_objects and obj in bpy.context.selected_objects)):
if obj.type == 'MESH':
row = layout.row()
if not obj.data.uv_layers:
row.operator(op_uv_channel_add.op.bl_idname, text="Add", icon = 'ADD')
else:
# UV Channel
group = row.row(align=True)
group.prop(context.scene.texToolsSettings, "uv_channel", text="")
group.operator(op_uv_channel_add.op.bl_idname, text="", icon = 'ADD')
group.operator(op_uv_channel_remove.op.bl_idname, text="", icon = 'REMOVE')
r = group.column(align=True)
r.active = obj.data.uv_layers.active_index > 0
r.operator(op_uv_channel_swap.op.bl_idname, text="", icon = 'TRIA_UP_BAR').is_down = False
r = group.column(align=True)
r.active = obj.data.uv_layers.active_index < (len(obj.data.uv_layers)-1)
r.operator(op_uv_channel_swap.op.bl_idname, text="", icon = 'TRIA_DOWN_BAR').is_down = True
# UDIM Tiles
row = layout.row()
row.prop(context.scene.texToolsSettings, "UDIMs_source", text="Tiles")
def get_UDIM_image():
for i in range(len(obj.material_slots)):
slot = obj.material_slots[i]
if slot.material:
tree = slot.material.node_tree
if tree:
nodes = tree.nodes
if nodes:
for node in nodes:
if node.type == 'TEX_IMAGE' and node.image and node.image.source =='TILED':
return node.image
return None
if bpy.context.scene.texToolsSettings.UDIMs_source == 'OBJECT':
image = get_UDIM_image()
else: # 'EDITOR'
image = context.space_data.image
if image:
row = layout.row(align=True)
col = row.column()
col.template_list("IMAGE_UL_udim_tiles", "", image, "tiles", image.tiles, "active_index", rows=3, maxrows=3)
col = layout.column(align=True)
row = col.row(align = True)
row.operator(op_texture_reload_all.op.bl_idname, text="Reload Textures", icon_value = icon_get("op_texture_reload_all"))
if settings.bversion >= 3.0:
row = col.row(align=True)
row.scale_y = 1.75
row.operator(op_texel_checker_map.op.bl_idname, text ="Checker Map", icon_value = icon_get("op_texel_checker_map"))
row.operator(op_texel_checker_map_cleanup.op.bl_idname, text ="", icon = 'TRASH')
if context.active_object and 'TT_CM_Scale' in context.active_object:
row = col.row(align = True)
row.prop(context.active_object, "TT_CM_Scale", text="Tiling")
class UI_PT_Panel_Layout(Panel):
bl_label = " "
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'UI'
bl_category = "TexTools"
bl_options = {'DEFAULT_CLOSED'}
def draw_header(self, _):
layout = self.layout
row = layout.row(align=True)
if bpy.context.preferences.addons[__package__].preferences.bool_help:
row.operator("wm.url_open", text="", icon='INFO').url = "http://renderhjs.net/textools/blender/index.html#uvlayout"
row.label(text ="UV Layout")
# def draw_header(self, _):
# layout = self.layout
# layout.label(text="", icon_value=icon("logo"))
def draw(self, context):
layout = self.layout
if bpy.app.debug_value != 0:
pass
# col = layout.column(align=True)
# col.alert = True
# row = col.row(align=True)
# row.operator(op_island_mirror.op.bl_idname, text="Mirror", icon_value = icon_get("op_island_mirror")).is_stack = False
# row.operator(op_island_mirror.op.bl_idname, text="Stack", icon_value = icon_get("op_island_mirror")).is_stack = True
#---------- Layout ------------
# layout.label(text="Layout")
box = layout.box()
col = box.column(align=True)
row = col.row(align=True)
row.operator(op_uv_crop.op.bl_idname, text="Crop", icon_value = icon_get("op_uv_crop"))
row.operator(op_uv_fill.op.bl_idname, text="Fill", icon_value = icon_get("op_uv_fill"))
row = col.row(align=True)
row.operator(op_island_align_edge.op.bl_idname, text="Align Edge", icon_value = icon_get("op_island_align_edge"))
row = col.row(align=True)
row.operator(op_island_align_world.op.bl_idname, text="Align World", icon_value = icon_get("op_island_align_world"))
if bpy.app.debug_value != 0:
c = col.column(align=True)
c.alert = True
c.operator(op_edge_split_bevel.op.bl_idname, text="Split Bevel")
col.separator()
col_tr = col.column(align=True)