Creating and Setting Materials

pyddg provides utilities to work with simple Blender materials.

Warning

All our utilities only create and work with materials consisting of a single Principled BSDF node.

Quick start

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

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

bobj = ddg.to_blender_object(
    ddg.datastructures.halfedge.surface_generator.dodecahedron()
)
mat = material()
set_material(bobj, mat)
../../../_images/default.png

One can also set any existing material by refering to its name. If the material does not exist, a new one is created with default parameters.

set_material(bobj, "My Material")

More options at creation

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)
../../../_images/blue.png

Color

The color argument sets the color as a (red, green, blue) tuple with values between 0 and 1. So (1, 0, 0) is red and (0, 1, 1) is cyan.

Shininess

The specular value is a mesure of the shininess, while the roughness quantifies how sharp this shininess appears. It is best to play with these parameters to get a feeling for their effects.

Transparency

The alpha argument sets the opacity of the material.

mat = mat = material(
    name="Transparent Material", color=(0, 0, 1), specular=1, roughness=0.1, alpha=0.3
)
set_material(bobj, mat)
../../../_images/transparent.png

Modifying materials

Arbitrary input parameters of the BSDF node of a material can be changed this way:

from ddg.visualization.blender.material import set_value

set_value(mat, "base color", (0, 0.5, 0, 1))
set_value(mat, "specular", 0)
set_value(mat, "alpha", 1)
../../../_images/modified.png