2
$\begingroup$

Example

Hey guys, I'm writing an blender python exporter and want to be able to export supported cycles material configurations.

Starting simple - diffuse with an image texture input:

diffuse_BSDF = mtl.node_tree.nodes['Diffuse BSDF']

if diffuse_BSDF != None:
   input = diffuse_BSDF.inputs[0]

... then not sure how to access the image texture from input which is a NodeSocketColor.

Thanks in advance for any assistance you can offer.

$\endgroup$

1 Answer 1

3
$\begingroup$

thanks to zeffii :

    diffuse_BSDF = mtl.node_tree.nodes.get('Diffuse BSDF')

    if diffuse_BSDF != None:
        # grab color input
        input = diffuse_BSDF.inputs[0]

        if input.is_linked:
            src = input.links[0].from_node
            if src.type == 'TEX_IMAGE':
                self.File.Write('tex_src:{}\n'.format(src.image.filepath))
            elif src.type == 'MIX_RGB':
                for i in src.inputs:
                    if i.type == 'RGBA':
                        if i.is_linked:
                            src_i = i.links[0].from_node
                            if src_i.type == 'TEX_IMAGE':
                                self.File.Write('tex_src:{}\n'.format(src_i.image.filepath))

(obviously the write function is script specific but maybe that's helpful to others)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.