random-geek / meshport

Easily export areas in Minetest to meshes for 3D rendering.
GNU Lesser General Public License v3.0
36 stars 7 forks source link

materials.py conversion script for Blender 3.0 #9

Closed sbrl closed 2 years ago

sbrl commented 2 years ago

I found the included materials.py script doesn't work very well in Blender 3.0 - it makes all materials very light in colour and difficult to see.

To fix this problem, @VorTechnix and I wrote a new script:

import bpy

context = bpy.context

for o in context.selected_objects:
    for m in o.material_slots:
        print(m.material.name)
        m.material.blend_method = 'HASHED'

        node_tree = m.material.node_tree

        if node_tree.nodes.find('Image Texture') > -1:
            node_tree.nodes['Image Texture'].interpolation = "Closest"
            node_tree.links.new(
                node_tree.nodes['Image Texture'].outputs['Alpha'],
                node_tree.nodes['Principled BSDF'].inputs['Alpha']
            )


I don't think it does everything the old one did, but it works well enough at least.

Posting here just in case it's useful for others.

random-geek commented 2 years ago

A couple new inputs got added to the Principled shader, so now the old script links texture alpha to emission. 🤦‍♂️

Addressing sockets by their string names is a good idea, as well as only modifying selected objects. I'll take a look at this script and maybe integrate some of those ideas into materials.py.

random-geek commented 2 years ago

Should be fixed now; thanks for the suggestions!

sbrl commented 2 years ago

Awesome, thanks! I'll give it a try.

random-geek commented 2 years ago

Changes have been released, closing.