Skip to content

Commit

Permalink
Merge pull request #79 from torrinworx/Rarity_Check_and_Duplicate_Check
Browse files Browse the repository at this point in the history
Logic Always with Rule, Resume Failed Batches | BMNFTs V3.0
  • Loading branch information
torrinworx authored Mar 27, 2022
2 parents d37fc69 + 4c945a9 commit bc5568b
Show file tree
Hide file tree
Showing 12 changed files with 676 additions and 409 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ The best way to understand how Logic works is to think of it as a sentence, exam
## Example Logic.json File
Say we have the following scene in a .blend file:
<img width="420" alt="Screen Shot 2022-03-13 at 4 21 52 PM" src="https://user-images.githubusercontent.com/82110564/158077693-86f961cf-c121-4d0e-8a84-1d6a39e7cafc.png">
Note that we have two Attributes, ``Cube`` and ``Sphere``, and that they have 4 Variants. If you'd like to follow along with this exmaple I'd recommend downloading the [Logic_Example.blend](https://github.com/torrinworx/BMNFTs_Examples/blob/main/Logic_Example.blend).
Note that we have two Attributes, ``Cube`` and ``Sphere``, and that they have 4 Variants. If you'd like to follow along with this example I'd recommend downloading the [Logic_Example.blend](https://github.com/torrinworx/BMNFTs_Examples/blob/main/Logic_Example.blend).

### Never with, Logic Rule Examples
- **Never with, Variants example:**
Expand Down
92 changes: 65 additions & 27 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
bl_info = {
"name": "Blend_My_NFTs",
"author": "Torrin Leonard, This Cozy Studio Inc",
"version": (2, 0, 0),
"version": (3, 0, 0),
"blender": (3, 0, 0),
"location": "View3D",
"description": "Blend_My_NFTs UI Edition",
"description": "An open source, free to use Blender add-on that enables you to create thousands of unique images, animations, and 3D models.",
"category": "Development",
}

Expand All @@ -14,25 +14,26 @@
from bpy.app.handlers import persistent

import os
import json
import importlib

# Import files from main directory:

importList = ['DNA_Generator', 'Batch_Sorter', 'Exporter', 'Batch_Refactorer', 'get_combinations', 'UIList']

if bpy in locals():
importlib.reload(DNA_Generator)
importlib.reload(Batch_Sorter)
importlib.reload(Exporter)
importlib.reload(Refactorer)
importlib.reload(get_combinations)
importlib.reload(Checks)

else:
from .main import \
DNA_Generator, \
Batch_Sorter, \
Exporter, \
Refactorer, \
get_combinations
get_combinations, \
Checks

# User input Property Group:
class BMNFTS_PGT_MyProperties(bpy.types.PropertyGroup):
Expand Down Expand Up @@ -164,6 +165,7 @@ def update_combinations(dummy1, dummy2):

bpy.app.handlers.depsgraph_update_post.append(update_combinations)


# Main Operators:
class createData(bpy.types.Operator):
bl_idname = 'create.data'
Expand All @@ -184,7 +186,7 @@ def execute(self, context):

Blend_My_NFTs_Output, batch_json_save_path, nftBatch_save_path = make_directories(save_path)

DNA_Generator.send_To_Record_JSON(nftName, maxNFTs, nftsPerBatch, save_path, enableRarity, enableLogic, logicFile, Blend_My_NFTs_Output)
DNA_Generator.send_To_Record_JSON(maxNFTs, nftsPerBatch, save_path, enableRarity, enableLogic, logicFile, Blend_My_NFTs_Output)
Batch_Sorter.makeBatches(nftName, maxNFTs, nftsPerBatch, save_path, batch_json_save_path)

self.report({'INFO'}, f"NFT Data created!")
Expand Down Expand Up @@ -214,16 +216,56 @@ def execute(self, context):
enableModelsBlender = bpy.context.scene.my_tool.modelBool
modelFileFormat = bpy.context.scene.my_tool.modelEnum

# fail state variables, set to no fail due to resume_failed_batch() Operator in BMNFTS_PT_GenerateNFTs Panel
fail_state = False
failed_batch = None
failed_dna = None
failed_dna_index = None

Exporter.render_and_save_NFTs(nftName, maxNFTs, batchToGenerate, batch_json_save_path, nftBatch_save_path, enableImages,
imageFileFormat, enableAnimations, animationFileFormat, enableModelsBlender,
modelFileFormat
modelFileFormat, fail_state, failed_batch, failed_dna, failed_dna_index
)

self.report({'INFO'}, f"All NFTs generated for batch {batchToGenerate}!")

return {"FINISHED"}

class resume_failed_batch(bpy.types.Operator):
bl_idname = 'exporter.resume_nfts'
bl_label = 'Resume Failed Batch'
bl_description = 'Failed Batch detected. Generate NFTs where the previous batch failed?'
bl_options = {"REGISTER", "UNDO"}

def execute(self, context):
nftName = bpy.context.scene.my_tool.nftName
save_path = bpy.path.abspath(bpy.context.scene.my_tool.save_path)
batchToGenerate = bpy.context.scene.my_tool.batchToGenerate
maxNFTs = bpy.context.scene.my_tool.collectionSize

Blend_My_NFTs_Output, batch_json_save_path, nftBatch_save_path = make_directories(save_path)
fail_state, failed_batch, failed_dna, failed_dna_index = Checks.check_FailedBatches(batch_json_save_path)

file_name = os.path.join(batch_json_save_path, "Batch{}.json".format(batchToGenerate))
batch = json.load(open(file_name))

nftBatch_save_path = batch["Generation Save"][-1]["Render_Settings"]["nftBatch_save_path"]
enableImages = batch["Generation Save"][-1]["Render_Settings"]["enableImages"]
imageFileFormat = batch["Generation Save"][-1]["Render_Settings"]["imageFileFormat"]
enableAnimations = batch["Generation Save"][-1]["Render_Settings"]["enableAnimations"]
animationFileFormat = batch["Generation Save"][-1]["Render_Settings"]["animationFileFormat"]
enableModelsBlender = batch["Generation Save"][-1]["Render_Settings"]["enableModelsBlender"]
modelFileFormat = batch["Generation Save"][-1]["Render_Settings"]["modelFileFormat"]

Exporter.render_and_save_NFTs(nftName, maxNFTs, failed_batch, batch_json_save_path, nftBatch_save_path, enableImages,
imageFileFormat, enableAnimations, animationFileFormat, enableModelsBlender,
modelFileFormat, fail_state, failed_batch, failed_dna, failed_dna_index
)

self.report({'INFO'}, f"Resuming Failed Batch Generation!")

return {"FINISHED"}

class refactor_Batches(bpy.types.Operator):
"""Refactor your collection? This action cannot be undone."""
bl_idname = 'refactor.batches'
Expand Down Expand Up @@ -337,9 +379,20 @@ def draw(self, context):
row = layout.row()
row.prop(mytool, "batchToGenerate")

row = layout.row()
self.layout.operator("exporter.nfts", icon='RENDER_RESULT', text="Generate NFTs")
save_path = bpy.path.abspath(bpy.context.scene.my_tool.save_path)
Blend_My_NFTs_Output, batch_json_save_path, nftBatch_save_path = make_directories(save_path)
fail_state, failed_batch, failed_dna, failed_dna_index = Checks.check_FailedBatches(batch_json_save_path)
if fail_state:
row = layout.row()
self.layout.operator("exporter.nfts", icon='RENDER_RESULT', text="Generate NFTs")

row = layout.row()
row.alert = True
row.operator("exporter.resume_nfts", icon='ERROR', text="Resume Failed Batch")

if not fail_state:
row = layout.row()
self.layout.operator("exporter.nfts", icon='RENDER_RESULT', text="Generate NFTs")
# Refactor Batches & create MetaData Panel:
class BMNFTS_PT_Refactor(bpy.types.Panel):
bl_label = "Refactor Batches & create MetaData"
Expand Down Expand Up @@ -393,7 +446,7 @@ def draw(self, context):
row.prop(mytool, "customfieldsFile")

row = layout.row()
self.layout.operator("refactor.batches", icon='FOLDER_REDIRECT', text="Refactor Batches & create MetaData")
self.layout.operator("refactor.batches", icon='FOLDER_REDIRECT', text="Refactor Batches & Create MetaData")

# Documentation Panel:
class BMNFTS_PT_Documentation(bpy.types.Panel):
Expand Down Expand Up @@ -426,21 +479,6 @@ def draw(self, context):
# scene = context.scene
# mytool = scene.my_tool
#
# # API Panel:
# class BMNFTS_PT_API_Panel(bpy.types.Panel):
# bl_label = "API"
# bl_idname = "BMNFTS_PT_API_Panel"
# bl_space_type = 'VIEW_3D'
# bl_region_type = 'UI'
# bl_category = 'Blend_My_NFTs'
#
# def draw(self, context):
# layout = self.layout
# scene = context.scene
# mytool = scene.my_tool
#
# row = layout.row()
# row.prop(mytool, "apiKey")

def redraw_panel():
try:
Expand All @@ -460,10 +498,10 @@ def redraw_panel():

# Other panels:
# BMNFTS_PT_MATERIALS_Panel,
# BMNFTS_PT_API_Panel,

createData,
exportNFTs,
resume_failed_batch,
refactor_Batches,
)

Expand Down
10 changes: 4 additions & 6 deletions main/Batch_Sorter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ def makeBatches(nftName, maxNFTs, nftsPerBatch, save_path, batch_json_save_path)
j = 0
while (j < nftsPerBatch) and (DNAList):
oneDNA = random.choice(DNAList)
BatchDNAList.append(oneDNA)
BatchDNAList.append({
oneDNA: {"Complete": False}
})
DNAList.remove(oneDNA)
j += 1

Expand All @@ -57,7 +59,7 @@ def makeBatches(nftName, maxNFTs, nftsPerBatch, save_path, batch_json_save_path)

i += 1

if len(DNAList) > 0:
if len(DNAList) > 0: # Add to Checks.py
print(f"One batch could not be filled completely and will contain {len(DNAList)} NFTs.")

incompleteBatch = {"NFTs_in_Batch": int(len(DNAList)), "hierarchy": hierarchy, "BatchDNAList": DNAList}
Expand All @@ -66,7 +68,3 @@ def makeBatches(nftName, maxNFTs, nftsPerBatch, save_path, batch_json_save_path)

with open(os.path.join(batch_json_save_path, ("Batch{}.json".format(i + 1))), "w") as outfile2:
outfile2.write(incompleteBatch)


if __name__ == '__main__':
makeBatches()
Loading

0 comments on commit bc5568b

Please sign in to comment.