kopia lustrzana https://github.com/torrinworx/Blend_My_NFTs
Cleaning things up
rodzic
c4bd40ae19
commit
417c8f0ebc
|
@ -5,7 +5,6 @@
|
|||
import bpy
|
||||
import os
|
||||
import sys
|
||||
import timeit
|
||||
import json
|
||||
import random
|
||||
import importlib
|
||||
|
@ -18,64 +17,59 @@ from src import config
|
|||
|
||||
importlib.reload(config)
|
||||
|
||||
|
||||
if config.runPreview:
|
||||
config.nftsPerBatch = config.maxNFTsTest
|
||||
config.maxNFTs = config.maxNFTsTest
|
||||
config.renderBatch = 1
|
||||
config.nftName = "TestImages"
|
||||
config.nftsPerBatch = config.maxNFTsTest
|
||||
config.maxNFTs = config.maxNFTsTest
|
||||
config.renderBatch = 1
|
||||
config.nftName = "TestImages"
|
||||
|
||||
|
||||
def makeBatches():
|
||||
file_name = os.path.join(config.save_path, "NFTRecord.json")
|
||||
DataDictionary = json.load(open(file_name))
|
||||
|
||||
file_name = os.path.join(config.save_path, "NFTRecord.json")
|
||||
DataDictionary = json.load(open(file_name))
|
||||
numNFTsGenerated = DataDictionary["numNFTsGenerated"]
|
||||
hierarchy = DataDictionary["hierarchy"]
|
||||
DNAList = DataDictionary["DNAList"]
|
||||
|
||||
numNFTsGenerated = DataDictionary["numNFTsGenerated"]
|
||||
hierarchy = DataDictionary["hierarchy"]
|
||||
DNAList = DataDictionary["DNAList"]
|
||||
numBatches = config.maxNFTs / config.nftsPerBatch
|
||||
|
||||
numBatches = config.maxNFTs/config.nftsPerBatch
|
||||
print(f"To generate batches of {config.nftsPerBatch} DNA sequences per batch, with a total of {numNFTsGenerated}"
|
||||
f" possible NFT DNA sequences, the number of batches generated will be {numBatches}")
|
||||
|
||||
print("To generate batches of " + str(config.nftsPerBatch) + " DNA sequences per batch, with a total of " +
|
||||
str(numNFTsGenerated) + " possible NFT DNA sequences, the number of batches generated will be " + str(numBatches))
|
||||
i = 0
|
||||
while i < numBatches:
|
||||
batchDictionary = {}
|
||||
BatchDNAList = []
|
||||
|
||||
i = 0
|
||||
while i < numBatches:
|
||||
batchDictionary = {}
|
||||
BatchDNAList = []
|
||||
j = 0
|
||||
while (j < config.nftsPerBatch) and (DNAList):
|
||||
oneDNA = random.choice(DNAList)
|
||||
BatchDNAList.append(oneDNA)
|
||||
DNAList.remove(oneDNA)
|
||||
j += 1
|
||||
|
||||
j = 0
|
||||
while (j < config.nftsPerBatch) and (DNAList):
|
||||
oneDNA = random.choice(DNAList)
|
||||
BatchDNAList.append(oneDNA)
|
||||
DNAList.remove(oneDNA)
|
||||
j += 1
|
||||
batchDictionary["NFTs_in_Batch"] = int(len(BatchDNAList))
|
||||
batchDictionary["hierarchy"] = hierarchy
|
||||
batchDictionary["BatchDNAList"] = BatchDNAList
|
||||
|
||||
batchDictionary["NFTs_in_Batch"] = int(len(BatchDNAList))
|
||||
batchDictionary["hierarchy"] = hierarchy
|
||||
batchDictionary["BatchDNAList"] = BatchDNAList
|
||||
batchDictionaryObject = json.dumps(batchDictionary, indent=1, ensure_ascii=True)
|
||||
|
||||
batchDictionaryObject = json.dumps(batchDictionary, indent=1, ensure_ascii=True)
|
||||
with open(os.path.join(config.batch_json_save_path, ("Batch{}.json".format(i + 1))), "w") as outfile:
|
||||
outfile.write(batchDictionaryObject)
|
||||
|
||||
with open(os.path.join(config.batch_json_save_path, ("Batch{}.json".format(i + 1))), "w") as outfile:
|
||||
outfile.write(batchDictionaryObject)
|
||||
i += 1
|
||||
|
||||
i += 1
|
||||
if len(DNAList) > 0:
|
||||
print(f"One batch could not be filled completely and will contain {len(DNAList)} NFTs.")
|
||||
|
||||
if len(DNAList) > 0:
|
||||
print("One batch could not be filled completely and will contain " + str(len(DNAList)) + " NFTs.")
|
||||
incompleteBatch = {"NFTs_in_Batch": int(len(DNAList)), "hierarchy": hierarchy, "BatchDNAList": DNAList}
|
||||
|
||||
incompleteBatch = {}
|
||||
incompleteBatch = json.dumps(incompleteBatch, indent=1, ensure_ascii=True)
|
||||
|
||||
incompleteBatch["NFTs_in_Batch"] = int(len(DNAList))
|
||||
incompleteBatch["hierarchy"] = hierarchy
|
||||
incompleteBatch["BatchDNAList"] = DNAList
|
||||
incompleteBatch["hierarchy"] = hierarchy
|
||||
with open(os.path.join(config.batch_json_save_path, ("Batch{}.json".format(i + 1))), "w") as outfile2:
|
||||
outfile2.write(incompleteBatch)
|
||||
|
||||
incompleteBatch = json.dumps(incompleteBatch, indent=1, ensure_ascii=True)
|
||||
|
||||
with open(os.path.join(config.batch_json_save_path, ("Batch{}.json".format(i + 1))), "w") as outfile2:
|
||||
outfile2.write(incompleteBatch)
|
||||
|
||||
if __name__ == '__main__':
|
||||
makeBatches()
|
||||
makeBatches()
|
||||
|
|
|
@ -56,8 +56,8 @@ def returnData():
|
|||
try:
|
||||
scriptIgnore = bpy.data.collections["Script_Ignore"]
|
||||
except:
|
||||
print(bcolors.ERROR + "ERROR:\nScript_Ignore collection is not in .blend file scene. Please add the Script_Ignore collection to your "
|
||||
".blend file scene. For more information, read the README.md file.\n"+ bcolors.RESET)
|
||||
print(f"{bcolors.ERROR} ERROR:\nScript_Ignore collection is not in .blend file scene. Please add the Script_Ignore collection to your "
|
||||
f".blend file scene. For more information, read the README.md file.\n {bcolors.RESET}")
|
||||
|
||||
listAllCollInScene = []
|
||||
listAllCollections = []
|
||||
|
@ -138,25 +138,25 @@ def returnData():
|
|||
attributeCollections1 = copy.deepcopy(attributeCollections)
|
||||
|
||||
def attributeData(attributeVariants):
|
||||
'''
|
||||
"""
|
||||
Creates a dictionary of each attribute
|
||||
'''
|
||||
"""
|
||||
allAttDataList = {}
|
||||
count = 0
|
||||
previousAttribute = ""
|
||||
for i in attributeVariants:
|
||||
|
||||
def getName(i):
|
||||
'''
|
||||
"""
|
||||
Returns the name of "i" attribute variant
|
||||
'''
|
||||
"""
|
||||
name = i.split("_")[0]
|
||||
return name
|
||||
|
||||
def getOrder_rarity(i):
|
||||
'''
|
||||
"""
|
||||
Returns the "order", "rarity" and "color" (if enabled) of i attribute variant in a list
|
||||
'''
|
||||
"""
|
||||
x = re.sub(r'[a-zA-Z]', "", i)
|
||||
a = x.split("_")
|
||||
del a[0]
|
||||
|
@ -166,8 +166,8 @@ def returnData():
|
|||
orderRarity = getOrder_rarity(i)
|
||||
|
||||
if len(orderRarity) == 0:
|
||||
print(bcolors.ERROR + "\nERROR:" + bcolors.RESET)
|
||||
print("The collection " + str(i) + " doesn't follow the naming conventions of attributes. Please move this \n"
|
||||
print(f"{bcolors.ERROR} \nERROR: {bcolors.RESET}")
|
||||
print(f"The collection {i} doesn't follow the naming conventions of attributes. Please move this \n"
|
||||
"colleciton to Script_Ignore or review proper collection format in README.md")
|
||||
return
|
||||
|
||||
|
@ -194,18 +194,18 @@ def returnData():
|
|||
variantMetaData = attributeData(attributeVariants)
|
||||
|
||||
def getHierarchy():
|
||||
'''
|
||||
"""
|
||||
Constructs the hierarchy dictionary from attributeCollections1 and variantMetaData.
|
||||
'''
|
||||
"""
|
||||
hierarchy = {}
|
||||
for i in attributeCollections1:
|
||||
colParLong = list(bpy.data.collections[str(i)].children)
|
||||
colParShort = {}
|
||||
for x in colParLong:
|
||||
if config.enableGeneration:
|
||||
'''
|
||||
"""
|
||||
Append colors to blender name for PNG generator and NFTRecord.json to create the correct list
|
||||
'''
|
||||
"""
|
||||
if x.name in config.colorList:
|
||||
for j in range(len(config.colorList[x.name])):
|
||||
colParShort[x.name + "_" + str(j+1)] = None
|
||||
|
@ -226,9 +226,9 @@ def returnData():
|
|||
hierarchy = getHierarchy()
|
||||
|
||||
def numOfCombinations(hierarchy):
|
||||
'''
|
||||
"""
|
||||
Returns "combinations" the number of all possible NFT combinations.
|
||||
'''
|
||||
"""
|
||||
|
||||
hierarchyByNum = []
|
||||
|
||||
|
@ -237,11 +237,9 @@ def returnData():
|
|||
if len(hierarchy[i]) != 0:
|
||||
hierarchyByNum.append(len(hierarchy[i]))
|
||||
else:
|
||||
print("The following collection has been identified as empty:")
|
||||
print(i)
|
||||
print(f"The following collection has been identified as empty: {i}")
|
||||
|
||||
combinations = 1
|
||||
|
||||
for i in hierarchyByNum:
|
||||
combinations = combinations*i
|
||||
|
||||
|
@ -249,25 +247,20 @@ def returnData():
|
|||
numBatches = combinations/config.nftsPerBatch
|
||||
|
||||
except:
|
||||
print(bcolors.ERROR + "ERROR:\nnftsPerBatch in config.py needs to be a positive integer." + bcolors.RESET)
|
||||
print(f"{bcolors.ERROR} ERROR:\nnftsPerBatch in config.py needs to be a positive integer. {bcolors.RESET}")
|
||||
|
||||
if combinations == 0:
|
||||
print(bcolors.ERROR + "\nERROR:" + bcolors.RESET)
|
||||
print("The number of all possible combinations is equal to 0. Please review your collection hierarchy \n "
|
||||
"and ensure it is formatted correctly.")
|
||||
print("Please review README.md for more information.")
|
||||
print("")
|
||||
print("Here is the hierarchy of all collections the DNA_Generator gathered from your .blend file, excluding "
|
||||
"\nthose in Script_Ignore:")
|
||||
print(hierarchy)
|
||||
print("The number of all possible combinations is equal to 0. Please review your collection hierarchy"
|
||||
"and ensure it is formatted correctly. Please review README.md for more information. \nHere is the "
|
||||
"hierarchy of all collections the DNA_Generator gathered from your .blend file, excluding those in "
|
||||
f"Script_Ignore: {hierarchy}")
|
||||
|
||||
if numBatches < 1:
|
||||
print(bcolors.ERROR + "ERROR:" + bcolors.RESET)
|
||||
print("The number of NFTs Per Batch (nftsPerBatch variable in config.py) is to high.")
|
||||
print("There are a total of " + str(combinations) + " possible NFT combinations and you've requested "
|
||||
+ str(config.nftsPerBatch) + " NFTs per batch.")
|
||||
print("Lower the number of NFTs per batch in config.py or increase the number of \nattributes and/or variants"
|
||||
" in your .blend file.")
|
||||
print(f"{bcolors.ERROR} ERROR: {bcolors.RESET}")
|
||||
print("The number of NFTs Per Batch (nftsPerBatch variable in config.py) is to high. There are a total of "
|
||||
f" {combinations} possible NFT combinations and you've requested {config.nftsPerBatch} NFTs per batch. "
|
||||
f"Lower the number of NFTs per batch in config.py or increase the number of attributes and/or variants in your .blend file.")
|
||||
|
||||
return combinations
|
||||
|
||||
|
@ -276,9 +269,9 @@ def returnData():
|
|||
for i in variantMetaData:
|
||||
def cameraToggle(i, toggle=True):
|
||||
if config.enableGeneration:
|
||||
'''
|
||||
"""
|
||||
Remove Color code so blender recognises the collection
|
||||
'''
|
||||
"""
|
||||
i = stripColorFromName(i)
|
||||
bpy.data.collections[i].hide_render = toggle
|
||||
bpy.data.collections[i].hide_viewport = toggle
|
||||
|
@ -287,9 +280,9 @@ def returnData():
|
|||
return listAllCollections, attributeCollections, attributeCollections1, hierarchy, possibleCombinations
|
||||
|
||||
def generateNFT_DNA():
|
||||
'''
|
||||
Returns batchDataDictionary containing the number of NFT cominations, hierarchy, and the DNAList.
|
||||
'''
|
||||
"""
|
||||
Returns batchDataDictionary containing the number of NFT combinations, hierarchy, and the DNAList.
|
||||
"""
|
||||
|
||||
listAllCollections, attributeCollections, attributeCollections1, hierarchy, possibleCombinations = returnData()
|
||||
|
||||
|
@ -336,10 +329,10 @@ def generateNFT_DNA():
|
|||
|
||||
if config.nftsPerBatch > config.maxNFTs:
|
||||
print(bcolors.WARNING + "\nWARNING:" + bcolors.RESET)
|
||||
print("The Max num of NFTs you chose is smaller than the NFTs Per Batch you set. Only " + str(config.maxNFTs) + " were added to 1 batch")
|
||||
print(f"The Max num of NFTs you chose is smaller than the NFTs Per Batch you set. Only {config.maxNFTs} were added to 1 batch")
|
||||
|
||||
if config.enableRarity:
|
||||
print(bcolors.OK + "Rarity is on. Weights listed in .blend will be taken into account " + bcolors.RESET)
|
||||
print(f"{bcolors.OK} Rarity is on. Weights listed in .blend will be taken into account {bcolors.RESET}")
|
||||
possibleCombinations = config.maxNFTs
|
||||
DNAList = Rarity_Sorter.sortRarityWeights(hierarchy, listOptionVariant, DNAList)
|
||||
|
||||
|
@ -358,12 +351,12 @@ def generateNFT_DNA():
|
|||
return DataDictionary, possibleCombinations, DNAList
|
||||
|
||||
def send_To_Record_JSON():
|
||||
'''
|
||||
"""
|
||||
Creates NFTRecord.json file and sends "batchDataDictionary" to it. NFTRecord.json is a permanent record of all DNA
|
||||
you've generated with all attribute variants. If you add new variants or attributes to your .blend file, other scripts
|
||||
need to reference this .json file to generate new DNA and make note of the new attributes and variants to prevent
|
||||
repeate DNA.
|
||||
'''
|
||||
"""
|
||||
|
||||
DataDictionary, possibleCombinations, DNAList = generateNFT_DNA()
|
||||
|
||||
|
@ -371,10 +364,11 @@ def send_To_Record_JSON():
|
|||
ledger = json.dumps(DataDictionary, indent=1, ensure_ascii=True)
|
||||
with open(os.path.join(config.save_path, "NFTRecord.json"), 'w') as outfile:
|
||||
outfile.write(ledger + '\n')
|
||||
print(bcolors.OK + f"{len(DNAList)} NFT DNA sent to NFTRecord.json in %.4f seconds.\n" % (time.time() - time_start) + bcolors.RESET)
|
||||
print(f"{bcolors.OK}{len(DNAList)} NFT DNA sent to NFTRecord.json in %.4f seconds.\n" % (time.time() - time_start) + bcolors.RESET)
|
||||
|
||||
except:
|
||||
print(bcolors.ERROR + "ERROR:\nNFT DNA not sent to NFTRecord.json.\n" + bcolors.RESET)
|
||||
print(f"{bcolors.ERROR} ERROR:\nNFT DNA not sent to NFTRecord.json.\n {bcolors.RESET}")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
stripColorFromName()
|
||||
|
|
|
@ -39,9 +39,9 @@ def stripColorFromName(name):
|
|||
return "_".join(name.split("_")[:-1])
|
||||
|
||||
def getBatchData():
|
||||
'''
|
||||
"""
|
||||
Retrieves a given batches data determined by renderBatch in config.py
|
||||
'''
|
||||
"""
|
||||
|
||||
file_name = os.path.join(config.batch_json_save_path, "Batch{}.json".format(config.renderBatch))
|
||||
batch = json.load(open(file_name))
|
||||
|
@ -53,10 +53,10 @@ def getBatchData():
|
|||
return NFTs_in_Batch, hierarchy, BatchDNAList
|
||||
|
||||
def render_and_save_NFTs():
|
||||
'''
|
||||
"""
|
||||
Renders the NFT DNA in a Batch#.json, where # is renderBatch in config.py. Turns off the viewport camera and
|
||||
the render camera for all items in hierarchy.
|
||||
'''
|
||||
"""
|
||||
|
||||
NFTs_in_Batch, hierarchy, BatchDNAList = getBatchData()
|
||||
|
||||
|
@ -67,9 +67,9 @@ def render_and_save_NFTs():
|
|||
for i in hierarchy:
|
||||
for j in hierarchy[i]:
|
||||
if config.enableGeneration:
|
||||
'''
|
||||
"""
|
||||
Remove Color code so blender recognises the collection
|
||||
'''
|
||||
"""
|
||||
j = stripColorFromName(j)
|
||||
bpy.data.collections[j].hide_render = True
|
||||
bpy.data.collections[j].hide_viewport = True
|
||||
|
@ -96,13 +96,8 @@ def render_and_save_NFTs():
|
|||
dnaDictionary = match_DNA_to_Variant(a)
|
||||
name = config.nftName + "_" + str(x)
|
||||
|
||||
print("")
|
||||
print("----------Rendering New NFT----------")
|
||||
print("DNA attribute list:")
|
||||
print(dnaDictionary)
|
||||
print("DNA Code:")
|
||||
print(a)
|
||||
print("")
|
||||
print(f"\n{bcolors.OK}|---Generating {x} NFT Files---|{bcolors.RESET}")
|
||||
print(f"DNA attribute list:\n{dnaDictionary}\nDNA Code:{a}")
|
||||
|
||||
for c in dnaDictionary:
|
||||
collection = dnaDictionary[c]
|
||||
|
@ -144,7 +139,7 @@ def render_and_save_NFTs():
|
|||
bpy.data.collections[collection].hide_render = False
|
||||
bpy.data.collections[collection].hide_viewport = False
|
||||
|
||||
print("Generating")
|
||||
print(f"{bcolors.OK}Generating{bcolors.RESET}")
|
||||
|
||||
if config.enableImages:
|
||||
if not os.path.exists(imageFolder):
|
||||
|
@ -196,11 +191,8 @@ def render_and_save_NFTs():
|
|||
if not os.path.exists(metaDataFolder):
|
||||
os.makedirs(metaDataFolder)
|
||||
|
||||
metaDataDict = {}
|
||||
metaDataDict["name"] = name
|
||||
metaDataDict["description"] = config.metaDataDescription
|
||||
metaDataDict["NFT_DNA"] = a
|
||||
metaDataDict["NFT_Variants"] = dnaDictionary
|
||||
metaDataDict = {"name": name, "description": config.metaDataDescription, "NFT_DNA": a,
|
||||
"NFT_Variants": dnaDictionary}
|
||||
|
||||
jsonMetaData = json.dumps(metaDataDict, indent=1, ensure_ascii=True)
|
||||
|
||||
|
|
|
@ -22,9 +22,7 @@ importlib.reload(config)
|
|||
|
||||
|
||||
def returnCardanoMetaData(name, description, NFT_DNA, NFT_Variants):
|
||||
metaDataDictCardano = {}
|
||||
|
||||
metaDataDictCardano["721"] = {
|
||||
metaDataDictCardano = {"721": {
|
||||
"<policy_id>": {
|
||||
"<asset_name>": {
|
||||
"name": name,
|
||||
|
@ -41,7 +39,7 @@ def returnCardanoMetaData(name, description, NFT_DNA, NFT_Variants):
|
|||
}
|
||||
},
|
||||
"version": "1.0"
|
||||
}
|
||||
}}
|
||||
|
||||
return metaDataDictCardano
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue