Added the ability to refactor meta data to templates

Refactored how meta data works and is exported
pull/34/head
Torrin Leonard 2021-12-09 21:58:11 -05:00
rodzic 24e5c25d18
commit 41c46b8b7f
5 zmienionych plików z 137 dodań i 71 usunięć

Wyświetl plik

@ -112,7 +112,7 @@ def render_and_save_NFTs():
imageFolder = os.path.join(batchFolder, "Images")
animationFolder = os.path.join(batchFolder, "Animations")
modelFolder = os.path.join(batchFolder, "Models")
metaDataFolder = os.path.join(batchFolder, "NFT_metaData")
metaDataFolder = os.path.join(batchFolder, "BMNFT_metaData")
if config.enableGeneration:
for c in dnaDictionary:
@ -184,20 +184,19 @@ def render_and_save_NFTs():
check_existing=True,
use_selection=True)
if config.enableMetaData:
if not os.path.exists(metaDataFolder):
os.makedirs(metaDataFolder)
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 = {}
metaDataDict["name"] = name
metaDataDict["description"] = config.metaDataDescription
metaDataDict["NFT_DNA"] = a
metaDataDict["NFT_Variants"] = dnaDictionary
jsonMetaData = json.dumps(metaDataDict, indent=1, ensure_ascii=True)
jsonMetaData = json.dumps(metaDataDict, indent=1, ensure_ascii=True)
with open(os.path.join(metaDataFolder, "Data_" + name + ".json"), 'w') as outfile:
outfile.write(jsonMetaData + '\n')
with open(os.path.join(metaDataFolder, "Data_" + name + ".json"), 'w') as outfile:
outfile.write(jsonMetaData + '\n')
print("Completed {} render in ".format(name) + "%.4f seconds" % (time.time() - time_start_2))
x += 1

Wyświetl plik

