Blender: Converting textures imported from obj to emissive materials
The snippet can be accessed without any authentication.
Authored by
Christian Mattes
obj-to-cycles-emissive.py 1.35 KiB
import bpy
mats = bpy.data.materials
for mat in mats:
mat.use_nodes = True
tree = mat.node_tree
links = tree.links
for n in tree.nodes:
tree.nodes.remove(n)
#diffuse = tree.nodes.new("ShaderNodeBsdfDiffuse")
diffuse = tree.nodes.new("ShaderNodeEmission")
diffuse.location = (0,-100)
output = tree.nodes.new("ShaderNodeOutputMaterial")
output.location = (400, 0)
mix = tree.nodes.new("ShaderNodeMixShader")
mix.location = (200,0)
mix.inputs[0].default_value = 1.0
links.new(mix.outputs[0], output.inputs[0])
transparent = tree.nodes.new("ShaderNodeBsdfTransparent")
transparent.location = (0,-250)
links.new(transparent.outputs[0], mix.inputs[1])
threshold = tree.nodes.new("ShaderNodeMath")
threshold.location = (0,150)
threshold.operation = "GREATER_THAN"
links.new(threshold.outputs[0], mix.inputs[0])
links.new(diffuse.outputs[0], mix.inputs[2])
textures = mat.texture_slots
for tex in textures:
print(tex)
if tex and tex.texture.type=='IMAGE':
img = tex.texture.image
texnode = tree.nodes.new("ShaderNodeTexImage")
texnode.location = (-200,0)
texnode.image = img
links.new(texnode.outputs[0],diffuse.inputs[0])
links.new(texnode.outputs[1],threshold.inputs[0])
break
Please register or sign in to comment