Creating and setting materials

To create and set materials of Blender objects one can use:

import ddg
from ddg.visualization.blender.material import set_material, material

bobj = ddg.to_blender_object(
    ddg.datastructures.halfedge.surface_generator.dodecahedron()
)
mat = material()
set_material(bobj, mat)

One can set basic properties of the materials this way:

mat = material(
    name="Custom Material", color=(0, 0, 1), specular=1, roughness=0.1, alpha=1
)
set_material(bobj, mat)

One can access all the inputs of the “Principled BSDF” node of the material using an input dictionary:

input_dict = {
    "Base Color": (1, 0, 0, 1),
    "Specular": 0.5,
    "Roughness": 1,
    "Alpha": 0.5,
    "Metallic": 1,
}
mat = material(input_dict=input_dict)
set_material(bobj, mat)

One can also set any existing material by refering to its name:

set_material(bobj, "My Material")