@ -21,40 +21,40 @@ from src import config
importlib.reload(config)
def returnMetaData(metaDataDict, name, a, dnaDictionary):
'''
This function exports formatted meta data based on the metaDataType variable in config.py
'''
def returnSolanaMetaData(name, description, NFT_DNA, NFT_Variants):
metaDataDictSolana = {}
if config.solanaMetaData:
metaDataDict["name"] = config.nftName
metaDataDict["symbol"] = ""
metaDataDict["description"] = config.metaDataDescription
metaDataDict["seller_fee_basis_points"] = None
metaDataDict["image"] = ""
metaDataDict["animation_url"] = ""
metaDataDict["external_url"] = ""
metaDataDictSolana["name"] = name
metaDataDictSolana["symbol"] = ""
metaDataDictSolana["description"] = description
metaDataDictSolana["seller_fee_basis_points"] = None
metaDataDictSolana["image"] = ""
metaDataDictSolana["animation_url"] = ""
metaDataDictSolana["external_url"] = ""
attributes = []
attributes = []
for i in dnaDictionary:
dictionary = {
"trait_type": i,
"value": dnaDictionary[i]
}
attributes.append(dictionary)
metaDataDict["attributes"] = attributes
metaDataDict["collection"] = {
"name": "",
"family": ""
for i in NFT_Variants:
dictionary = {
"trait_type": i,
"value": NFT_Variants[i]
}
metaDataDict["properties"] = {"files": [{"uri": "", "type": ""}],
"category": "",
"creators": [{"address": "", "share": None}]
}
attributes.append(dictionary)
metaDataDictSolana["attributes"] = attributes
metaDataDictSolana["collection"] = {
"name": "",
"family": ""
}
metaDataDictSolana["properties"] = {"files": [{"uri": "", "type": ""}],
"category": "",
"creators": [{"address": "", "share": None}]
}
return metaDataDictSolana
'''
if config.cardanoMetaData:
metaDataDict["721"] = {
"<policy_id>": {
@ -81,6 +81,7 @@ def returnMetaData(metaDataDict, name, a, dnaDictionary):
metaDataDict["properties"] = {"NFT_Variants": dnaDictionary,
"description": config.metaDataDescription,
"NFT_DNA": a}
'''
if __name__ == '__main__':
returnMetaData()

Wyświetl plik

@ -16,8 +16,10 @@ sys.path.append(dir)
sys.modules.values()
from src import config
from src.Main_Generators import metaData
importlib.reload(config)
importlib.reload(metaData)
def getNFType():
images = False
@ -33,23 +35,89 @@ def getNFType():
animations = True
if "Models" in batchContent:
models = True
if "NFT_metaData" in batchContent:
if "BMNFT_metaData" in batchContent:
metaData = True
return images, animations, models, metaData
def renameMetaData():
# refactor name in all meta data files to include new order numbers
def getMetaDataDirty(completeMetaDataPath, i):
'''
Retrieves a given batches data determined by renderBatch in config.py
'''
file_name = os.path.join(completeMetaDataPath, i)
metaDataDirty = json.load(open(file_name))
name = metaDataDirty["name"]
description = metaDataDirty["description"]
NFT_DNA = metaDataDirty["NFT_DNA"]
NFT_Variants = metaDataDirty["NFT_Variants"] # Variant dictionary
return name, description, NFT_DNA, NFT_Variants
def sendMetaDataToJson(metaDataDict, metaDataPath, jsonName):
jsonMetaData = json.dumps(metaDataDict, indent=1, ensure_ascii=True)
with open(os.path.join(metaDataPath, jsonName), 'w') as outfile:
outfile.write(jsonMetaData + '\n')
def renameMetaData(completeCollPath, completeMetaDataPath):
metaDataListOld = os.listdir(completeMetaDataPath)
print(metaDataListOld)
defaultMetaDataPath = os.path.join(completeCollPath, "Default_metaData")
cardanoMetaDataPath = os.path.join(completeCollPath, "Cardano_metaData")
solanaMetaDataPath = os.path.join(completeCollPath, "Solana_metaData")
erc721MetaDataPath = os.path.join(completeCollPath, "Erc721_metaData")
for i in metaDataListOld:
name, description, NFT_DNA, NFT_Variants = getMetaDataDirty(completeMetaDataPath, i)
file_name = os.path.splitext(i)[0]
file_num = file_name.split("_")[1]
if config.defaultMetaData:
if not os.path.exists(defaultMetaDataPath):
os.mkdir(defaultMetaDataPath)
metaDataDictDefault = metaData.returnSolanaMetaData(name, description, NFT_DNA, NFT_Variants)
if config.cardanoMetaData:
if not os.path.exists(cardanoMetaDataPath):
os.mkdir(completeCollPath)
metaDataDictCardano = metaData.returnSolanaMetaData(name, description, NFT_DNA, NFT_Variants)
if config.solanaMetaData:
if not os.path.exists(solanaMetaDataPath):
os.mkdir(solanaMetaDataPath)
solanaJsonNew = "Solana_" + i
solanaNewName = name.split("_")[0] + "_" + str(file_num)
metaDataDictSolana = metaData.returnSolanaMetaData(solanaNewName, description, NFT_DNA, NFT_Variants)
sendMetaDataToJson(metaDataDictSolana, solanaMetaDataPath, solanaJsonNew)
if config.erc721MetaData:
if not os.path.exists(erc721MetaDataPath):
os.mkdir(erc721MetaDataPath)
metaDataDictErc721 = metaData.returnSolanaMetaData(name, description, NFT_DNA, NFT_Variants)
return
def reformatBatches():
def reformatNFTCollection():
images, animations, models, metaData = getNFType()
completeCollPath = os.path.join(config.save_path, "Complete_Collection")
completeImagePath = os.path.join(completeCollPath, "Images")
completeAnimationsPath = os.path.join(completeCollPath, "Animations")
completeModelsPath = os.path.join(completeCollPath, "Models")
completeMetaDataPath = os.path.join(completeCollPath, "NFT_metaData")
completeMetaDataPath = os.path.join(completeCollPath, "BMNFT_metaData")
if not os.path.exists(completeCollPath):
os.mkdir(completeCollPath)
@ -123,11 +191,11 @@ def reformatBatches():
modelCount += 1
if metaData:
dataDir = os.path.join(config.nft_save_path, i, "NFT_metaData")
dataDir = os.path.join(config.nft_save_path, i, "BMNFT_metaData")
dataList = sorted(os.listdir(dataDir))
for j in dataList:
dataOldPath = os.path.join(config.nft_save_path, i, "NFT_metaData", j)
dataOldPath = os.path.join(config.nft_save_path, i, "BMNFT_metaData", j)
nameOldDirty = copy.deepcopy(os.path.splitext(j)[0])
extension = copy.deepcopy(os.path.splitext(j)[1])
nameOldClean = nameOldDirty.split("_")[0]
@ -141,5 +209,7 @@ def reformatBatches():
print("All NFT files stored and sorted to the Complete_Collection folder in {}".format(config.save_path))
renameMetaData(completeCollPath, completeMetaDataPath)
if __name__ == '__main__':
reformatBatches()
reformatNFTCollection()

Wyświetl plik

@ -39,7 +39,7 @@ save_path_windows = r''
maxNFTs = 20 # The maximum number of NFTs you want to generate.
nftsPerBatch = 5 # Number of NFTs per batch
renderBatch = 1 # The batch number to render in Exporter.py
renderBatch = 4 # The batch number to render in Exporter.py
# Set to True to generate images or 3D models depending on your settings below when main.py is run in Blender. Only works
# if you have already generated NFTRecord.json and all batches.
@ -90,24 +90,6 @@ materialList2 = ['Material2', 'Material2.001', 'Material2.002', 'Material2.003',
if generationType == 'material': # Do not change this line.
colorList = {"Cube_1_33": materialList1, "Sphere_2_0": materialList2}
# Meta Data generation
enableMetaData = True # Set to True to turn on meta data, set to False to turn off meta data generation.
metaDataType = 'ADA'
# Select the format of the generated Meta Data for your NFTs blockchain.
defaultMetaData = True # The default setting; exports variants, dna, number, name, and rarity of each NFT to a dictionary (Not a blockchain standard)
cardanoMetaData = False # Cardano - Format Source: https://cips.cardano.org/cips/cip25/
solanaMetaData = False # Solana - Format Source: https://docs.metaplex.com/nft-standard
erc721MetaData = False # Ethereum ERC721 - Format Source: https://eips.ethereum.org/EIPS/eip-721
# NOTE: This is just the information Blend_My_NFTs can provide, you will have to add policy ID, URI information, etc
# yourself when you upload and mint your NFT collection.
# DISCLAIMER: These are only templates based on the common standards for the given blockchain, you will have to modify
# and fill them in with a script of your own when you mint your NFT collection. These metadata templates are only provided
# for your convenience and are as accurate to the standards above that I could make them.
metaDataDescription = '' # The description of your NFT that will be inserted into its meta data
enableResetViewport = True # If True: turns all viewport and render cameras on after Image_Generator is finished operations
# 3D model imports and exports variables:
@ -151,13 +133,27 @@ runPreview = False
maxNFTsTest = 5 # Increase to get a more accurate reading of the render time. The number of images generated in the render test.
# Turn this on when you run main.py to generate NFTRecord.json and appropriate batches to confirm there are no duplicate
# NFT DNA.
# NFT DNA. Note - This file is provided for transparency, it is impossible for duplicates to be made with the current code in
# DNA_Generator.py.
checkDups = False
# EXPERIMENTAL FEATURE:
refactorBatchOrder = False # When set to True, sorts, renames, and moves all NFTs files in all batches in NFT_Output
refactorBatchOrder = True # When set to True, sorts, renames, and moves all NFTs files in all batches in NFT_Output
# folder to the Complete_Collection folder.
# After you generate all batches move them all to one computer and place them in the NFT_Output folder of Blend_My_NFTs.
# Run main.py with refactorBatchOrder set to True and all NFT files will be renamed and sorted into a folder called Complete_Collection.
# Meta Data Templates - Run after refactorBatchOrder
# Set the following to True to generate the format of the Meta Data template for your NFTs blockchain. (You can use multiple)
defaultMetaData = False # The default setting; exports variants, dna, number, name, and rarity of each NFT to a dictionary (Not a blockchain standard)
cardanoMetaData = False # Cardano - Format Source: https://cips.cardano.org/cips/cip25/
solanaMetaData = True # Solana - Format Source: https://docs.metaplex.com/nft-standard
erc721MetaData = False # Ethereum ERC721 - Format Source: https://eips.ethereum.org/EIPS/eip-721
# NOTE: This is just the information Blend_My_NFTs can provide, you will have to add policy ID, URI information, etc
# yourself when you upload and mint your NFT collection.
# DISCLAIMER: These are only templates based on the common standards for the given blockchain, you will have to modify
# and fill them in with a script of your own when you mint your NFT collection. These metadata templates are only provided
# for your convenience and are as accurate to the standards above that I could make them.
metaDataDescription = '' # The description of your NFT that will be inserted into its meta data

Wyświetl plik

@ -43,4 +43,4 @@ if config.runPreview:
Preview.printImportant()
if config.refactorBatchOrder:
BatchRefactorer.reformatBatches()
BatchRefactorer.reformatNFTCollection()