Refactored files to prepare for more 3D model features

Refactored imports in main.py
Added the ability to limit 3D models generated in Model_Generator.py
pull/19/head
Torrin Leonard 2021-11-17 18:56:33 -05:00
rodzic faee567a7f
commit 2b3bece134
9 zmienionych plików z 52 dodań i 49 usunięć

Wyświetl plik

@ -15,7 +15,8 @@ sys.modules.values()
from src.main import config
importlib.reload(config)
from src.generators_and_sorters import Rarity_Sorter
from src.Image_Generators import Rarity_Sorter
importlib.reload(Rarity_Sorter)
if config.runPreview:

Wyświetl plik

@ -11,10 +11,9 @@ dir = os.path.dirname(bpy.data.filepath)
sys.path.append(dir)
sys.modules.values()
from src.generators_and_sorters import DNA_Generator
importlib.reload(DNA_Generator)
from src.Image_Generators import DNA_Generator, RenderTest
from src.generators_and_sorters import RenderTest
importlib.reload(DNA_Generator)
importlib.reload(RenderTest)
class bcolors:

Wyświetl plik

@ -11,7 +11,8 @@ sys.modules.values()
from src.main import config
importlib.reload(config)
from src.generators_and_sorters import DNA_Generator
from src.Image_Generators import DNA_Generator
importlib.reload(DNA_Generator)
if config.runPreview:

Wyświetl plik

@ -14,15 +14,11 @@ sys.path.append(dir)
sys.modules.values()
from src.main import config
from src.Image_Generators import Batch_Sorter, DNA_Generator, Image_Generator
importlib.reload(config)
from src.generators_and_sorters import DNA_Generator
importlib.reload(DNA_Generator)
from src.generators_and_sorters import Batch_Sorter
importlib.reload(Batch_Sorter)
from src.generators_and_sorters import Image_Generator
importlib.reload(Image_Generator)
class bcolors:

Wyświetl plik

