When I import an fbx, it has image textures that should be linked from their Alpha socket to Principled BSDF's Alpha socket, but right now link goes from texture's Color to Principled's Alpha, like this:
I tried to write\find a script that would loop through every material and do this:
- Find Image Texture node and get the name of a texture used, since I don't know their names
- Replace Color -> Alpha link with Alpha -> Alpha link
Every thread I've found about Image texture nodes creates a new node for this and then adds an image. Tried doing it like this, creates an eternal loop:
import bpy
nodes = bpy.context.active_object.active_material.node_tree.nodes
links = bpy.context.active_object.active_material.node_tree.links
principled = nodes.get('Principled BSDF')
for obj in bpy.context.scene.objects:
for s in obj.material_slots:
if s.material and s.material.use_nodes:
for n in s.material.node_tree.nodes:
if n.type == 'TEX_IMAGE':
image_node = nodes.new('ShaderNodeTexImage')
tex = bpy.data.images.get(n.image.name)
image_node.image = tex
links.new(image_node.outputs[1], principled.inputs[18])