Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to set a list of color attributes for sub collections #8

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 68 additions & 5 deletions src/generators_and_sorters/DNA_Generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ class bcolors:

time_start = time.time()

def stripColorFromName(name):
return "_".join(name.split("_")[:-1])

def checkCollectionChildNames():
#Needs to be implemented to ensure that objects under a collection share the same structure check before compiling list
#Example
#AreaLight Collection
#AreaLigjht_1_0 != AreaLight_2_0
#AreaLigjht vs AreaLight
return True
def returnData():
'''
Generates important variables, dictionaries, and lists needed to be stored to catalog the NFTs.
Expand All @@ -39,9 +49,32 @@ def returnData():
listAllCollections = []
scriptIgnore = bpy.data.collections["Script_Ignore"]

def listSubIgnoreCollections():
def getParentSubCollections(collection):
yield collection
for child in collection.children:
yield from getParentSubCollections(child)
collList = []
for c in getParentSubCollections(scriptIgnore):
collList.append(c.name)
return collList

ignoreList = listSubIgnoreCollections()
print(ignoreList)
for i in bpy.data.collections:
listAllCollections.append(i.name)

if generateColors:
if i.name in colorList:
for j in range(len(colorList[i.name])):
if i.name[-1].isdigit() and i.name not in ignoreList:
listAllCollections.append(i.name + "_" + str(j+1))
elif j == 0:
listAllCollections.append(i.name)
elif i.name[-1].isdigit() and i.name not in ignoreList:
listAllCollections.append(i.name+"_0")
else:
listAllCollections.append(i.name)
else:
listAllCollections.append(i.name)
listAllCollections.remove(scriptIgnore.name)

def allScriptIgnore(collection):
Expand Down Expand Up @@ -78,6 +111,8 @@ def attributeData(attributeVariants):
Creates a dictionary of each attribute
'''
allAttDataList = {}
count = 0
previousAttribute = ""
for i in attributeVariants:

def getName(i):
Expand All @@ -89,7 +124,7 @@ def getName(i):

def getOrder_rarity(i):
'''
Returns the "order" and "rarity" of i attribute variant in a list
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("_")
Expand All @@ -106,8 +141,21 @@ def getOrder_rarity(i):
return
elif len(orderRarity) > 0:
number = orderRarity[0]
if generateColors:
if count == 1 or count == 0:
previousAttribute = i.partition("_")[0]
count +=1
elif i.partition("_")[0] == previousAttribute:
count +=1
else:
count = 1
number = str(count)
rarity = orderRarity[1]
eachObject = {"name": name, "number": number, "rarity": rarity}
if generateColors and stripColorFromName(i) in colorList:
color = orderRarity[2]
else:
color = "0"
eachObject = {"name": name, "number": number, "rarity": rarity, "color": color}
allAttDataList[i] = eachObject
return allAttDataList

Expand All @@ -122,7 +170,17 @@ def getHierarchy():
colParLong = list(bpy.data.collections[str(i)].children)
colParShort = {}
for x in colParLong:
colParShort[x.name] = None
if generateColors:
'''
Append colors to blender name for PNG generator and NFTRecord.json to create the correct list
'''
if x.name in colorList:
for j in range(len(colorList[x.name])):
colParShort[x.name + "_" + str(j+1)] = None
else:
colParShort[x.name + "_0"] = None
else:
colParShort[x.name] = None
hierarchy[i] = colParShort

for a in hierarchy:
Expand Down Expand Up @@ -173,6 +231,11 @@ def numOfCombinations(hierarchy):

for i in variantMetaData:
def cameraToggle(i,toggle = True):
if generateColors:
'''
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
cameraToggle(i)
Expand Down
40 changes: 37 additions & 3 deletions src/generators_and_sorters/Image_Generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
importlib.reload(config)
from src.main.config import *

def stripColorFromName(name):
return "_".join(name.split("_")[:-1])

def getBatchData():
'''
Retrieves a given batches data determined by renderBatch in config.py
Expand Down Expand Up @@ -45,6 +48,11 @@ def render_and_save_NFTs():
for a in BatchDNAList:
for i in hierarchy:
for j in hierarchy[i]:
if generateColors:
'''
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

Expand Down Expand Up @@ -80,18 +88,37 @@ def match_DNA_to_Variant(a):

for c in dnaDictionary:
collection = dnaDictionary[c]
bpy.data.collections[collection].hide_render = False
bpy.data.collections[collection].hide_viewport = False
if not generateColors:
bpy.data.collections[collection].hide_render = False
bpy.data.collections[collection].hide_viewport = False

time_start_2 = time.time()

imageOutputBatchSubFolder = "Batch" + str(renderBatch)

fullImagePath = images_path + slash + imageOutputBatchSubFolder + slash + "{}.jpeg".format(name)

if generateColors:
for c in dnaDictionary:
collection = dnaDictionary[c]
if stripColorFromName(collection) in colorList:
colorVal = int(collection.rsplit("_",1)[1])-1
collection = stripColorFromName(collection)
bpy.data.collections[collection].hide_render = False
bpy.data.collections[collection].hide_viewport = False
for activeObject in bpy.data.collections[collection].all_objects:
mat = bpy.data.materials.new("PKHG")
mat.diffuse_color = colorList[collection][colorVal]
activeObject.active_material = mat
else:
collection = stripColorFromName(collection)
bpy.data.collections[collection].hide_render = False
bpy.data.collections[collection].hide_viewport = False
print("Rendering")
bpy.context.scene.render.filepath = fullImagePath
bpy.context.scene.render.image_settings.file_format = fileFormat
bpy.ops.render.render(write_still=True)

print("Completed {} render in ".format(name) + "%.4f seconds" % (time.time() - time_start_2))

#Image meta data stuff, for future implementation, doesn't work right now:
Expand All @@ -115,7 +142,14 @@ def imageMetaData():
'''

x += 1

if resetViewport:
for a in BatchDNAList:
for i in hierarchy:
for j in hierarchy[i]:
if generateColors:
j = stripColorFromName(j)
bpy.data.collections[j].hide_render = False
bpy.data.collections[j].hide_viewport = False
print("")
print("All NFT PNGs rendered, process finished.")
print("Completed all renders in Batch{}.json in ".format(renderBatch) + "%.4f seconds" % (time.time() - time_start_1))
Expand Down
7 changes: 7 additions & 0 deletions src/main/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
# True = include weighted rarity percentages in NFTRecord.json calculations,
# False = Pure random selection of variants

resetViewport = True

generateColors = True
collection1 = [(1,0,0,1),(0,1,0,1),(0,0,1,1),(1,1,1,1),(.5,0,0,1)]
collection2 = [(1,1,0,1),(0,1,1,1),(.5,0,1,1),(.5,1,1,1),(0,.5,0,1)]
colorList = {"Cube_2_0":collection1,"Sphere_1_0":collection2}

# The path to Blend_My_NFTs folder:
save_path_mac = '/Users/torrinleonard/Desktop/Blend_My_NFTs'
save_path_windows = r''
Expand Down