2022-07-14 14:02:05 +00:00
|
|
|
import bpy
|
2022-08-24 17:04:20 +00:00
|
|
|
import json
|
2022-07-01 04:36:07 +00:00
|
|
|
|
2022-08-24 15:49:09 +00:00
|
|
|
from main import dna_generator, exporter
|
2022-07-14 14:02:05 +00:00
|
|
|
|
2022-08-24 17:04:20 +00:00
|
|
|
# TODO: migrate this code to the exporter.py to simplify render process into one file.
|
|
|
|
|
2022-07-14 14:02:25 +00:00
|
|
|
|
2022-08-24 17:04:20 +00:00
|
|
|
def send_to_record(input, reverse_order=False):
|
|
|
|
if input.enable_logic:
|
|
|
|
if input.enable_logic_json and input.logic_file:
|
|
|
|
input.logic_file = json.load(open(input.logic_file))
|
2022-07-14 14:02:25 +00:00
|
|
|
|
2022-08-24 17:04:20 +00:00
|
|
|
if input.enable_logic_json and not input.logic_file:
|
2022-07-14 14:02:25 +00:00
|
|
|
print({'ERROR'}, f"No Logic.json file path set. Please set the file path to your Logic.json file.")
|
|
|
|
|
2022-08-24 17:04:20 +00:00
|
|
|
if not input.enable_logic_json:
|
2022-07-14 14:02:25 +00:00
|
|
|
scn = bpy.context.scene
|
|
|
|
if reverse_order:
|
2022-08-24 17:04:20 +00:00
|
|
|
input.logic_file = {}
|
2022-07-14 14:02:25 +00:00
|
|
|
num = 1
|
|
|
|
for i in range(scn.logic_fields_index, -1, -1):
|
|
|
|
item = scn.logic_fields[i]
|
|
|
|
|
|
|
|
item_list1 = item.item_list1
|
|
|
|
rule_type = item.rule_type
|
|
|
|
item_list2 = item.item_list2
|
2022-08-24 17:04:20 +00:00
|
|
|
input.logic_file[f"Rule-{num}"] = {
|
2022-08-11 13:48:01 +00:00
|
|
|
"IF": item_list1.split(','),
|
|
|
|
rule_type: item_list2.split(',')
|
2022-07-14 14:02:25 +00:00
|
|
|
}
|
|
|
|
num += 1
|
|
|
|
else:
|
2022-08-24 17:04:20 +00:00
|
|
|
input.logic_file = {}
|
2022-07-14 14:02:25 +00:00
|
|
|
num = 1
|
|
|
|
for item in scn.logic_fields:
|
|
|
|
item_list1 = item.item_list1
|
|
|
|
rule_type = item.rule_type
|
|
|
|
item_list2 = item.item_list2
|
2022-08-24 17:04:20 +00:00
|
|
|
input.logic_file[f"Rule-{num}"] = {
|
2022-08-11 13:48:01 +00:00
|
|
|
"IF": item_list1.split(','),
|
|
|
|
rule_type: item_list2.split(',')
|
2022-07-14 14:02:25 +00:00
|
|
|
}
|
|
|
|
num += 1
|
2022-07-14 14:02:05 +00:00
|
|
|
|
2022-08-24 17:04:20 +00:00
|
|
|
dna_generator.send_to_record(
|
|
|
|
input.collection_size,
|
|
|
|
input.nfts_per_batch,
|
|
|
|
input.save_path,
|
|
|
|
input.enable_rarity,
|
|
|
|
input.enable_logic,
|
|
|
|
input.logic_file,
|
|
|
|
input.enable_materials,
|
|
|
|
input.materials_file,
|
|
|
|
input.blend_my_nfts_output,
|
|
|
|
input.batch_json_save_path,
|
|
|
|
input.enable_debug,
|
2022-08-25 13:41:22 +00:00
|
|
|
input.log_path
|
2022-08-24 17:04:20 +00:00
|
|
|
)
|
2022-08-11 13:48:01 +00:00
|
|
|
|
2022-07-14 14:02:05 +00:00
|
|
|
|
2022-08-24 17:04:20 +00:00
|
|
|
def render_and_save_nfts(input, reverse_order=False):
|
|
|
|
if input.enable_custom_fields:
|
2022-07-14 14:02:25 +00:00
|
|
|
scn = bpy.context.scene
|
|
|
|
if reverse_order:
|
|
|
|
for i in range(scn.custom_metadata_fields_index, -1, -1):
|
|
|
|
item = scn.custom_metadata_fields[i]
|
2022-08-24 17:04:20 +00:00
|
|
|
if item.field_name in list(input.custom_fields.keys()):
|
2022-08-11 13:48:01 +00:00
|
|
|
raise ValueError(
|
2022-08-24 17:04:20 +00:00
|
|
|
f"A duplicate of '{item.field_name}' was found. Please ensure all Custom Metadata field Names "
|
|
|
|
f"are unique."
|
|
|
|
)
|
2022-07-14 14:02:25 +00:00
|
|
|
else:
|
2022-08-24 17:04:20 +00:00
|
|
|
input.custom_fields[item.field_name] = item.field_value
|
2022-07-14 14:02:25 +00:00
|
|
|
else:
|
|
|
|
for item in scn.custom_metadata_fields:
|
2022-08-24 17:04:20 +00:00
|
|
|
if item.field_name in list(input.custom_fields.keys()):
|
2022-08-11 13:48:01 +00:00
|
|
|
raise ValueError(
|
2022-08-24 17:04:20 +00:00
|
|
|
f"A duplicate of '{item.field_name}' was found. Please ensure all Custom Metadata field Names "
|
|
|
|
f"are unique."
|
|
|
|
)
|
2022-07-14 14:02:25 +00:00
|
|
|
else:
|
2022-08-24 17:04:20 +00:00
|
|
|
input.custom_fields[item.field_name] = item.field_value
|
2022-07-14 14:02:25 +00:00
|
|
|
|
2022-08-24 17:04:20 +00:00
|
|
|
exporter.render_and_save_nfts(input)
|