def createBubbleMaterial(name, baseColor):
    mat = bpy.data.materials.new(name)
    mat.use_nodes = True
    mat.blend_method = 'BLEND'
    principled = PrincipledBSDFWrapper(mat, is_readonly=False)
    principled.base_color = baseColor
    principled.metallic = 0.5
    principled.specular = 0.2
    principled.roughness = 0.05
    #principled.IOR = 1.1
    principled.alpha = 0.3
    # principled.specular_texture.image = load_image("/path/to/image.png")

    # Export
    principled = PrincipledBSDFWrapper(mat, is_readonly=True)
    base_color = principled.base_color
    specular_texture = principled.specular_texture
    if specular_texture and specular_texture.image:
        specular_texture_filepath = principled.specular_texture.image.filepath
Example #2
0
def handle_materials(context, model, materials, update):
    """
    """
    for m in model.Materials:
        matname = material_name(m)
        if matname not in materials:
            blmat = utils.get_iddata(context.blend_data.materials, None,
                                     m.Name, None)
            if update:
                blmat.use_nodes = True
                refl = m.Reflectivity
                transp = m.Transparency
                ior = m.IndexOfRefraction
                roughness = m.ReflectionGlossiness
                transrough = m.RefractionGlossiness
                spec = m.Shine / 255.0

                if m.DiffuseColor == _black and m.Reflectivity > 0.0 and m.Transparency == 0.0:
                    r, g, b, _ = m.ReflectionColor
                elif m.DiffuseColor == _black and m.Reflectivity == 0.0 and m.Transparency > 0.0:
                    r, g, b, _ = m.TransparentColor
                    refl = 0.0
                elif m.DiffuseColor == _black and m.Reflectivity > 0.0 and m.Transparency > 0.0:
                    r, g, b, _ = m.TransparentColor
                    refl = 0.0
                else:
                    r, g, b, a = m.DiffuseColor
                    if refl > 0.0 and transp > 0.0:
                        refl = 0.0
                principled = PrincipledBSDFWrapper(blmat, is_readonly=False)
                principled.base_color = (r / 255.0, g / 255.0, b / 255.0)
                principled.metallic = refl
                principled.transmission = transp
                principled.ior = ior
                principled.roughness = roughness
                principled.specular = spec
                principled.node_principled_bsdf.inputs[
                    16].default_value = transrough
            materials[matname] = blmat