-
Notifications
You must be signed in to change notification settings - Fork 339
/
__init__.py
1189 lines (933 loc) · 40.7 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": "Blend_My_NFTs",
"author": "Torrin Leonard, This Cozy Studio Inc.",
"version": (4, 6, 0),
"blender": (3, 2, 2),
"location": "View3D",
"description": "A free and opensource Blender add-on that enables you to create thousands of unique images, "
"animations, and 3D models.",
"support": "COMMUNITY",
"doc_url": "https://github.com/torrinworx/Blend_My_NFTs",
"tracker_url": "https://github.com/torrinworx/Blend_My_NFTs/issues/new",
"category": "Development",
}
BMNFTS_VERSION = "v4.6.0"
LAST_UPDATED = "08:31PM, Jan 1st, 2023"
# ======== Import handling ======== #
# Blender modules:
import bpy
from bpy.app.handlers import persistent
from bpy.props import (IntProperty, BoolProperty, CollectionProperty)
# Python modules:
import os
import sys
import json
import importlib
import traceback
from typing import Any
from dataclasses import dataclass
from datetime import datetime, timezone
# "a little hacky bs" - matt159 ;)
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
# Local modules:
from main import \
helpers, \
dna_generator, \
exporter, \
headless_util, \
intermediate, \
logic, \
material_generator, \
metadata_templates, \
refactorer
from UILists import \
custom_metadata_ui_list, \
logic_ui_list
# Refresh Locals for development:
if "bpy" in locals():
modules = {
"helpers": helpers,
"dna_generator": dna_generator,
"exporter": exporter,
"headless_util": headless_util,
"intermediate": intermediate,
"logic": logic,
"material_generator": material_generator,
"metadata_templates": metadata_templates,
"refactorer": refactorer,
"custom_metadata_ui_list": custom_metadata_ui_list,
"logic_ui_list": logic_ui_list,
}
for i in modules:
if i in locals():
importlib.reload(modules[i])
# ======== Persistent UI Refresh ======== #
# Used for updating text and buttons in UI panels
combinations: int = 0
recommended_limit: int = 0
dt = datetime.now(timezone.utc).astimezone() # Date Time in UTC local
@persistent
def refresh_ui(dummy1, dummy2):
"""
Refreshes the UI upon user interacting with Blender (using depsgraph_update_post handler). Might be a better handler
to use.
"""
global combinations
global recommended_limit
combinations = (helpers.get_combinations())
recommended_limit = int(round(combinations / 2))
# Add panel classes that require refresh to this refresh_panels tuple:
refresh_panel_classes = (
BMNFTS_PT_CreateData,
)
def redraw_panel(panels):
for i in panels:
try:
bpy.utils.unregister_class(i)
except Exception:
print(traceback.format_exc())
bpy.utils.register_class(i)
redraw_panel(refresh_panel_classes)
bpy.app.handlers.depsgraph_update_post.append(refresh_ui)
# ======== Defining BMNFTs Data ======== #
@dataclass
class BMNFTData:
nft_name: str
save_path: str
nfts_per_batch: int
batch_to_generate: int
collection_size: int
blend_my_nfts_output: str
batch_json_save_path: str
nft_batch_save_path: str
enable_images: bool
image_file_format: str
enable_animations: bool
animation_file_format: str
enable_models: bool
model_file_format: str
enable_custom_fields: bool
cardano_metadata_bool: bool
solana_metadata_bool: bool
erc721_metadata: bool
cardano_description: str
solana_description: str
erc721_description: str
enable_materials: bool
materials_file: str
enable_logic: bool
enable_logic_json: bool
logic_file: str
enable_rarity: bool
enable_auto_shutdown: bool
specify_time_bool: bool
hours: int
minutes: int
email_notification_bool: bool
sender_from: str
email_password: str
receiver_to: str
enable_debug: bool
log_path: str
enable_dry_run: str
order_num_offset: int
custom_fields: dict = None
fail_state: Any = False
failed_batch: Any = None
failed_dna: Any = None
failed_dna_index: Any = None
def __post_init__(self):
self.custom_fields = {}
def get_bmnft_data():
_save_path = bpy.path.abspath(bpy.context.scene.input_tool.save_path)
_Blend_My_NFTs_Output, _batch_json_save_path, _nftBatch_save_path = make_directories(_save_path)
# IMPORTANT: if a new directory variable is ever added, use 'bpy.path.abspath' instead of 'os.path.abspath'.
data = BMNFTData(
nft_name=bpy.context.scene.input_tool.nft_name,
save_path=bpy.path.abspath(_save_path), # Converting from Blender's relative path system to absolute.
nfts_per_batch=bpy.context.scene.input_tool.nfts_per_batch,
batch_to_generate=bpy.context.scene.input_tool.batch_to_generate,
collection_size=bpy.context.scene.input_tool.collection_size,
enable_rarity=bpy.context.scene.input_tool.enable_rarity,
blend_my_nfts_output=_Blend_My_NFTs_Output,
batch_json_save_path=_batch_json_save_path,
nft_batch_save_path=_nftBatch_save_path,
enable_logic=bpy.context.scene.input_tool.enable_logic,
enable_logic_json=bpy.context.scene.input_tool.enable_logic_json,
logic_file=bpy.path.abspath(bpy.context.scene.input_tool.logic_file),
enable_images=bpy.context.scene.input_tool.image_bool,
image_file_format=bpy.context.scene.input_tool.image_enum,
enable_animations=bpy.context.scene.input_tool.animation_bool,
animation_file_format=bpy.context.scene.input_tool.animation_enum,
enable_models=bpy.context.scene.input_tool.model_bool,
model_file_format=bpy.context.scene.input_tool.model_enum,
enable_custom_fields=bpy.context.scene.input_tool.enable_custom_fields,
cardano_metadata_bool=bpy.context.scene.input_tool.cardano_metadata_bool,
solana_metadata_bool=bpy.context.scene.input_tool.solana_metadata_bool,
erc721_metadata=bpy.context.scene.input_tool.erc721_metadata,
cardano_description=bpy.context.scene.input_tool.cardano_description,
solana_description=bpy.context.scene.input_tool.solana_description,
erc721_description=bpy.context.scene.input_tool.erc721_description,
enable_materials=bpy.context.scene.input_tool.enable_materials,
materials_file=bpy.path.abspath(bpy.context.scene.input_tool.materials_file),
enable_auto_shutdown=bpy.context.scene.input_tool.enable_auto_shutdown,
specify_time_bool=bpy.context.scene.input_tool.specify_time_bool,
hours=bpy.context.scene.input_tool.hours,
minutes=bpy.context.scene.input_tool.minutes,
email_notification_bool=bpy.context.scene.input_tool.email_notification_bool,
sender_from=bpy.context.scene.input_tool.sender_from,
email_password=bpy.context.scene.input_tool.email_password,
receiver_to=bpy.context.scene.input_tool.receiver_to,
enable_debug=bpy.context.scene.input_tool.enable_debug,
order_num_offset=bpy.context.scene.input_tool.order_num_offset,
log_path=bpy.path.abspath(bpy.context.scene.input_tool.log_path),
enable_dry_run=bpy.context.scene.input_tool.enable_dry_run
)
return data
# ======== Helper functions ======== #
def make_directories(save_path):
"""Makes all Blend_My_NFTs Output folder directories from save_path input."""
Blend_My_NFTs_Output = os.path.join(save_path, "Blend_My_NFTs Output", "NFT_Data")
batch_json_save_path = os.path.join(Blend_My_NFTs_Output, "Batch_Data")
nftBatch_save_path = os.path.join(save_path, "Blend_My_NFTs Output", "Generated NFT Batches")
if not os.path.exists(Blend_My_NFTs_Output):
os.makedirs(Blend_My_NFTs_Output)
if not os.path.exists(batch_json_save_path):
os.makedirs(batch_json_save_path)
if not os.path.exists(nftBatch_save_path):
os.makedirs(nftBatch_save_path)
return Blend_My_NFTs_Output, batch_json_save_path, nftBatch_save_path
def run_as_headless():
"""
For use when running from the command line.
"""
# force CUDA device usage with cycles renderer
cprefs = bpy.context.preferences.addons['cycles'].preferences
cprefs.compute_device_type = 'CUDA'
cprefs.get_devices()
print(cprefs.devices.keys())
for key in cprefs.devices.keys():
cprefs.devices[key].use = True
print('Using {} devices for rendering!'.format(cprefs.get_num_gpu_devices()))
# def dumpSettings(settings):
# output = (
# f"nft_name={settings.nft_name}\n"
# f"collection_size={str(settings.collection_size)}\n"
# f"nfts_per_batch={str(settings.nfts_per_batch)}\n"
# f"save_path={settings.save_path}\n"
# f"enable_rarity={(settings.enable_rarity)}\n"
# f"enable_logic={str(settings.enable_logic)}\n"
# f"image_bool={str(settings.image_bool)}\n"
# f"image_enum={settings.image_enum}\n"
# f"animation_bool={str(settings.animation_bool)}\n"
# f"animation_enum={settings.animation_enum}\n"
# f"model_bool={str(settings.model_bool)}\n"
# f"model_enum={settings.model_enum}\n"
# f"batch_to_generate={str(settings.batch_to_generate)}\n"
# f"cardano_metadata_bool={str(settings.cardano_metadata_bool)}\n"
# f"cardano_description={settings.cardano_description}\n"
# f"erc721_metadata={str(settings.erc721_metadata)}\n"
# f"erc721_description={settings.erc721_description}\n"
# f"solana_metadata_bool={str(settings.solana_metadata_bool)}\n"
# f"solana_description={settings.solana_description}\n"
# f"enable_custom_fields={str(settings.enable_custom_fields)}\n"
# f"custom_fields_file={settings.custom_fields_file}\n"
# f"enable_materials={str(settings.custom_fields_file)}\n"
# f"materials_file={settings.materials_file}\n"
# )
# print(output)
args, parser = headless_util.get_python_args()
settings = bpy.context.scene.input_tool
# dumpSettings(settings)
with open(args.config_path, 'r') as f:
configs = [line.strip() for line in f.readlines() if not (line[0] == '#' or len(line.strip()) < 1)]
pairs = [config.strip().split('=') for config in configs]
# print(pairs)
settings.nft_name = pairs[0][1]
settings.collection_size = int(pairs[1][1])
settings.nfts_per_batch = int(pairs[2][1])
settings.save_path = pairs[3][1]
settings.enable_rarity = pairs[4][1] == 'True'
settings.enable_logic = pairs[5][1] == 'True'
settings.enableLogicJson = pairs[6][1] == 'True'
settings.logic_file = pairs[7][1]
settings.image_bool = pairs[8][1] == 'True'
settings.image_enum = pairs[9][1]
settings.animation_bool = pairs[10][1] == 'True'
settings.animation_enum = pairs[11][1]
settings.model_bool = pairs[12][1] == 'True'
settings.model_enum = pairs[13][1]
settings.batch_to_generate = int(pairs[14][1])
settings.cardano_metadata_bool = pairs[15][1] == 'True'
settings.cardano_description = pairs[16][1]
settings.erc721_metadata = pairs[17][1] == 'True'
settings.erc721_description = pairs[18][1]
settings.solana_metadata_bool = pairs[19][1] == 'True'
settings.solanaDescription = pairs[20][1]
settings.enable_custom_fields = pairs[21][1] == 'True'
settings.custom_fields_file = pairs[22][1]
settings.enable_materials = pairs[23][1] == 'True'
settings.materials_file = pairs[24][1]
if args.save_path:
settings.save_path = args.save_path
if args.batch_number:
settings.batch_to_generate = args.batch_number
input = get_bmnft_data()
if args.batch_data_path:
input.batch_json_save_path = args.batch_data_path
if args.operation == 'create-dna':
intermediate.send_to_record(input)
elif args.operation == 'generate-nfts':
intermediate.render_and_save_nfts(input)
elif args.operation == 'refactor-batches':
refactorer.reformat_nft_collection(input)
# ======== User input Property Group ======== #
class BMNFTS_PGT_Input_Properties(bpy.types.PropertyGroup):
# Create NFT Data Panel:
nft_name: bpy.props.StringProperty(name="NFT Name")
collection_size: bpy.props.IntProperty(
name="NFT Collection Size",
default=1,
min=1
) # max=(combinations - offset)
nfts_per_batch: bpy.props.IntProperty(
name="NFTs Per Batch",
default=1,
min=1
) # max=(combinations - offset)
save_path: bpy.props.StringProperty(
name="Save Path",
description="Save path for NFT files",
default="",
maxlen=1024,
subtype="DIR_PATH"
)
enable_rarity: bpy.props.BoolProperty(
name="Enable Rarity"
)
enable_logic: bpy.props.BoolProperty(
name="Enable Logic"
)
enable_logic_json: bpy.props.BoolProperty(
name="Use Logic.json instead"
)
logic_file: bpy.props.StringProperty(
name="Logic File Path",
description="Path where Logic.json is located.",
default="",
maxlen=1024,
subtype="FILE_PATH"
)
enable_materials: bpy.props.BoolProperty(
name="Enable Materials"
)
materials_file: bpy.props.StringProperty(
name="Materials File",
description="Path where Materials.json is located.",
default="",
maxlen=1024,
subtype="FILE_PATH"
)
# Generate NFTs Panel:
image_bool: bpy.props.BoolProperty(
name="Image"
)
image_enum: bpy.props.EnumProperty(
name="Image File Format",
description="Select Image file format",
items=[
('PNG', ".PNG", "Export NFT as PNG"),
('JPEG', ".JPEG", "Export NFT as JPEG")
]
)
animation_bool: bpy.props.BoolProperty(
name="Animation"
)
animation_enum: bpy.props.EnumProperty(
name="Animation File Format",
description="Select Animation file format",
items=[
('AVI_JPEG', '.avi (AVI_JPEG)', 'Export NFT as AVI_JPEG'),
('AVI_RAW', '.avi (AVI_RAW)', 'Export NFT as AVI_RAW'),
('FFMPEG', '.mkv (FFMPEG)', 'Export NFT as FFMPEG'),
('MP4', '.mp4', 'Export NFT as .mp4'),
('PNG', '.png', 'Export NFT as PNG'),
('TIFF', '.tiff', 'Export NFT as TIFF')
]
)
model_bool: bpy.props.BoolProperty(
name="3D Model"
)
model_enum: bpy.props.EnumProperty(
name="3D Model File Format",
description="Select 3D Model file format",
items=[
('GLB', '.glb', 'Export NFT as .glb'),
('GLTF_SEPARATE', '.gltf + .bin + textures',
'Export NFT as .gltf with separated textures in .bin + textures.'),
('GLTF_EMBEDDED', '.gltf', 'Export NFT as embedded .gltf file that contains textures.'),
('FBX', '.fbx', 'Export NFT as .fbx'),
('OBJ', '.obj', 'Export NFT as .obj'),
('X3D', '.x3d', 'Export NFT as .x3d'),
('STL', '.stl', 'Export NFT as .stl'),
('VOX', '.vox (Experimental)',
'Export NFT as .vox, requires the voxwriter add on: https://github.com/Spyduck/voxwriter')
]
)
batch_to_generate: bpy.props.IntProperty(
name="Batch To Generate",
default=1,
min=1
)
# Refactor Batches & Create Metadata Panel:
cardano_metadata_bool: bpy.props.BoolProperty(
name="Cardano Cip"
)
cardano_description: bpy.props.StringProperty(
name="Cardano description"
)
solana_metadata_bool: bpy.props.BoolProperty(
name="Solana Metaplex"
)
solana_description: bpy.props.StringProperty(
name="Solana description"
)
erc721_metadata: bpy.props.BoolProperty(
name="ERC721"
)
erc721_description: bpy.props.StringProperty(
name="ERC721 description"
)
enable_custom_fields: bpy.props.BoolProperty(
name="Enable Custom Metadata Fields"
)
custom_fields_file: bpy.props.StringProperty(
name="Custom Fields File",
description="Path where Custom_Fields.json is located.",
default="",
maxlen=1024,
subtype="FILE_PATH"
)
# Other Panel:
enable_auto_save: bpy.props.BoolProperty(
name="Auto Save Before Generation",
description="Automatically saves your Blender file when 'Generate NFTs & Create Metadata' button is clicked"
)
enable_auto_shutdown: bpy.props.BoolProperty(
name="Auto Shutdown",
description="Automatically shuts down your computer after a Batch is finished Generating"
)
specify_time_bool: bpy.props.BoolProperty(
name="Shutdown in a Given Amount of Time",
description="Wait a given amount of time after a Batch is generated before Automatic Shutdown"
)
hours: bpy.props.IntProperty(
default=0, min=0
)
minutes: bpy.props.IntProperty(
default=0, min=0
)
email_notification_bool: bpy.props.BoolProperty(
name="Email Notifications",
description="Receive Email Notifications from Blender once a batch is finished generating"
)
sender_from: bpy.props.StringProperty(
name="From",
default="[email protected]"
)
email_password: bpy.props.StringProperty(
name="Password",
subtype='PASSWORD'
)
receiver_to: bpy.props.StringProperty(
name="To",
default="[email protected]"
)
enable_debug: bpy.props.BoolProperty(
name="Enable Debug Mode",
description="Allows you to run Blend_My_NFTs without generating any content files and enables debugging "
"console messages saved to a BMNFTs_Log.txt file."
)
order_num_offset: bpy.props.IntProperty(
default=0, min=0
)
log_path: bpy.props.StringProperty(
name="Debug Log Path",
description="Path where BMNFT_Log.txt is located.",
default="",
maxlen=1024,
subtype="FILE_PATH"
)
enable_dry_run: bpy.props.BoolProperty(
name="Enable Dry Run",
description="Allows you to run Blend_My_NFTs without generating any content files."
)
# API Panel properties:
api_key: bpy.props.StringProperty(
name="API Key",
subtype='PASSWORD'
) # Test code for future features
# ======== Main Operators ======== #
class CreateData(bpy.types.Operator):
bl_idname = 'create.data'
bl_label = 'Create Data'
bl_description = 'Creates NFT Data. Run after any changes were made to scene. All previous data will be ' \
'overwritten and cannot be recovered.'
bl_options = {"REGISTER", "UNDO"}
reverse_order: BoolProperty(
default=False,
name="Reverse Order")
def execute(self, context):
helpers.activate_logging()
# Handling Custom Fields UIList input:
input = get_bmnft_data()
if input.enable_logic:
if input.enable_logic_json and not input.logic_file:
self.report({'ERROR'},
f"No Logic.json file path set. Please set the file path to your Logic.json file.")
intermediate.send_to_record(input)
self.report({'INFO'}, f"NFT Data created!")
return {"FINISHED"}
def invoke(self, context, event):
return context.window_manager.invoke_confirm(self, event)
class ExportNFTs(bpy.types.Operator):
bl_idname = 'exporter.nfts'
bl_label = 'Export NFTs'
bl_description = 'Generate and export a given batch of NFTs.'
bl_options = {"REGISTER", "UNDO"}
reverse_order: BoolProperty(
default=False,
name="Reverse Order")
def execute(self, context):
helpers.activate_logging()
input = get_bmnft_data()
intermediate.render_and_save_nfts(input)
self.report({'INFO'}, f"All NFTs generated for batch {input.batch_to_generate}!")
return {"FINISHED"}
class ResumeFailedBatch(bpy.types.Operator):
bl_idname = 'exporter.resume_nfts'
bl_label = 'Resume Failed Batch'
bl_description = 'Failed Batch detected. Generate NFTs where the previous batch failed?'
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
helpers.activate_logging()
_save_path = bpy.path.abspath(bpy.context.scene.input_tool.save_path)
_Blend_My_NFTs_Output, _batch_json_save_path, _nftBatch_save_path = make_directories(_save_path)
_batchToGenerate = bpy.context.scene.input_tool.batch_to_generate
file_name = os.path.join(_batch_json_save_path, "Batch{}.json".format(_batchToGenerate))
batch_data = json.load(open(file_name))
_fail_state, _failed_batch, _failed_dna, _failed_dna_index = helpers.check_failed_batches(_batch_json_save_path)
render_settings = batch_data["Generation Save"][-1]["Render_Settings"]
input = BMNFTData(
nft_name=render_settings["nft_name"],
save_path=_save_path,
nfts_per_batch=render_settings["nfts_per_batch"],
batch_to_generate=render_settings["batch_to_generate"],
collection_size=render_settings["collection_size"],
blend_my_nfts_output=_Blend_My_NFTs_Output,
batch_json_save_path=_batch_json_save_path,
nft_batch_save_path=render_settings["nft_batch_save_path"],
enable_images=render_settings["enable_images"],
image_file_format=render_settings["image_file_format"],
enable_animations=render_settings["enable_animations"],
animation_file_format=render_settings["animation_file_format"],
enable_models=render_settings["enable_models"],
model_file_format=render_settings["model_file_format"],
enable_custom_fields=render_settings["enable_custom_fields"],
cardano_metadata_bool=render_settings["cardano_metadata_bool"],
solana_metadata_bool=render_settings["solana_metadata_bool"],
erc721_metadata=render_settings["erc721_metadata"],
cardano_description=render_settings["cardano_description"],
solana_description=render_settings["solana_description"],
erc721_description=render_settings["erc721_description"],
enable_materials=render_settings["enable_materials"],
materials_file=render_settings["materials_file"],
enable_logic=render_settings["enable_logic"],
enable_logic_json=render_settings["enable_logic_json"],
logic_file=render_settings["logic_file"],
enable_rarity=render_settings["enable_rarity"],
enable_auto_shutdown=render_settings["enable_auto_shutdown"],
specify_time_bool=render_settings["specify_time_bool"],
hours=render_settings["hours"],
minutes=render_settings["minutes"],
email_notification_bool=render_settings["email_notification_bool"],
sender_from=render_settings["sender_from"],
email_password=render_settings["email_password"],
receiver_to=render_settings["receiver_to"],
enable_debug=render_settings["enable_debug"],
order_num_offset=render_settings["order_num_offset"],
log_path=render_settings["log_path"],
enable_dry_run=render_settings["enable_dry_run"],
fail_state=_fail_state,
failed_batch=_failed_batch,
failed_dna=_failed_dna,
failed_dna_index=_failed_dna_index,
custom_fields=render_settings["custom_fields"],
)
exporter.render_and_save_nfts(input)
self.report({'INFO'}, f"Resuming Failed Batch Generation!")
return {"FINISHED"}
class RefactorBatches(bpy.types.Operator):
"""Refactor your collection? This action cannot be undone."""
bl_idname = 'refactor.batches'
bl_label = 'Refactor your Batches?'
bl_description = 'This action cannot be undone.'
bl_options = {'REGISTER', 'INTERNAL'}
reverse_order: BoolProperty(
default=False,
name="Reverse Order")
def execute(self, context):
helpers.activate_logging()
refactorer.reformat_nft_collection(get_bmnft_data())
return {"FINISHED"}
def invoke(self, context, event):
return context.window_manager.invoke_confirm(self, event)
class ExportSettings(bpy.types.Operator):
"""Export your settings into a configuration file."""
bl_idname = 'export.settings'
bl_label = 'Export Settings'
bl_description = 'Save your settings to a configuration file'
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
helpers.activate_logging()
save_path = bpy.path.abspath(bpy.context.scene.input_tool.save_path)
filename = "config.cfg"
settings = bpy.context.scene.input_tool
with open(save_path + filename, 'w') as config:
output = (
"#This file was auto-generated from the Blend_My_NFTs addon and is used\n"
"#when running Blend_My_NFTs in a headless environment.\n"
"\n"
"#The name of your nft project\n"
f"nft_name={settings.nft_name}\n"
"\n"
"#NFT Collection Size\n"
f"collection_size={settings.collection_size}\n"
"\n"
"#The number of NFTs to generate per batch\n"
f"nfts_per_batch={str(settings.nfts_per_batch)}\n"
"\n"
"#Save path for your NFT files\n"
f"save_path={settings.save_path}\n"
"\n"
"#Enable Rarity\n"
f"enable_rarity={settings.enable_rarity}\n"
"\n"
"#Enable Logic\n"
f"enable_logic={str(settings.enable_logic)}\n"
f"enableLogicJson={str(settings.enable_logic_json)}\n"
f"logicFilePath={settings.logic_file}\n"
"\n"
"#NFT Media output type(s):\n"
f"image_bool={str(settings.image_bool)}\n"
f"image_enum={settings.image_enum}\n"
f"animation_bool={str(settings.animation_bool)}\n"
f"animation_enum={settings.animation_enum}\n"
f"model_bool={str(settings.model_bool)}\n"
f"model_enum={settings.model_enum}\n"
"\n"
"#Batch to generate\n"
f"batch_to_generate={str(settings.batch_to_generate)}\n"
"\n"
"#Metadata Format\n"
f"cardano_metadata_bool={str(settings.cardano_metadata_bool)}\n"
f"cardano_description={settings.cardano_description}\n"
f"erc721_metadata={str(settings.erc721_metadata)}\n"
f"erc721_description={settings.erc721_description}\n"
f"solana_metadata_bool={str(settings.solana_metadata_bool)}\n"
f"solana_description={settings.solana_description}\n"
"\n"
"#Enable Custom Fields\n"
f"enable_custom_fields={str(settings.enable_custom_fields)}\n"
f"custom_fields_file={settings.custom_fields_file}\n"
"\n"
"#Enable Materials\n"
f"enable_materials={str(settings.enable_materials)}\n"
f"materials_file={settings.materials_file}\n"
)
print(output, file=config)
self.report({'INFO'}, f"Saved settings to: {save_path + filename}!")
return {"FINISHED"}
# ======== UI Panels ======== #
class BMNFTS_PT_CreateData(bpy.types.Panel):
bl_label = "Create NFT Data"
bl_idname = "BMNFTS_PT_CreateData"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'Blend_My_NFTs'
def draw(self, context):
layout = self.layout
scene = context.scene
input_tool_scene = scene.input_tool
row = layout.row()
row.prop(input_tool_scene, "nft_name")
row = layout.row()
layout.label(text=f"Maximum Number Of NFTs: {combinations}")
layout.label(text=f"Recommended limit: {recommended_limit}")
row = layout.row()
row.prop(input_tool_scene, "collection_size")
row = layout.row()
row.prop(input_tool_scene, "nfts_per_batch")
row = layout.row()
row.prop(input_tool_scene, "save_path")
row = layout.row()
row.prop(input_tool_scene, "enable_rarity")
row = layout.row()
row.prop(input_tool_scene, "enable_logic")
# Logic_UIList implementation:
if bpy.context.scene.input_tool.enable_logic:
layout = self.layout
scn = bpy.context.scene
rows = 2
row = layout.row()
row.template_list("CUSTOM_UL_logic_items", "", scn, "logic_fields", scn,
"logic_fields_index", rows=rows)
col = row.column(align=True)
col.operator("logic_uilist.logic_list_action", icon='ZOOM_IN', text="").action = 'ADD'
col.operator("logic_uilist.logic_list_action", icon='ZOOM_OUT', text="").action = 'REMOVE'
col.separator()
col.operator("logic_uilist.logic_list_action", icon='TRIA_UP', text="").action = 'UP'
col.operator("logic_uilist.logic_list_action", icon='TRIA_DOWN', text="").action = 'DOWN'
row = layout.row()
col = row.column(align=True)
row = col.row(align=True)
row.operator("logic_uilist.logic_clear_list", icon="X")
row = col.row(align=True)
row.label(text=f"*Field Names must be unique.")
row = layout.row()
row.prop(input_tool_scene, "enable_logic_json")
if bpy.context.scene.input_tool.enable_logic_json:
row = layout.row()
row.prop(input_tool_scene, "logic_file")
row = layout.row()
row.prop(input_tool_scene, "enable_materials")
if bpy.context.scene.input_tool.enable_materials:
row = layout.row()
row.prop(input_tool_scene, "materials_file")
row = layout.row()
self.layout.operator("create.data", icon='DISCLOSURE_TRI_RIGHT', text="Create Data")
row = layout.row()
layout.label(text=f"{BMNFTS_VERSION}")
class BMNFTS_PT_GenerateNFTs(bpy.types.Panel):
bl_label = "Generate NFTs & Create Metadata"
bl_idname = "BMNFTS_PT_GenerateNFTs"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'Blend_My_NFTs'
def draw(self, context):
layout = self.layout
scene = context.scene
input_tool_scene = scene.input_tool
row = layout.row()
layout.label(text="NFT Media files:")
row = layout.row()
row.prop(input_tool_scene, "image_bool")
if bpy.context.scene.input_tool.image_bool:
row.prop(input_tool_scene, "image_enum")
row = layout.row()
row.prop(input_tool_scene, "animation_bool")
if bpy.context.scene.input_tool.animation_bool:
row.prop(input_tool_scene, "animation_enum")
row = layout.row()
row.prop(input_tool_scene, "model_bool")
if bpy.context.scene.input_tool.model_bool:
row.prop(input_tool_scene, "model_enum")
row = layout.row()
layout.label(text="Meta Data format:")
row = layout.row()
row.prop(input_tool_scene, "cardano_metadata_bool")
if bpy.context.scene.input_tool.cardano_metadata_bool:
row = layout.row()
row.prop(input_tool_scene, "cardano_description")
row = layout.row()
row.operator("wm.url_open", text="Cardano Metadata Documentation",
icon='URL').url = "https://cips.cardano.org/cips/cip25/"
row = layout.row()
row.prop(input_tool_scene, "solana_metadata_bool")
if bpy.context.scene.input_tool.solana_metadata_bool:
row = layout.row()
row.prop(input_tool_scene, "solana_description")
row = layout.row()
row.operator("wm.url_open", text="Solana Metadata Documentation",
icon='URL').url = "https://docs.metaplex.com/token-metadata/specification"
row = layout.row()
row.prop(input_tool_scene, "erc721_metadata")
if bpy.context.scene.input_tool.erc721_metadata:
row = layout.row()
row.prop(input_tool_scene, "erc721_description")
row = layout.row()
row.operator("wm.url_open", text="ERC721 Metadata Documentation",
icon='URL').url = "https://docs.opensea.io/docs/metadata-standards"
row = layout.row()
row.prop(input_tool_scene, "enable_custom_fields")
# Custom Metadata Fields UIList:
if bpy.context.scene.input_tool.enable_custom_fields:
layout = self.layout
scn = bpy.context.scene
rows = 2
row = layout.row()
row.template_list("CUSTOM_UL_custom_metadata_fields_items", "", scn, "custom_metadata_fields", scn,
"custom_metadata_fields_index", rows=rows)
col = row.column(align=True)
col.operator("custom_metadata_fields_uilist.list_action", icon='ZOOM_IN', text="").action = 'ADD'
col.operator("custom_metadata_fields_uilist.list_action", icon='ZOOM_OUT', text="").action = 'REMOVE'
col.separator()
col.operator("custom_metadata_fields_uilist.list_action", icon='TRIA_UP', text="").action = 'UP'
col.operator("custom_metadata_fields_uilist.list_action", icon='TRIA_DOWN', text="").action = 'DOWN'
row = layout.row()
col = row.column(align=True)
row = col.row(align=True)
row.label(text=f"*Field Names must be unique.")
row = col.row(align=True)
row.operator("custom_metadata_fields_uilist.clear_list", icon="X")
row = layout.row()
row.prop(input_tool_scene, "batch_to_generate")
save_path = bpy.path.abspath(bpy.context.scene.input_tool.save_path)
Blend_My_NFTs_Output = os.path.join(save_path, "Blend_My_NFTs Output", "NFT_Data")
batch_json_save_path = os.path.join(Blend_My_NFTs_Output, "Batch_Data")
nftBatch_save_path = os.path.join(save_path, "Blend_My_NFTs Output", "Generated NFT Batches")
fail_state, failed_batch, failed_dna, failed_dna_index = helpers.check_failed_batches(batch_json_save_path)
if fail_state:
row = layout.row()
self.layout.operator("exporter.nfts", icon='RENDER_RESULT', text="Generate NFTs & Create Metadata")