@ -9,6 +9,7 @@ import sys
import copy
import time
import json
import random
import itertools
import importlib
@ -17,9 +18,7 @@ sys.path.append(dir)
sys.modules.values()
from src.main import config
importlib.reload(config)
from src.main.config import *
class bcolors:
'''
@ -53,14 +52,15 @@ def generate3DModels():
bpy.ops.object.delete()
deleteAllObjects()
attributeList = os.listdir(modelAssetPath)
attributeList = os.listdir(config.modelAssetPath)
removeList = [".gitignore", ".DS_Store", "Script_Ignore_Folder"]
attributeList = [x for x in attributeList if (x not in removeList)]
hierarchy = {}
for i in attributeList:
hierarchy[i] = os.listdir(modelAssetPath + slash + i)
file_unfiltered = os.listdir(config.modelAssetPath + config.slash + i)
add_to_hierarchy = [x for x in file_unfiltered if x not in removeList]
hierarchy[i] = add_to_hierarchy
def numOfCombinations(hierarchy):
'''
@ -74,7 +74,7 @@ def generate3DModels():
combinations = combinations*i
if combinations == 0:
print(bcolors.FAIL + "ERROR:" + bcolors.RESET)
print(bcolors.FAIL + "\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.")
return combinations
@ -82,22 +82,29 @@ def generate3DModels():
combinations = numOfCombinations(hierarchy)
allCombinationsNames = list(itertools.product(*hierarchy.values()))
listToGenerate = []
while len(listToGenerate) < config.maxNFTs:
randCombo = random.choice(allCombinationsNames)
if randCombo not in listToGenerate:
listToGenerate.append(randCombo)
count = 1
for i in allCombinationsNames:
path1 = modelAssetPath + slash + "Script_Ignore_Folder"
Script_Ignore_Folder = os.listdir(path1)
for i in listToGenerate:
if os.path.isdir(config.model_Script_Ignore_Path):
Script_Ignore_Folder = os.listdir(config.model_Script_Ignore_Path)
for h in Script_Ignore_Folder:
fileName, fileExtension = os.path.splitext(h)
if fileExtension == ".glb":
bpy.ops.import_scene.gltf(filepath=path1 + slash + h)
elif fileExtension == ".fbx":
bpy.ops.import_scene.fbx(filepath=path1 + slash + h)
elif fileExtension == ".obj":
bpy.ops.import_scene.obj(filepath=path1 + slash + h)
elif fileExtension == ".x3d":
bpy.ops.import_scene.obj(filepath=path1 + slash + h)
for h in Script_Ignore_Folder:
fileName, fileExtension = os.path.splitext(h)
if fileExtension == ".glb":
bpy.ops.import_scene.gltf(filepath=config.model_Script_Ignore_Path + config.slash + h)
elif fileExtension == ".fbx":
bpy.ops.import_scene.fbx(filepath=config.model_Script_Ignore_Path + config.slash + h)
elif fileExtension == ".obj":
bpy.ops.import_scene.obj(filepath=config.model_Script_Ignore_Path + config.slash + h)
elif fileExtension == ".x3d":
bpy.ops.import_scene.obj(filepath=config.model_Script_Ignore_Path + config.slash + h)
for j in i:
def getParent(hierarchy):
@ -107,9 +114,9 @@ def generate3DModels():
return x
parent = getParent(hierarchy)
path2 = modelAssetPath + slash + parent + slash + j
path2 = config.modelAssetPath + config.slash + parent + config.slash + j
fileName, fileExtension = os.path.splitext(j)
if fileExtension == ".glb":
bpy.ops.import_scene.gltf(filepath=path2)
elif fileExtension == ".fbx":
@ -119,25 +126,22 @@ def generate3DModels():
elif fileExtension == ".x3d":
bpy.ops.import_scene.obj(filepath=path2)
if objectFormatExport == 'glb':
bpy.ops.export_scene.gltf(filepath=model_save_path + slash + imageName + str(count),
if config.objectFormatExport == 'glb':
bpy.ops.export_scene.gltf(filepath=config.model_save_path + config.slash + config.imageName + str(count),
check_existing=True, export_format='GLB')
elif objectFormatExport == 'fbx':
bpy.ops.export_scene.fbx(filepath=model_save_path + slash + imageName + str(count),
elif config.objectFormatExport == 'fbx':
bpy.ops.export_scene.fbx(filepath=config.model_save_path + config.slash + config.imageName + str(count),
check_existing=True)
elif objectFormatExport == 'obj':
bpy.ops.export_scene.obj(filepath=model_save_path + slash + imageName + str(count),
elif config.objectFormatExport == 'obj':
bpy.ops.export_scene.obj(filepath=config.model_save_path + config.slash + config.imageName + str(count),
check_existing=True)
elif objectFormatExport == 'x3d':
bpy.ops.export_scene.x3d(filepath=model_save_path + slash + imageName + str(count),
elif config.objectFormatExport == 'x3d':
bpy.ops.export_scene.x3d(filepath=config.model_save_path + config.slash + config.imageName + str(count),
check_existing=True)
deleteAllObjects()
count += 1
print("Generated .glb files in %.4f seconds" % (time.time() - time_start))
print("Generated ." + str(config.objectFormatExport) +" files in %.4f seconds" % (time.time() - time_start))
if __name__ == '__main__':
generate3DModels()

Wyświetl plik

@ -38,7 +38,7 @@ objectFormatExport = '' # The file format of the objects you would like to expo
### Select colour or material.###
# Object generation options:
enableGeneration = True # When set to true this applies the sets of colors listed below to the objects in the collections named below
enableGeneration = False # When set to true this applies the sets of colors listed below to the objects in the collections named below
generationType = 'material' # You can either set 'color' or 'material' here. Type you set will correspond to following options.
# The collections below are RGBA Color values. You can put as many or as little color values in these lists as you would like.
@ -84,6 +84,7 @@ batch_save_path = save_path + slash + 'Batch_Json_files' # The output path for
images_save_path = save_path + slash + 'NFT_Image_Output' # The output path for images generated by Image_Generator.py
modelAssetPath = save_path + slash + "3D_Model_Input" # The input path for 3D models
model_save_path = save_path + slash + "3D_Model_Output" # The output path for 3D models generated by Model_Generator.py
model_Script_Ignore_Path = modelAssetPath + slash + "Script_Ignore_Folder" # The path to the Script_Ignore_Folder for 3D models
# EXPERIMENTAL FEATURES:

Wyświetl plik

@ -11,10 +11,12 @@ sys.modules.values()
from src.main import config
importlib.reload(config)
from src.generators_and_sorters import DNA_Generator, Preview, RenderTest, Batch_Sorter, Model_Generator, Image_Generator
importlib.reload(DNA_Generator)
importlib.reload(Batch_Sorter)
from src.Model_Generators import Model_Generator
from src.Image_Generators import Batch_Sorter, DNA_Generator, Image_Generator, RenderTest, Preview
importlib.reload(Model_Generator)
importlib.reload(Batch_Sorter)
importlib.reload(DNA_Generator)
importlib.reload(Preview)
importlib.reload(RenderTest)
importlib.reload(Image_Generator)
@ -32,4 +34,3 @@ if config.runPreview:
if config.renderImage:
Image_Generator.render_and_save_NFTs()