anata
๐ Download layers:
๐ Github: https://github.com/M3-org/anata/issues/8
๐ฃ Dework: https://app.dework.xyz/webaverse/anata-81736?taskId=965a126f-8827-425d-95af-140f726cd7ea
import bpy
## Make every material in scene principled bsdf
## Blend file only had image texture node per material
# Get the active scene
scene = bpy.context.scene
# Iterate through all visible objects in the scene
for obj in bpy.context.visible_objects:
# Set the object as the active object
bpy.context.view_layer.objects.active = obj
# Check if the object has a material
if obj.material_slots:
# Iterate through all material slots of the object
for slot in obj.material_slots:
# Get the material of the slot
material = slot.material
# Check if the material has a node tree
if material.use_nodes:
# Get the material's node tree
tree = material.node_tree
# Create a list to store the Image Texture nodes
image_nodes = []
# Iterate through all nodes in the node tree
for node in tree.nodes:
# Check if the node is an Image Texture node
if node.type == 'TEX_IMAGE':
# Append the Image Texture node to the list
image_nodes.append(node)
# Create a Principled BSDF node
principled_node = tree.nodes.new('ShaderNodeBsdfPrincipled')
# Connect each Image Texture node to the Base Color input of the Principled BSDF node
for image_node in image_nodes:
# Get the output socket of the Image Texture node
output_socket = image_node.outputs['Color']
# Connect the Image Texture node to the Base Color input of the Principled BSDF node
tree.links.new(output_socket, principled_node.inputs['Base Color'])
# Create a Material Output node
output_node = tree.nodes.new('ShaderNodeOutputMaterial')
# Connect the BSDF output of the Principled BSDF node to the Surface input of the Material Output node
tree.links.new(principled_node.outputs['BSDF'], output_node.inputs['Surface'])
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up