ddg.blender.material module

ddg.blender.material.set_material(bobj_or_mesh, material, protect=True)[source]

Assigns a material to a Blender object or mesh.

If a material is not a bpy.types.Material but rather its name, then it will assign the material with that name. A new material is creates if it did not exist before!

Parameters:
bobj_or_mesh: bpy.types.Object or bpy.types.Mesh

The Blender object the material is assigned to.

material: str or bpy.types.Material

Name of the material or actual material object

protect: bool (default=True)

If True, the material is protected from being deleted when unused. Is only applied if the material did not exist before!

Returns:
bobj_or_meshbpy.types.Object or bpy.types.Mesh
ddg.blender.material.protect_material(material)[source]

Protects given material from being deleted after reloading the file if not in use.

Parameters:
materialstr or bpy.types.Material

Name of the material or actual material object. Must exist.

ddg.blender.material.material(name='DDG Material', color=(1, 1, 1), specular=1.0, roughness=0.5, alpha=1.0)[source]

Create a Principled BSDF material.

Parameters:
namestr (default=”DDG Material”)

The name of the material.

color3-tuple (default=(1,1,1))

The color in RGB base.

specularfloat (default=1.0)

The specular value in [0,1]

roughnessfloat (default=0.5)

The roughness value in [0,1]

alphafloat (default=1.0)

The alpha value in [0,1]

Returns:
bpy.types.Material
ddg.blender.material.clear(materials=None, only_unused=False)[source]

Delete all given materials.

Parameters:
materialsIterable of bpy.types.Material (default=None)

Materials to be deleted. If argument is not provided or None, all materials will be deleted.

only_unusedbool (default=False)

Removes all unused material. If an Iterable of materials is given as first parameter, only those are effected, otherwise all materials.

ddg.blender.material.set_transparency(mat, alpha=0.5, blend_method='HASHED')[source]

Setup a BSDF material for transparent rendering.

The oppacity then corresponds to the ‘alpha’ value of the material. It can be set using set_value. The default alpha value is 0.5, which corresponds to 50% opacity.

Parameters:
mat: bpy.tyes.Material with a BSDF node.

Material to make transparent.

alpha: float between 0 and 1 (default=0.5)

Opacity of the material. 0 is transparent, 1 is opaque.

blend_method: valid string for bpy.types.Material.blend_method (default=”HASHED”)

Method used by real-time renderers, i.e. Eevee, to blend the transparent material with its background.

Returns:
bpy.types.Material

See also

ddg.blender.material.transparent_material
ddg.blender.material.set_value(mat, name, value)[source]

Set a value for an input of a BSDF material.

Parameters:
mat: bpy.types.Material
name: str

Name of the input. (For example alpha)

value: Any

Value to set for the input.

Returns:
bpy.types.Material