-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpresets.py
2082 lines (1767 loc) · 80.6 KB
/
presets.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 LICENSE & COPYRIGHT BLOCK.
#
# Copyright (C) 2022-2024 Kiril Strezikozin
# BakeMaster Blender Add-on (version 2.7.0)
#
# This file is a part of BakeMaster Blender Add-on, a plugin for texture
# baking in open-source Blender 3d modelling software.
# The author can be contacted at <[email protected]>.
#
# Redistribution and use for any purpose including personal, educational, and
# commercial, with or without modification, are permitted provided
# that the following conditions are met:
#
# 1. The current acquired License allows copies/redistributions of this
# software be made to UNLIMITED END USER SEATS (OPEN SOURCE LICENSE).
# 2. Redistributions of this source code or partial usage of this source code
# must follow the terms of this license and retain the above copyright
# notice, and the following disclaimer.
# 3. The name of the author may be used to endorse or promote products derived
# from this software. In such a case, a prior written permission from the
# author is required.
#
# This program is free software and 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. IN NO EVENT SHALL THE
# AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# You should have received a copy of the GNU General Public License in the
# GNU.txt file along with this program. If not,
# see <http://www.gnu.org/licenses/>.
#
# END LICENSE & COPYRIGHT BLOCK.
from typing import Literal
import bpy
import os
import re
from bpy.app.translations import pgettext_iface as iface_
###########################################################
### Presets Directory Setup ###
###########################################################
def presets_makedir(path: str, name: str):
path_dir = os.path.join(path, name)
if not os.path.exists(path_dir):
os.makedirs(path_dir)
def BM_Presets_FolderSetup():
bm_presets_subdir = "bakemaster_presets"
bm_presets_dir_path = os.path.join(bpy.utils.user_resource('SCRIPTS'), "presets", bm_presets_subdir)
bm_presets_paths = bpy.utils.preset_paths(bm_presets_subdir)
# bakemaster_presets main dir
if bm_presets_dir_path not in bm_presets_paths and not os.path.exists(bm_presets_dir_path):
os.makedirs(bm_presets_dir_path)
presets_makedir(bm_presets_dir_path, "PRESETS_FULL_OBJECT_decal_hl_uv_csh_out_maps_chnlp_bake")
presets_makedir(bm_presets_dir_path, "PRESETS_OBJECT_decal_hl_uv_csh")
presets_makedir(bm_presets_dir_path, "PRESETS_DECAL_decal")
presets_makedir(bm_presets_dir_path, "PRESETS_HL_hl")
presets_makedir(bm_presets_dir_path, "PRESETS_UV_uv")
presets_makedir(bm_presets_dir_path, "PRESETS_CSH_csh")
presets_makedir(bm_presets_dir_path, "PRESETS_OUT_out")
presets_makedir(bm_presets_dir_path, "PRESETS_FULL_MAP_maps_hl_uv_out")
presets_makedir(bm_presets_dir_path, "PRESETS_MAP_map")
presets_makedir(bm_presets_dir_path, "PRESETS_CHNLP_chnlp")
presets_makedir(bm_presets_dir_path, "PRESETS_BAKE_bake")
presets_makedir(bm_presets_dir_path, "PRESETS_CM_cm")
###########################################################
### Presets Bases ###
###########################################################
# AddPresetBase script
# original from https://developer.blender.org/diffusion/B/browse/master/release/scripts/startup/bl_operators/presets.py%2424
# modified for bakemaster preset base
class BM_AddPresetBase():
"""BakeMaster Add Preset Base,
for subclassing"""
# class has to define:
# preset_menu
# preset_subdir
# preset_defines
# preset_values
# optional and preset-dependant:
# preset_tag
# only because invoke_props_popup requires. Also do not add to search menu.
bl_options = {'REGISTER', 'INTERNAL'}
name: bpy.props.StringProperty(
name="Name",
description="Name of the preset, used to make the path name",
maxlen=64,
options={'SKIP_SAVE'},
)
prop_name: bpy.props.StringProperty(
name="Last used preset property name",
default="",
options={'SKIP_SAVE'},
)
remove_name: bpy.props.BoolProperty(
default=False,
options={'HIDDEN', 'SKIP_SAVE'},
)
remove_active: bpy.props.BoolProperty(
default=False,
options={'HIDDEN', 'SKIP_SAVE'},
)
overwrite: bpy.props.BoolProperty(
default=False,
options={'HIDDEN', 'SKIP_SAVE'},
)
@classmethod
def description(cls, context: bpy.types.Context, properties) -> str:
#return cls.bl_description
if properties.remove_name:
return "Remove this preset from the list"
elif properties.overwrite:
return "Overwrite settings in the '{}' preset with the current ones".format(properties.name)
else:
return "Add new '{}' preset with the current settings".format(properties.name)
@staticmethod
def as_filename(name): # could reuse for other presets
# lazy init maketrans
def maketrans_init():
cls = BM_AddPresetBase
attr = "_as_filename_trans"
trans = getattr(cls, attr, None)
if trans is None:
trans = str.maketrans({char: "_" for char in " |!@#$%^&*(){}:\";'[]<>,.\\/?"})
setattr(cls, attr, trans)
return trans
name = name.strip()
name = bpy.path.display_name_to_filepath(name)
trans = maketrans_init()
# Strip surrounding "_" as they are displayed as spaces.
return name.translate(trans).strip("_")
def execute(self, context):
import os
from bpy.utils import is_path_builtin
if hasattr(self, "pre_cb"):
self.pre_cb(context)
preset_menu_class = getattr(bpy.types, self.preset_menu)
is_xml = getattr(preset_menu_class, "preset_type", None) == 'XML'
is_preset_add = not (self.remove_name or self.remove_active)
if is_xml:
ext = ".xml"
else:
ext = ".py"
name = self.name.strip() if is_preset_add else self.name
if is_preset_add:
if not name:
return {'FINISHED'}
filename = self.as_filename(name)
target_path = os.path.join("presets", self.preset_subdir)
target_path = bpy.utils.user_resource('SCRIPTS', path=target_path, create=True)
if not target_path:
self.report({'WARNING'}, "Failed to create presets path")
return {'CANCELLED'}
filepath = os.path.join(target_path, filename) + ext
# preset with this name already exists
if os.path.isfile(filepath):
self.report({'INFO'}, "Preset exists. Overwriting")
if hasattr(self, "add"):
self.add(context, filepath)
else:
print("Writing Preset: %r" % filepath)
if is_xml:
import rna_xml
rna_xml.xml_file_write(context,
filepath,
preset_menu_class.preset_xml_map)
else:
# Custom for BakeMaster
def rna_recursive_attr_expand(value, rna_path_step, level, add_except, except_type, except_for):
if isinstance(value, bpy.types.PropertyGroup):
for sub_value_attr in value.bl_rna.properties.keys():
if sub_value_attr == "rna_type":
continue
sub_value = getattr(value, sub_value_attr)
rna_recursive_attr_expand(sub_value, "%s.%s" % (rna_path_step, sub_value_attr), level)
elif type(value).__name__ == "bpy_prop_collection_idprop": # could use nicer method
file_preset.write("%s.clear()\n" % rna_path_step)
for sub_value in value:
file_preset.write("item_sub_%d = %s.add()\n" % (level, rna_path_step))
rna_recursive_attr_expand(sub_value, "item_sub_%d" % level, level + 1)
else:
# convert thin wrapped sequences
# to simple lists to repr()
try:
value = value[:]
except Exception:
pass
except_for_in_rna_all = [x for x in except_for if rna_path_step.find(x) != -1]
except_for_in_rna = bool(len(except_for_in_rna_all))
if add_except and except_type and except_for_in_rna:
file_preset.write("try:\n")
file_preset.write("\t%s = %r\n" % (rna_path_step, value))
file_preset.write("except %s:\n" % except_type)
# XXX: stupid, probaly should write it better
if "_map_" in except_for_in_rna_all:
file_preset.write("\t%s = %r\n" % (rna_path_step, 'NONE'))
else:
file_preset.write("\tpass\n")
else:
file_preset.write("%s = %r\n" % (rna_path_step, value))
file_preset = open(filepath, 'w', encoding="utf-8")
file_preset.write("import bpy\n")
bm_props = bpy.context.scene.bm_props
bm_item = bpy.context.scene.bm_table_of_objects[bpy.context.scene.bm_props.global_active_index]
# for hl, uv, out tags add check for if execute for map instead of object
if hasattr(self, "preset_tag"):
preset_defines_bm_item = "bm_item = bpy.context.scene.bm_table_of_objects[bpy.context.scene.bm_props.global_active_index]"
if hasattr(self, "preset_defines") and preset_defines_bm_item in self.preset_defines:
try:
getattr(bm_item, "%s_use_unique_per_map" % getattr(self, "preset_tag"))
except AttributeError:
pass
else:
define = "bm_map = bm_item.global_maps[bm_item.global_maps_active_index] if bm_item.%s_use_unique_per_map and len(bm_item.global_maps) else bm_item" % getattr(self, "preset_tag")
if define not in self.preset_defines:
self.preset_defines.append(define)
# writing preset_defines
if hasattr(self, "preset_defines"):
for rna_path in self.preset_defines:
exec(rna_path)
file_preset.write("%s\n" % rna_path)
file_preset.write("\n")
add_except = True
except_type = "TypeError"
except_for = ["out_bit_depth", "uv_active_layer", "uv_type", "map_vertexcolor_layer", "decal_custom_camera", "cm"]
# add try except TypeError for channel pack maps for chnl preset
if getattr(self, "preset_tag", "other") in ["full_object", "full_map"]:
except_for.append("_map_")
except_for.append("_data")
# append each map props to preset_values for full_object, full_map preset
for map_index, _ in enumerate(bm_item.global_maps):
map_data = [
"global_use_bake",
"global_map_type",
"map_ALBEDO_prefix",
"map_METALNESS_prefix",
"map_ROUGHNESS_prefix",
"map_DIFFUSE_prefix",
"map_SPECULAR_prefix",
"map_GLOSSINESS_prefix",
"map_OPACITY_prefix",
"map_EMISSION_prefix",
"map_PASS_prefix",
# "map_PASS_use_preview",
"map_pass_type",
"map_DECAL_prefix",
# "map_DECAL_use_preview",
"map_decal_pass_type",
"map_decal_height_opacity_invert",
"map_decal_normal_preset",
"map_decal_normal_custom_preset",
"map_decal_normal_r",
"map_decal_normal_g",
"map_decal_normal_b",
"map_VERTEX_COLOR_LAYER_prefix",
# "map_VERTEX_COLOR_LAYER_use_preview",
"map_vertexcolor_layer",
"map_C_COMBINED_prefix",
"map_C_AO_prefix",
"map_C_SHADOW_prefix",
"map_C_POSITION_prefix",
"map_C_NORMAL_prefix",
"map_C_UV_prefix",
"map_C_ROUGHNESS_prefix",
"map_C_EMIT_prefix",
"map_C_ENVIRONMENT_prefix",
"map_C_DIFFUSE_prefix",
"map_C_GLOSSY_prefix",
"map_C_TRANSMISSION_prefix",
"map_cycles_use_pass_direct",
"map_cycles_use_pass_indirect",
"map_cycles_use_pass_color",
"map_cycles_use_pass_diffuse",
"map_cycles_use_pass_glossy",
"map_cycles_use_pass_transmission",
"map_cycles_use_pass_ambient_occlusion",
"map_cycles_use_pass_emit",
"map_NORMAL_prefix",
# "map_NORMAL_use_preview",
"map_normal_data",
"map_normal_space",
"map_normal_multires_subdiv_levels",
"map_normal_preset",
"map_normal_custom_preset",
"map_normal_r",
"map_normal_g",
"map_normal_b",
"map_DISPLACEMENT_prefix",
# "map_DISPLACEMENT_use_preview",
"map_displacement_data",
"map_displacement_result",
"map_displacement_subdiv_levels",
"map_displacement_multires_subdiv_levels",
"map_displacement_use_lowres_mesh",
"map_VECTOR_DISPLACEMENT_prefix",
# "map_VECTOR_DISPLACEMENT_use_preview",
"map_vector_displacement_use_negative",
"map_vector_displacement_result",
"map_vector_displacement_subdiv_levels",
"map_POSITION_prefix",
# "map_POSITION_use_preview",
"map_AO_prefix",
# "map_AO_use_preview",
"map_AO_use_default",
"map_ao_samples",
"map_ao_distance",
"map_ao_black_point",
"map_ao_white_point",
"map_ao_brightness",
"map_ao_contrast",
"map_ao_opacity",
"map_ao_use_local",
"map_ao_use_invert",
"map_CAVITY_prefix",
# "map_CAVITY_use_preview",
"map_CAVITY_use_default",
"map_cavity_black_point",
"map_cavity_white_point",
"map_cavity_power",
"map_cavity_use_invert",
"map_CURVATURE_prefix",
# "map_CURVATURE_use_preview",
"map_CURVATURE_use_default",
"map_curv_samples",
"map_curv_radius",
"map_curv_black_point",
"map_curv_mid_point",
"map_curv_white_point",
"map_curv_body_gamma",
"map_THICKNESS_prefix",
# "map_THICKNESS_use_preview",
"map_THICKNESS_use_default",
"map_thick_samples",
"map_thick_distance",
"map_thick_black_point",
"map_thick_white_point",
"map_thick_brightness",
"map_thick_contrast",
"map_thick_use_invert",
"map_ID_prefix",
# "map_ID_use_preview",
"map_matid_data",
"map_matid_vertex_groups_name_contains",
"map_matid_algorithm",
"map_matid_seed",
"map_MASK_prefix",
# "map_MASK_use_preview",
"map_mask_data",
"map_mask_vertex_groups_name_contains",
"map_mask_materials_name_contains",
"map_mask_color1",
"map_mask_color2",
"map_mask_use_invert",
"map_XYZMASK_prefix",
# "map_XYZMASK_use_preview",
"map_XYZMASK_use_default",
"map_xyzmask_use_x",
"map_xyzmask_use_y",
"map_xyzmask_use_z",
"map_xyzmask_coverage",
"map_xyzmask_saturation",
"map_xyzmask_opacity",
"map_xyzmask_use_invert",
"map_GRADIENT_prefix",
# "map_GRADIENT_use_preview",
"map_GRADIENT_use_default",
"map_gmask_type",
"map_gmask_location_x",
"map_gmask_location_y",
"map_gmask_location_z",
"map_gmask_rotation_x",
"map_gmask_rotation_y",
"map_gmask_rotation_z",
"map_gmask_scale_x",
"map_gmask_scale_y",
"map_gmask_scale_z",
"map_gmask_coverage",
"map_gmask_contrast",
"map_gmask_saturation",
"map_gmask_opacity",
"map_gmask_use_invert",
"map_EDGE_prefix",
# "map_EDGE_use_preview",
"map_EDGE_use_default",
"map_edgemask_samples",
"map_edgemask_radius",
"map_edgemask_edge_contrast",
"map_edgemask_body_contrast",
"map_edgemask_use_invert",
"map_WIREFRAME_prefix",
# "map_WIREFRAME_use_preview",
"map_wireframemask_line_thickness",
"map_wireframemask_use_invert",
"out_use_denoise",
"out_file_format",
"out_tga_use_raw",
"out_dpx_use_log",
"out_tiff_compression",
"out_exr_codec",
"out_compression",
"out_quality",
"out_res",
"out_res_height",
"out_res_width",
"out_margin",
"out_margin_type",
"out_bit_depth",
"out_use_alpha",
"out_use_transbg",
"out_udim_start_tile",
"out_udim_end_tile",
"out_super_sampling_aa",
"out_upscaling",
"out_samples",
"out_use_adaptive_sampling",
"out_adaptive_threshold",
"out_min_samples",
"uv_bake_data",
"uv_bake_target",
"uv_active_layer",
"uv_type",
"uv_snap_islands_to_pixels",
"hl_cage_type",
"hl_cage_extrusion",
"hl_max_ray_distance",
]
for key in map_data:
self.preset_values.append("bm_item.global_maps[%d].%s" % (map_index, key))
# write trash, add maps for full_object, full_map preset
ad_lines = [
"to_remove = []",
"for index, _ in enumerate(bm_item.global_maps):",
"\tto_remove.append(index)",
"bm_item.global_maps_active_index = 0",
"for index in sorted(to_remove, reverse=True):",
"\tbm_item.global_maps.remove(index)",
"for i in range(%s):" % len(bm_item.global_maps),
"\tnew_pass = bm_item.global_maps.add()",
"\tnew_pass.global_map_type = 'ALBEDO'",
"\tnew_pass.global_map_index = len(bm_item.global_maps)",
"\tnew_pass.global_map_object_index = bpy.context.scene.bm_props.global_active_index",
"\tbm_item.global_maps_active_index = len(bm_item.global_maps) - 1",
]
for line in ad_lines:
file_preset.write("%s\n" % line)
# append each channel pack props to preset_values for full_object preset
if getattr(self, "preset_tag") == "full_object":
for channelpack_index, _ in enumerate(bm_item.chnlp_channelpacking_table):
channelpack_data = [
"global_channelpack_name",
"global_channelpack_type",
"R1G1B_use_R",
"R1G1B_map_R",
"R1G1B_use_G",
"R1G1B_map_G",
"R1G1B_use_B",
"R1G1B_map_B",
"RGB1A_use_RGB",
"RGB1A_map_RGB",
"RGB1A_use_A",
"RGB1A_map_A",
"R1G1B1A_use_R",
"R1G1B1A_map_R",
"R1G1B1A_use_G",
"R1G1B1A_map_G",
"R1G1B1A_use_B",
"R1G1B1A_map_B",
"R1G1B1A_use_A",
"R1G1B1A_map_A",
]
for key in channelpack_data:
self.preset_values.append("bm_item.chnlp_channelpacking_table[%d].%s" % (channelpack_index, key))
# write trash, add channel packs for full_object preset
ad_lines = [
"to_remove = []",
"for index, _ in enumerate(bm_item.chnlp_channelpacking_table):",
"\tto_remove.append(index)",
"bm_item.chnlp_channelpacking_table_active_index = 0",
"for index in sorted(to_remove, reverse=True):",
"\tbm_item.chnlp_channelpacking_table.remove(index)",
"for i in range(%s):" % len(bm_item.chnlp_channelpacking_table),
"\tnew_item = bm_item.chnlp_channelpacking_table.add()",
"\tnew_item.global_channelpack_index = len(bm_item.chnlp_channelpacking_table)",
"\tnew_item.global_channelpack_name = 'ChannelPack%d'" % len(bm_item.chnlp_channelpacking_table),
"\tbm_item.chnlp_channelpacking_table_active_index = len(bm_item.chnlp_channelpacking_table) - 1",
]
for line in ad_lines:
file_preset.write("%s\n" % line)
for rna_path in self.preset_values:
value = eval(rna_path)
rna_recursive_attr_expand(value, rna_path, 1, add_except, except_type, except_for)
# Custom for BakeMaster ended
file_preset.close()
preset_menu_class.bl_label = bpy.path.display_name(filename)
bm_props = context.scene.bm_props
setattr(bm_props, self.prop_name, self.name)
# removing preset
else:
if self.remove_active is True:
name = preset_menu_class.bl_label
# fairly sloppy but convenient.
filepath = bpy.utils.preset_find(name, self.preset_subdir, ext=ext)
if not filepath:
filepath = bpy.utils.preset_find(name, self.preset_subdir, display_name=True, ext=ext)
if not filepath:
return {'CANCELLED'}
# Do not remove bundled presets
if is_path_builtin(filepath):
self.report({'WARNING'}, "Unable to remove default presets")
return {'CANCELLED'}
try:
if hasattr(self, "remove"):
self.remove(context, filepath)
else:
os.remove(filepath)
except Exception as e:
self.report({'ERROR'}, "Unable to remove preset: %r" % e)
import traceback
traceback.print_exc()
return {'CANCELLED'}
# XXX, stupid!
preset_menu_class.bl_label = "Presets"
bm_props = context.scene.bm_props
default_p_prop = self.prop_name.replace("_ln_", "_master_")
if hasattr(bm_props, default_p_prop):
setattr(bm_props, default_p_prop, "")
return {'FINISHED'}
def check(self, _context):
self.name = self.as_filename(self.name.strip())
def invoke(self, context, _event):
# if not (self.remove_active or self.remove_name):
# wm = context.window_manager
# return wm.invoke_props_dialog(self)
# else:
return self.execute(context)
###########################################################
class BM_OT_FULL_OBJECT_Preset_Add(BM_AddPresetBase, bpy.types.Operator):
bl_idname = "bakemaster.full_object_preset_add"
bl_label = "Full Object Preset"
bl_description = "Add, Remove, or Update Full Object Preset"
bl_opetions = {'REGISTER', 'UNDO', 'INTERNAL'}
preset_menu = 'BM_MT_FULL_OBJECT_Presets'
preset_subdir = os.path.join('bakemaster_presets', 'PRESETS_FULL_OBJECT_decal_hl_uv_csh_out_maps_chnlp_bake')
preset_defines = [
"bm_item = bpy.context.scene.bm_table_of_objects[bpy.context.scene.bm_props.global_active_index]",
]
preset_tag = "full_object"
# maps and channel packs in addpresetbase,
# depends on bm_item maps and channel packs
preset_values = [
"bm_item.decal_is_decal",
"bm_item.decal_use_custom_camera",
"bm_item.decal_custom_camera",
"bm_item.decal_upper_coordinate",
"bm_item.decal_rotation",
"bm_item.decal_use_flip_vertical",
"bm_item.decal_use_flip_horizontal",
"bm_item.decal_use_adapt_res",
"bm_item.decal_use_precise_bounds",
"bm_item.decal_boundary_offset",
# "bm_item.hl_highpoly_table",
"bm_item.hl_use_bake_individually",
"bm_item.hl_decals_use_separate_texset",
"bm_item.hl_decals_separate_texset_prefix",
# "bm_item.hl_use_cage",
"bm_item.hl_cage_type",
"bm_item.hl_cage_extrusion",
"bm_item.hl_max_ray_distance",
# "bm_item.hl_cage",
"bm_item.hl_use_unique_per_map",
"bm_item.uv_bake_data",
"bm_item.uv_bake_target",
"bm_item.uv_active_layer",
"bm_item.uv_type",
"bm_item.uv_snap_islands_to_pixels",
"bm_item.uv_use_auto_unwrap",
"bm_item.uv_auto_unwrap_angle_limit",
"bm_item.uv_auto_unwrap_island_margin",
"bm_item.uv_auto_unwrap_use_scale_to_bounds",
"bm_item.uv_use_unique_per_map",
"bm_item.csh_use_triangulate_lowpoly",
"bm_item.csh_use_lowpoly_recalc_normals",
"bm_item.csh_lowpoly_use_smooth",
"bm_item.csh_lowpoly_smoothing_groups_enum",
"bm_item.csh_lowpoly_smoothing_groups_angle",
"bm_item.csh_lowpoly_smoothing_groups_name_contains",
"bm_item.csh_use_highpoly_recalc_normals",
"bm_item.csh_highpoly_use_smooth",
"bm_item.csh_highpoly_smoothing_groups_enum",
"bm_item.csh_highpoly_smoothing_groups_angle",
"bm_item.csh_highpoly_smoothing_groups_name_contains",
"bm_item.out_use_denoise",
"bm_item.out_file_format",
"bm_item.out_tga_use_raw",
"bm_item.out_dpx_use_log",
"bm_item.out_tiff_compression",
"bm_item.out_exr_codec",
"bm_item.out_compression",
"bm_item.out_quality",
"bm_item.out_res",
"bm_item.out_res_height",
"bm_item.out_res_width",
"bm_item.out_margin",
"bm_item.out_margin_type",
"bm_item.out_bit_depth",
"bm_item.out_use_alpha",
"bm_item.out_use_transbg",
"bm_item.out_udim_start_tile",
"bm_item.out_udim_end_tile",
"bm_item.out_super_sampling_aa",
"bm_item.out_upscaling",
"bm_item.out_samples",
"bm_item.out_use_adaptive_sampling",
"bm_item.out_adaptive_threshold",
"bm_item.out_min_samples",
"bm_item.out_use_unique_per_map",
"bm_item.bake_save_internal",
"bm_item.bake_output_filepath",
"bm_item.bake_create_subfolder",
"bm_item.bake_subfolder_name",
"bm_item.bake_batchname",
"bm_item.bake_batchname_use_caps",
"bm_item.bake_create_material",
"bm_item.bake_assign_modifiers",
"bm_item.bake_device",
"bm_item.bake_view_from",
"bm_item.bake_use_scene_lights",
"bm_item.bake_hide_when_inactive",
"bm_item.bake_vg_index",
]
@classmethod
def poll(cls, context: bpy.types.Context) -> bool:
sc = context.scene
if len(sc.bm_table_of_objects) == 0:
cls.poll_message_set("No objects added")
return False
return True
class BM_OT_OBJECT_Preset_Add(BM_AddPresetBase, bpy.types.Operator):
bl_idname = "bakemaster.object_preset_add"
bl_label = "Object Preset"
bl_description = "Add, Remove, or Update Decal, High to Lowpoly, UVs & Layers, Shading Preset"
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
preset_menu = 'BM_MT_OBJECT_Presets'
preset_subdir = os.path.join('bakemaster_presets', 'PRESETS_OBJECT_decal_hl_uv_csh')
preset_defines = [
"bm_item = bpy.context.scene.bm_table_of_objects[bpy.context.scene.bm_props.global_active_index]",
]
preset_values = [
"bm_item.decal_is_decal",
"bm_item.decal_use_custom_camera",
"bm_item.decal_custom_camera",
"bm_item.decal_upper_coordinate",
"bm_item.decal_rotation",
"bm_item.decal_use_flip_vertical",
"bm_item.decal_use_flip_horizontal",
"bm_item.decal_use_adapt_res",
"bm_item.decal_use_precise_bounds",
"bm_item.decal_boundary_offset",
# "bm_item.hl_highpoly_table",
"bm_item.hl_use_bake_individually",
"bm_item.hl_decals_use_separate_texset",
"bm_item.hl_decals_separate_texset_prefix",
# "bm_item.hl_use_cage",
"bm_item.hl_cage_type",
"bm_item.hl_cage_extrusion",
"bm_item.hl_max_ray_distance",
# "bm_item.hl_cage",
"bm_item.hl_use_unique_per_map",
"bm_item.uv_bake_data",
"bm_item.uv_bake_target",
"bm_item.uv_active_layer",
"bm_item.uv_type",
"bm_item.uv_snap_islands_to_pixels",
"bm_item.uv_use_auto_unwrap",
"bm_item.uv_auto_unwrap_angle_limit",
"bm_item.uv_auto_unwrap_island_margin",
"bm_item.uv_auto_unwrap_use_scale_to_bounds",
"bm_item.uv_use_unique_per_map",
"bm_item.csh_use_triangulate_lowpoly",
"bm_item.csh_use_lowpoly_recalc_normals",
"bm_item.csh_lowpoly_use_smooth",
"bm_item.csh_lowpoly_smoothing_groups_enum",
"bm_item.csh_lowpoly_smoothing_groups_angle",
"bm_item.csh_lowpoly_smoothing_groups_name_contains",
"bm_item.csh_use_highpoly_recalc_normals",
"bm_item.csh_highpoly_use_smooth",
"bm_item.csh_highpoly_smoothing_groups_enum",
"bm_item.csh_highpoly_smoothing_groups_angle",
"bm_item.csh_highpoly_smoothing_groups_name_contains",
]
@classmethod
def poll(cls, context: bpy.types.Context) -> bool:
sc = context.scene
if len(sc.bm_table_of_objects) == 0:
cls.poll_message_set("No objects added")
return False
return True
class BM_OT_DECAL_Preset_Add(BM_AddPresetBase, bpy.types.Operator):
bl_idname = "bakemaster.decal_preset_add"
bl_label = "Decal Preset"
bl_description = "Add, Remove, or Update Decal Preset"
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
preset_menu = 'BM_MT_DECAL_Presets'
preset_subdir = os.path.join('bakemaster_presets', 'PRESETS_DECAL_decal')
preset_defines = [
"bm_item = bpy.context.scene.bm_table_of_objects[bpy.context.scene.bm_props.global_active_index]",
]
preset_values = [
"bm_item.decal_is_decal",
"bm_item.decal_use_custom_camera",
"bm_item.decal_custom_camera",
"bm_item.decal_upper_coordinate",
"bm_item.decal_rotation",
"bm_item.decal_use_flip_vertical",
"bm_item.decal_use_flip_horizontal",
"bm_item.decal_use_adapt_res",
"bm_item.decal_use_precise_bounds",
"bm_item.decal_boundary_offset",
]
@classmethod
def poll(cls, context: bpy.types.Context) -> bool:
sc = context.scene
if len(sc.bm_table_of_objects) == 0:
cls.poll_message_set("No objects added")
return False
return True
class BM_OT_HL_Preset_Add(BM_AddPresetBase, bpy.types.Operator):
bl_idname = "bakemaster.hl_preset_add"
bl_label = "High to Lowpoly Preset"
bl_description = "Add, Remove, or Update High to Lowpoly Preset"
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
preset_menu = 'BM_MT_HL_Presets'
preset_subdir = os.path.join('bakemaster_presets', 'PRESETS_HL_hl')
preset_defines = [
"bm_item = bpy.context.scene.bm_table_of_objects[bpy.context.scene.bm_props.global_active_index]",
]
preset_tag = "hl"
preset_values = [
# "bm_item.hl_use_unique_per_map",
# "bm_map.hl_highpoly_table",
"bm_item.hl_use_bake_individually",
"bm_item.hl_decals_use_separate_texset",
"bm_item.hl_decals_separate_texset_prefix",
# "bm_map.hl_use_cage",
"bm_map.hl_cage_type",
"bm_map.hl_cage_extrusion",
"bm_map.hl_max_ray_distance",
# "bm_map.hl_cage",
]
@classmethod
def poll(cls, context: bpy.types.Context) -> bool:
sc = context.scene
if len(sc.bm_table_of_objects) == 0:
cls.poll_message_set("No objects added")
return False
bm_props = sc.bm_props
bm_item = sc.bm_table_of_objects[bm_props.global_active_index]
if bm_item.hl_use_unique_per_map and len(bm_item.global_maps) == 0:
cls.poll_message_set("No maps added")
return False
return True
class BM_OT_UV_Preset_Add(BM_AddPresetBase, bpy.types.Operator):
bl_idname = "bakemaster.uv_preset_add"
bl_label = "UVs & Layers Preset"
bl_description = "Add, Remove, or Update UVs & Layers Preset"
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
preset_menu = 'BM_MT_UV_Presets'
preset_subdir = os.path.join('bakemaster_presets', 'PRESETS_UV_uv')
preset_defines = [
"bm_item = bpy.context.scene.bm_table_of_objects[bpy.context.scene.bm_props.global_active_index]",
]
preset_tag = "uv"
preset_values = [
"bm_map.uv_bake_data",
"bm_map.uv_bake_target",
"bm_map.uv_active_layer",
"bm_map.uv_type",
"bm_map.uv_snap_islands_to_pixels",
"bm_item.uv_use_auto_unwrap",
"bm_item.uv_auto_unwrap_angle_limit",
"bm_item.uv_auto_unwrap_island_margin",
"bm_item.uv_auto_unwrap_use_scale_to_bounds",
# "bm_item.uv_use_unique_per_map",
]
@classmethod
def poll(cls, context: bpy.types.Context) -> bool:
sc = context.scene
if len(sc.bm_table_of_objects) == 0:
cls.poll_message_set("No objects added")
return False
bm_props = sc.bm_props
bm_item = sc.bm_table_of_objects[bm_props.global_active_index]
if bm_item.uv_use_unique_per_map and len(bm_item.global_maps) == 0:
cls.poll_message_set("No maps added")
return False
return True
class BM_OT_CSH_Preset_Add(BM_AddPresetBase, bpy.types.Operator):
bl_idname = "bakemaster.csh_preset_add"
bl_label = "Shading Preset"
bl_description = "Add, Remove, or Update Shading Preset"
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
preset_menu = 'BM_MT_CSH_Presets'
preset_subdir = os.path.join('bakemaster_presets', 'PRESETS_CSH_csh')
preset_defines = [
"bm_item = bpy.context.scene.bm_table_of_objects[bpy.context.scene.bm_props.global_active_index]",
]
preset_values = [
"bm_item.csh_use_triangulate_lowpoly",
"bm_item.csh_use_lowpoly_recalc_normals",
"bm_item.csh_lowpoly_use_smooth",
"bm_item.csh_lowpoly_smoothing_groups_enum",
"bm_item.csh_lowpoly_smoothing_groups_angle",
"bm_item.csh_lowpoly_smoothing_groups_name_contains",
"bm_item.csh_use_highpoly_recalc_normals",
"bm_item.csh_highpoly_use_smooth",
"bm_item.csh_highpoly_smoothing_groups_enum",
"bm_item.csh_highpoly_smoothing_groups_angle",
"bm_item.csh_highpoly_smoothing_groups_name_contains",
]
@classmethod
def poll(cls, context: bpy.types.Context) -> bool:
sc = context.scene
if len(sc.bm_table_of_objects) == 0:
cls.poll_message_set("No objects added")
return False
return True
class BM_OT_OUT_Preset_Add(BM_AddPresetBase, bpy.types.Operator):
bl_idname = "bakemaster.out_preset_add"
bl_label = "Format Preset"
bl_description = "Add, Remove, or Update Format Preset"
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
preset_menu = 'BM_MT_OUT_Presets'
preset_subdir = os.path.join('bakemaster_presets', 'PRESETS_OUT_out')
preset_defines = [
"bm_item = bpy.context.scene.bm_table_of_objects[bpy.context.scene.bm_props.global_active_index]",
]
preset_tag = "out"
preset_values = [
"bm_map.out_use_denoise",
"bm_map.out_file_format",
"bm_map.out_tga_use_raw",
"bm_map.out_dpx_use_log",
"bm_map.out_tiff_compression",
"bm_map.out_exr_codec",
"bm_map.out_compression",
"bm_map.out_quality",
"bm_map.out_res",
"bm_map.out_res_height",
"bm_map.out_res_width",
"bm_map.out_margin",
"bm_map.out_margin_type",
"bm_map.out_bit_depth",
"bm_map.out_use_alpha",
"bm_map.out_use_transbg",
"bm_map.out_udim_start_tile",
"bm_map.out_udim_end_tile",
"bm_map.out_super_sampling_aa",
"bm_map.out_upscaling",