Does any one know how to attach texture created with,
tex = bpy.data.textures.new('Flag', type = 'WOOD')
to be used in a ShaderNode ?
tex
does not have tex.image
and the issue is reference code is using
texture_slots.add()
which is deprecated from 2.8. help is greatly appreciated.
this is the function I'm writing. obviously it doesn't work when a texture is passed .
def textured(material_name, texture=None, image=None):
mat = bpy.data.materials.new(material_name)
mat.use_nodes = True
nodes = mat.node_tree.nodes # Get the nodes
nodes.clear()
node_principled = nodes.new(type='ShaderNodeBsdfPrincipled') # Add the Principled Shader node
node_principled.location = 0,0
node_output = nodes.new(type='ShaderNodeOutputMaterial') # Add the Output node
node_output.location = 400,0
node_tex = nodes.new('ShaderNodeTexImage') # Add the Image Texture node
node_tex.location = -400,0
links = mat.node_tree.links # Link all nodes
link = links.new(node_tex.outputs["Color"], node_principled.inputs["Base Color"])
link = links.new(node_principled.outputs["BSDF"], node_output.inputs["Surface"])
if texture:
node_tex.image = texture.image
elif image:
img = bpy.data.images.get(image) # Get the image and assign it to the Node.image
if img: node_tex.image = img
else: node_tex.image = bpy.data.images.load(image) # Assign the image
return mat
```