Refactored DNA creation methods for Random and Rarity

Now using partial method for checking if Dups exist.
pull/30/head
Torrin Leonard 2021-12-02 13:23:07 -05:00
rodzic 527ad88420
commit 362d42a903
4 zmienionych plików z 28 dodań i 36 usunięć

Wyświetl plik

@ -10,6 +10,7 @@ import time
import json
import random
import importlib
from functools import partial
dir = os.path.dirname(bpy.data.filepath)
sys.path.append(dir)
@ -283,6 +284,8 @@ def generateNFT_DNA():
DNAList = []
if not config.enableRarity:
DNASet = set()
for i in hierarchy:
numChild = len(hierarchy[i])
possibleNums = list(range(1, numChild + 1))
@ -306,24 +309,11 @@ def generateNFT_DNA():
return str(dna)
for i in range(config.maxNFTs):
DNAList.append(createDNARandom())
dnaPushToList = partial(createDNARandom)
def anydup(DNAList):
dups = None
seen = set()
DNASet |= {''.join([dnaPushToList()]) for _ in range(config.maxNFTs - len(DNASet))}
for x in DNAList:
if x in seen:
DNAList.remove(x)
DNAList.append(createDNARandom())
dups = True
anydup(DNAList)
else:
dups = False
seen.add(x)
return dups
anydup(DNAList)
DNAList = list(DNASet)
possibleCombinations = config.maxNFTs
@ -334,7 +324,7 @@ def generateNFT_DNA():
if config.enableRarity:
print(bcolors.OK + "Rarity is on. Weights listed in .blend will be taken into account " + bcolors.RESET)
possibleCombinations = config.maxNFTs
Rarity_Sorter.sortRarityWeights(hierarchy, listOptionVariant, DNAList)
DNAList = Rarity_Sorter.sortRarityWeights(hierarchy, listOptionVariant, DNAList)
#Data stored in batchDataDictionary:
DataDictionary["numNFTsGenerated"] = possibleCombinations

Wyświetl plik

@ -144,7 +144,6 @@ def render_and_save_NFTs():
os.mkdir(modelPath)
for i in dnaDictionary:
print("\ni in dnaDict: ")
coll = dnaDictionary[i]
for obj in bpy.data.collections[coll].all_objects:

Wyświetl plik

@ -6,6 +6,8 @@ import os
import sys
import random
import importlib
from functools import partial
dir = os.path.dirname(bpy.data.filepath)
sys.path.append(dir)
@ -31,6 +33,8 @@ def sortRarityWeights(hierarchy, listOptionVariant, DNAList):
("rarity" in DNA_Generator). Then
'''
DNASet = set()
for i in hierarchy:
numChild = len(hierarchy[i])
possibleNums = list(range(1, numChild + 1))
@ -65,18 +69,16 @@ def sortRarityWeights(hierarchy, listOptionVariant, DNAList):
elif ifZeroBool == False:
variantByNum = random.choices(number_List_Of_i, weights=rarity_List_Of_i, k=1)
dnaStr1 += '-' + str(variantByNum[0])
dnaStr1 += "-" + str(variantByNum[0])
dnaStr1 = ''.join(dnaStr1.split('-', 1))
return dnaStr1
dnaStr = createDNA()
dnaPushToList = partial(createDNA)
if dnaStr not in DNAList:
dnaPushToList = ''.join(dnaStr.split('-', 1))
else:
createDNA()
DNASet |= {''.join([dnaPushToList()]) for _ in range(config.maxNFTs - len(DNASet))}
DNAList.append(dnaPushToList)
return
DNAListRare = list(DNASet)
return DNAListRare
if __name__ == '__main__':
sortRarityWeights()

Wyświetl plik

@ -39,6 +39,12 @@ enableImages = False # Renders and exports Images when main.py is run in Blende
enableModelsBlender = False # Generates 3D models when main.py is run in Blender if enableExporter = True
# ^^ Generates models with .blend file NOT external object library.
# Enables Rarity_Sorter to weigh NFT DNA attributes and variants:
enableRarity = False
# generateColors must be turned off and enableMaxNFTs must be turned on.
# True = include weighted rarity percentages in NFTRecord.json calculations,
# False = Pure random selection of variants
### Select colour or material.###
# Object generation options:
enableGeneration = False # When set to true this applies the sets of colors listed below to the objects in the collections named below
@ -72,7 +78,7 @@ 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.
enableMetaData = False # Set to True to turn on meta data, set to False to turn off meta data generation.
metaDataType = 'DEFAULT' # Select the format of the generated Meta Data for your NFTs blockchain.
# DEFAULT - The default setting; exports variants, dna, number, name, and rarity of each NFT to a dictionary (Not a blockchain standard)
@ -121,20 +127,15 @@ model_Script_Ignore_Path = modelAssetPath + slash + "Script_Ignore_Folder" # Th
if objectFormatExport not in ['fbx', 'glb', 'obj', 'x3d'] and enable3DModels:
raise ValueError("Output format in `objectFormatExport` can only be 'fbx', 'glb', 'obj', 'x3d'.")
# EXPERIMENTAL FEATURES:
# Enables Rarity_Sorter to weigh NFT DNA attributes and variants:
enableRarity = False
# generateColors must be turned off and enableMaxNFTs must be turned on.
# True = include weighted rarity percentages in NFTRecord.json calculations,
# False = Pure random selection of variants
# Tests and Previews:
# Preview and render test settings:
# Set to True to run Preview test, set to False to stop test. Run main.py in Blender to initiate the test. Results will
# be displayed in the Blender terminal or console. enable3DModels and enableExporter must be False to run the preview.
# be displayed in the Blender terminal or console. enableExporter must be False, and enableImages and/or enableModelsBlender
# to run a preview.
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.
checkDups = False
checkDups = True