kopia lustrzana https://github.com/torrinworx/Blend_My_NFTs
Reformatting refactorer to support Tiff and PNG folder animations
rodzic
643c2f1819
commit
3a874aea71
10
__init__.py
10
__init__.py
|
@ -326,7 +326,9 @@ class BMNFTS_PGT_Input_Properties(bpy.types.PropertyGroup):
|
|||
('AVI_JPEG', '.avi (AVI_JPEG)', 'Export NFT as AVI_JPEG'),
|
||||
('AVI_RAW', '.avi (AVI_RAW)', 'Export NFT as AVI_RAW'),
|
||||
('FFMPEG', '.mkv (FFMPEG)', 'Export NFT as FFMPEG'),
|
||||
('MP4', '.mp4', 'Export NFT as .mp4')
|
||||
('MP4', '.mp4', 'Export NFT as .mp4'),
|
||||
('PNG', ".png", "Export NFT as PNG"),
|
||||
('TIFF', ".tiff", "Export NFT as TIFF")
|
||||
]
|
||||
)
|
||||
|
||||
|
@ -615,11 +617,7 @@ class refactor_Batches(bpy.types.Operator):
|
|||
Blend_My_NFTs_Output, batch_json_save_path, nftBatch_save_path = make_directories(save_path)
|
||||
|
||||
# Passing info to main functions for refactoring:
|
||||
try:
|
||||
Refactorer.reformatNFTCollection(input)
|
||||
self.report({'INFO'}, "Batches successfully refactored!")
|
||||
except Exception:
|
||||
raise """Something went wrong while refactoring."""
|
||||
Refactorer.reformatNFTCollection(input)
|
||||
return {"FINISHED"}
|
||||
|
||||
def invoke(self, context, event):
|
||||
|
|
|
@ -7,18 +7,21 @@ import os
|
|||
removeList = [".gitignore", ".DS_Store", "desktop.ini", ".ini"]
|
||||
|
||||
def remove_file_by_extension(dirlist):
|
||||
"""
|
||||
Checks if a given directory list contains any of the files or file extensions listed above, if so, remove them from
|
||||
list and return a clean dir list. These files interfer with BMNFTs operations and should be removed whenever dealing
|
||||
with directories.
|
||||
"""
|
||||
"""
|
||||
Checks if a given directory list contains any of the files or file extensions listed above, if so, remove them from
|
||||
list and return a clean dir list. These files interfer with BMNFTs operations and should be removed whenever dealing
|
||||
with directories.
|
||||
"""
|
||||
|
||||
return_dirs = []
|
||||
for directory in dirlist:
|
||||
if not str(os.path.splitext(directory)[1]) in removeList:
|
||||
return_dirs.append(directory)
|
||||
if str(type(dirlist)) == "<class 'list'>":
|
||||
dirlist = list(dirlist) # converts single string path to list if dir pasted as string
|
||||
|
||||
return return_dirs
|
||||
return_dirs = []
|
||||
for directory in dirlist:
|
||||
if not str(os.path.split(directory)[1]) in removeList:
|
||||
return_dirs.append(directory)
|
||||
|
||||
return return_dirs
|
||||
|
||||
|
||||
class bcolors:
|
||||
|
|
|
@ -252,15 +252,15 @@ def render_and_save_NFTs(input):
|
|||
# Main paths for batch subfolders:
|
||||
batchFolder = os.path.join(input.nftBatch_save_path, "Batch" + str(input.batchToGenerate))
|
||||
|
||||
imagePath = os.path.join(batchFolder, "Images", name)
|
||||
animationPath = os.path.join(batchFolder, "Animations", name)
|
||||
modelPath = os.path.join(batchFolder, "Models", name)
|
||||
|
||||
imageFolder = os.path.join(batchFolder, "Images")
|
||||
animationFolder = os.path.join(batchFolder, "Animations")
|
||||
modelFolder = os.path.join(batchFolder, "Models")
|
||||
BMNFT_metaData_Folder = os.path.join(batchFolder, "BMNFT_metadata")
|
||||
|
||||
imagePath = os.path.join(imageFolder, name)
|
||||
animationPath = os.path.join(animationFolder, name)
|
||||
modelPath = os.path.join(modelFolder, name)
|
||||
|
||||
cardanoMetadataPath = os.path.join(batchFolder, "Cardano_metadata")
|
||||
solanaMetadataPath = os.path.join(batchFolder, "Solana_metadata")
|
||||
erc721MetadataPath = os.path.join(batchFolder, "Erc721_metadata")
|
||||
|
@ -299,16 +299,32 @@ def render_and_save_NFTs(input):
|
|||
if not os.path.exists(animationFolder):
|
||||
os.makedirs(animationFolder)
|
||||
|
||||
bpy.context.scene.render.filepath = animationPath
|
||||
|
||||
if input.animationFileFormat == 'MP4':
|
||||
bpy.context.scene.render.filepath = animationPath
|
||||
bpy.context.scene.render.image_settings.file_format = "FFMPEG"
|
||||
|
||||
bpy.context.scene.render.ffmpeg.format = 'MPEG4'
|
||||
bpy.context.scene.render.ffmpeg.codec = 'H264'
|
||||
bpy.ops.render.render(animation=True)
|
||||
|
||||
if input.animationFileFormat == 'PNG':
|
||||
if not os.path.exists(animationPath):
|
||||
os.makedirs(animationPath)
|
||||
|
||||
bpy.context.scene.render.filepath = os.path.join(animationPath, name)
|
||||
bpy.context.scene.render.image_settings.file_format = input.animationFileFormat
|
||||
bpy.ops.render.render(animation=True)
|
||||
|
||||
if input.animationFileFormat == 'TIFF':
|
||||
if not os.path.exists(animationPath):
|
||||
os.makedirs(animationPath)
|
||||
|
||||
bpy.context.scene.render.filepath = os.path.join(animationPath, name)
|
||||
bpy.context.scene.render.image_settings.file_format = input.animationFileFormat
|
||||
bpy.ops.render.render(animation=True)
|
||||
|
||||
else:
|
||||
bpy.context.scene.render.filepath = animationPath
|
||||
bpy.context.scene.render.image_settings.file_format = input.animationFileFormat
|
||||
bpy.ops.render.render(animation=True)
|
||||
|
||||
|
|
|
@ -9,57 +9,35 @@ import shutil
|
|||
from .Constants import bcolors, removeList, remove_file_by_extension
|
||||
|
||||
|
||||
def moveAll(completeCollPath: str, batch_path: str, folder_type_list: list):
|
||||
"""
|
||||
Creates all Completed_Collection sub folders and moves all files of a given batch to the appropriate file folders.
|
||||
"""
|
||||
|
||||
# Create folder_type_dict and make dirs from batch_folder_list if they exist in a given batch:
|
||||
for folder_type in folder_type_list:
|
||||
folder_type_old_path = os.path.join(batch_path, folder_type)
|
||||
folder_type_new_path = os.path.join(completeCollPath, folder_type)
|
||||
|
||||
if os.path.isdir(folder_type_old_path):
|
||||
if not os.path.isdir(folder_type_new_path):
|
||||
os.mkdir(folder_type_new_path)
|
||||
|
||||
file_list = sorted(os.listdir(folder_type_old_path))
|
||||
for item in file_list:
|
||||
file_list_dir_old = os.path.join(folder_type_old_path, item)
|
||||
file_list_dir_new = os.path.join(folder_type_new_path, item)
|
||||
|
||||
os.rename(file_list_dir_old, file_list_dir_new)
|
||||
|
||||
|
||||
def reformatNFTCollection(refactor_panel_input):
|
||||
completeCollPath = os.path.join(refactor_panel_input.save_path, "Blend_My_NFTs Output", "Complete_Collection")
|
||||
|
||||
if not os.path.exists(completeCollPath):
|
||||
os.mkdir(completeCollPath)
|
||||
|
||||
batchListDirty = os.listdir(refactor_panel_input.nftBatch_save_path)
|
||||
batchList = sorted([x for x in batchListDirty if (x not in removeList)])
|
||||
|
||||
batchList = remove_file_by_extension(batchListDirty)
|
||||
collection_info = {"Total Time": 0}
|
||||
for batch in batchList:
|
||||
folder_type_list = [
|
||||
"Images",
|
||||
"Animations",
|
||||
"Models",
|
||||
"Cardano_metadata",
|
||||
"Solana_metadata",
|
||||
"Erc721_metadata",
|
||||
"BMNFT_metaData"
|
||||
]
|
||||
|
||||
batch_path = os.path.join(refactor_panel_input.nftBatch_save_path, batch)
|
||||
|
||||
moveAll(completeCollPath, batch_path, folder_type_list)
|
||||
|
||||
batch_info = json.load(open(os.path.join(refactor_panel_input.nftBatch_save_path, batch, "batch_info.json")))
|
||||
collection_info[os.path.basename(batch)] = batch_info
|
||||
|
||||
for folder in batchList:
|
||||
batch_info = json.load(open(os.path.join(refactor_panel_input.nftBatch_save_path, folder, "batch_info.json")))
|
||||
collection_info[os.path.basename(folder)] = batch_info
|
||||
collection_info["Total Time"] = collection_info["Total Time"] + batch_info["Batch Render Time"]
|
||||
|
||||
fileListDirty = os.listdir(os.path.join(refactor_panel_input.nftBatch_save_path, folder))
|
||||
filelist = remove_file_by_extension(fileListDirty)
|
||||
|
||||
for mediaTypeFolder in filelist:
|
||||
if mediaTypeFolder != "batch_info.json":
|
||||
mediaTypeFolderDir = os.path.join(refactor_panel_input.nftBatch_save_path, folder, mediaTypeFolder)
|
||||
|
||||
for i in os.listdir(mediaTypeFolderDir):
|
||||
destination = os.path.join(completeCollPath, mediaTypeFolder)
|
||||
if not os.path.exists(destination):
|
||||
os.makedirs(destination)
|
||||
|
||||
shutil.move(os.path.join(mediaTypeFolderDir, i), destination)
|
||||
|
||||
collection_info = json.dumps(collection_info, indent=1, ensure_ascii=True)
|
||||
with open(os.path.join(completeCollPath, "collection_info.json"), 'w') as outfile:
|
||||
outfile.write(collection_info + '\n')
|
||||
|
@ -67,3 +45,4 @@ def reformatNFTCollection(refactor_panel_input):
|
|||
print(f"All NFT files stored and sorted to the Complete_Collection folder in {refactor_panel_input.save_path}")
|
||||
|
||||
shutil.rmtree(refactor_panel_input.nftBatch_save_path)
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue