0
$\begingroup$

I am trying to script a simple exporter that would help me get material data to a webGL engine from Blender 2.8. I am able to get default values of roughness, metallic and transparency. For now this is how it looks:

import bpy

materials_list = []

for mat in  bpy.data.materials:    
    mat_dict = {}
    mat_dict["name"] = mat.name
    mat_dict["roughness"] = mat.node_tree.nodes.get("Principled BSDF").inputs["Roughness"].default_value
    mat_dict["metallic"] = mat.node_tree.nodes.get("Principled BSDF").inputs["Metallic"].default_value
    mat_dict["opacity"] = 1 - mat.node_tree.nodes.get("Principled BSDF").inputs["Transmission"].default_value
    materials_list.append(mat_dict)    
  

print(materials_list)

I tried to extend the script but with no success still. This is how it looks like now:

import bpy

materials_list = []

for mat in  bpy.data.materials:    
    mat_dict = {}
    prinBSDF = mat.node_tree.nodes['Principled BSDF']
    
    mat_dict['name'] = mat.name
    
    if prinBSDF.inputs['Roughness'].type =='TEX_IMAGE':
        mat_dict['roughness'] = prinBSDF.inputs['Roughness'].image.filepath
    else:
        mat_dict['roughness'] = prinBSDF.inputs['Roughness'].default_value

    materials_list.append(mat_dict)    
  
print(materials_list)

It ignores the textures and collects only default values. When remove the part storing default values I get an error: "AttributeError: 'NodeSocketFloatFactor' object has no attribute 'image' ". What am I missing?

$\endgroup$

Your Answer

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

Browse other questions tagged or ask your own question.