DEV Community

Cover image for Create NFT 3D Collectibles Using Blender Scripting

Create NFT 3D Collectibles Using Blender Scripting

hideckies on November 21, 2021

I wanted to create 3D characters for about 1000+ NFT Collectibles, but didn't know how to do that. It's stupid to create all models one by one manu...
Collapse
 
thankgod_jacob_3ec2e40787 profile image
ThankGod Jacob

Hello, can I edit and make use of your NFT example as the base model for my own NFT collection?

Collapse
 
hideckies profile image
hideckies

Hello. Sure, feel free to use it.

Collapse
 
yojirasuro profile image
Yoji Rasuro

Hi there! Thank you so much for the script, it's seems great!
However, I don't know how to use it. -_-"
I tried using this with the files you provided but I keep getting snagged at the duplicate error. I don't understand what I should be doing to go past that. :(
What duplicates is it talking about?

Collapse
 
hideckies profile image
hideckies

Hi, thanks!

As I said here, please set TOTAL_CHARACTERS = 2. I think it will probably work. Anyway, repeat "Run" until you succeed.

This error occurs when the combination of parts is duplicated.
Our ideal is to create a unique collection, so we have to avoid the exact same characters.

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
hideckies profile image
hideckies

Hi,

How do I make it so that it uses the second character only if a t-shirt is selected to be displayed?

Such a case, you can add the optional code after random.choice() in gen_metadata.py

def rand_attributes(id):
    # ...
    random_model = random.choice(...
    random_clothes = random.choice(...

    # Add it!
    if random_clothes == "t-shirts":
        random_model = "another"    # assumed that the model names are "original" and "another"

    # ...
    random_model = random_model.replace(...
    random_clothes = random_clothes.replace(...

    attributes = [...]
Enter fullscreen mode Exit fullscreen mode
Collapse
 
raul_proppe profile image
Proppe

Hi hideckies I'm using your code (thanks btw). I made some NFTS to test and I notice that the PNG number differs from the JSON file number after 3 renders. Is that a reason for that? Thank you for you time.

Collapse
 
shekhar04487389 profile image
chapapa

Thanks bruv…great help. I’ve been looking for this since so long haha

Collapse
 
teampermanent profile image
Permanent ®

Hey, amazing information here, thanks a lot! Is It possible to create that kind of script in cinema4d?

Collapse
 
hideckies profile image
hideckies

Thank you! But sorry, I don't know about Cinema4D.

Collapse
 
k0nd0r3 profile image
Serie Tv Streaming Sub ITA

hello, thank you it was really very useful
I have a question
I only have 1 model, 1 head
to this I want to apply different textures and backgrounds
in order to release various versions

is it possible to do this with this script?

Thread Thread
 
hideckies profile image
hideckies

In that case, add multiple materials(textures) to the object (e.g. material names are "material_1", "material_2", so on) in advance, then you can write for example:

# gen_metadata.py

# List
list_background = [black, red, green, ...]
list_head = [material_1, material_2, ...]

random_background = random.choice(list_background)
# ...

attributes = [
    {
        "trait_type": "Background",
        "value": random_background
    },
    # ...
]
Enter fullscreen mode Exit fullscreen mode
# gen_model.py

# Assign background material
def assign_background_material(material_name):
    # Get the object named "background" in the "misc" collection from the scene
    background_object = bpy.data.objects["background"]

    # Set the material you want to assign
    target_material = bpy.data.materials.get(material_name)

    # Assign material
    background_object.data.materials[0] = target_material

# Append head
def append_head(trait_value):
    # Set the material name (e.g. "material_1", "material_2", etc)
    material_name = trait_value

    # Append "head" collection in the scene
    path = PARTS_DIR + "head/head.blend/Collection/"
    bpy.ops.wm.append(filename="head", directory=path)

    # Get the "head" collection
    head_col = bpy.data.collections["head"]

     # Assign material
    target_material = bpy.data.materials.get(material_name)
    for head in head_col.objects:
        head.data.materials[0] = target_material

# Generate
def generate(id, metadata):
    # Background
   if attr in metadata["attributes"]:
        if attr["trait_type"] == "Background" and attr["value"] != "":
            assign_background_material(attr["value"])
    # ....
Enter fullscreen mode Exit fullscreen mode
Collapse
 
kite16 profile image
kite16

how do I run this on a render farm, should I code it so that it makes 4444 .blend files?
I would appreciate it if you could include the code in the comments :))

Collapse
 
hideckies profile image
hideckies

Sorry I don't use a render farm, so I have no idea.

Collapse
 
katonacsaba profile image
CsabaKatona

Hey, is there any way that i could generate to .blender files instead of PNG?

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
hideckies profile image
hideckies

What's the IRL Apes SC? I'm not a blender master, but I'm interested.

Collapse
 
hideckies profile image
hideckies

Exactly, I've added the demo repository.
Please check it!

github.com/hideckies/nft-collectib...