blenderproc.python.material.MaterialLoaderUtility module

Provides a lot of functions to deal with materials.

blenderproc.python.material.MaterialLoaderUtility.add_alpha(nodes, links, alpha_image_path, principled_bsdf)[source]

Adds alpha to the principled bsdf node.

Parameters:
  • nodes (Nodes) – Nodes from the current material

  • links (NodeLinks) – Links from the current material

  • alpha_image_path (str) – Path to the metal image

  • principled_bsdf (Node) – Principled BSDF node of the current material

Returns:

bpy.types.Node: The newly constructed texture node

blenderproc.python.material.MaterialLoaderUtility.add_alpha_channel_to_textures(blurry_edges)[source]

Adds transparency to all textures, which contain an .png image as an image input

Parameters:

blurry_edges – If True, the edges of the alpha channel might be blurry, this causes errors if the alpha channel should only be 0 or 1

Be careful, when you replace the original texture with something else (Segmentation, …), the necessary texture node gets lost. By copying it into a new material as done in the SegMapRenderer, you can keep the transparency even for those nodes.

blenderproc.python.material.MaterialLoaderUtility.add_alpha_texture_node(used_material, new_material)[source]

Adds to a predefined new_material a texture node from an existing material (used_material) This is necessary to connect it later on in the add_alpha_channel_to_textures

Parameters:
  • used_material – existing material, which might contain a texture node with a .png texture

  • new_material – a new material, which will get a copy of this texture node

Returns:

the modified new_material, if no texture node was found, the original new_material

blenderproc.python.material.MaterialLoaderUtility.add_ambient_occlusion(nodes, links, ambient_occlusion_image_path, principled_bsdf, base_color)[source]

Adds ambient occlusion to the principled bsdf node.

Parameters:
  • nodes (Nodes) – Nodes from the current material

  • links (NodeLinks) – Links from the current material

  • ambient_occlusion_image_path – Path to the ambient occlusion image

  • principled_bsdf (Node) – Principled BSDF node of the current material

  • base_color (Node) – Base color node of the current material

Returns:

bpy.types.Node: The newly constructed texture node

blenderproc.python.material.MaterialLoaderUtility.add_base_color(nodes, links, base_image_path, principled_bsdf)[source]

Adds base color to the principled bsdf node.

Parameters:
  • nodes (Nodes) – Nodes from the current material

  • links (NodeLinks) – Links from the current material

  • base_image_path – Path to the base image

  • principled_bsdf (Node) – Principled BSDF node of the current material

Returns:

bpy.types.Node: The newly constructed texture node

blenderproc.python.material.MaterialLoaderUtility.add_bump(nodes, links, bump_image_path, principled_bsdf)[source]

Adds bump to the principled bsdf node.

Parameters:
  • nodes (Nodes) – Nodes from the current material

  • links (NodeLinks) – Links from the current material

  • bump_image_path (str) – Path to the metal image

  • principled_bsdf (Node) – Principled BSDF node of the current material

Returns:

bpy.types.Node: The newly constructed texture node

blenderproc.python.material.MaterialLoaderUtility.add_displacement(nodes, links, displacement_image_path, output_node)[source]

Adds bump to the principled bsdf node.

Parameters:
  • nodes (Nodes) – Nodes from the current material

  • links (NodeLinks) – Links from the current material

  • displacement_image_path (str) – Path to the metal image

  • output_node (Node) – Output node of the current material

Returns:

bpy.types.Node: The newly constructed texture node

blenderproc.python.material.MaterialLoaderUtility.add_metal(nodes, links, metalness_image_path, principled_bsdf)[source]

Adds metal to the principled bsdf node.

Parameters:
  • nodes (Nodes) – Nodes from the current material

  • links (NodeLinks) – Links from the current material

  • metalness_image_path (str) – Path to the metal image

  • principled_bsdf (Node) – Principled BSDF node of the current material

Returns:

bpy.types.Node: The newly constructed texture node

blenderproc.python.material.MaterialLoaderUtility.add_normal(nodes, links, normal_image_path, principled_bsdf, invert_y_channel)[source]

Adds normal to the principled bsdf node.

Parameters:
  • nodes (Nodes) – Nodes from the current material

  • links (NodeLinks) – Links from the current material

  • normal_image_path (str) – Path to the metal image

  • principled_bsdf (Node) – Principled BSDF node of the current material

  • invert_y_channel (bool) – If this is True the Y Color Channel is inverted.

Returns:

bpy.types.Node: The newly constructed texture node

blenderproc.python.material.MaterialLoaderUtility.add_roughness(nodes, links, roughness_image_path, principled_bsdf)[source]

Adds roughness to the principled bsdf node.

Parameters:
  • nodes (Nodes) – Nodes from the current material

  • links (NodeLinks) – Links from the current material

  • roughness_image_path (str) – Path to the metal image

  • principled_bsdf (Node) – Principled BSDF node of the current material

Returns:

bpy.types.Node: The newly constructed texture node

blenderproc.python.material.MaterialLoaderUtility.add_specular(nodes, links, specular_image_path, principled_bsdf)[source]

Adds specular to the principled bsdf node.

Parameters:
  • nodes (Nodes) – Nodes from the current material

  • links (NodeLinks) – Links from the current material

  • specular_image_path (str) – Path to the metal image

  • principled_bsdf (Node) – Principled BSDF node of the current material

Returns:

bpy.types.Node: The newly constructed texture node

blenderproc.python.material.MaterialLoaderUtility.change_to_texture_less_render(use_alpha_channel)[source]

Changes the materials, which do not contain a emission shader to a white slightly glossy texture

Parameters:

use_alpha_channel – If true, the alpha channel stored in .png textures is used.

blenderproc.python.material.MaterialLoaderUtility.collect_all()[source]

Returns all existing materials.

Return type:

List[Optional[Material]]

Returns:

A list of all materials.

blenderproc.python.material.MaterialLoaderUtility.connect_uv_maps(nodes, links, collection_of_texture_nodes)[source]

Connect all given texture nodes to a newly constructed UV node.

Parameters:
  • nodes (Nodes) – Nodes from the current material

  • links (NodeLinks) – Links from the current material

  • collection_of_texture_nodes (list) – List of :class: bpy.type.Node of type :class: ShaderNodeTexImage

blenderproc.python.material.MaterialLoaderUtility.convert_to_materials(blender_materials)[source]

Converts the given list of blender materials to bproc.Material(s)

Parameters:

blender_materials (List[Optional[Material]]) – List of materials.

Return type:

List[Optional[Material]]

Returns:

The list of materials.

blenderproc.python.material.MaterialLoaderUtility.create(name)[source]

Creates a new empty material.

Parameters:

name (str) – The name of the new material.

Return type:

Material

Returns:

The new material.

blenderproc.python.material.MaterialLoaderUtility.create_image_node(nodes, image, non_color_mode=False, x_location=0.0, y_location=0.0)[source]

Creates a texture image node inside a material.

Parameters:
  • nodes (Nodes) – Nodes from the current material

  • image (Union[str, Image]) – Either the path to the image which should be loaded or the bpy.types.Image

  • non_color_mode (bool) – If this True, the color mode of the image will be “Non-Color”

  • x_location (float) – X Location in the node tree

  • y_location (float) – Y Location in the node tree

Returns:

bpy.type.Node: Return the newly constructed image node

blenderproc.python.material.MaterialLoaderUtility.create_material_from_texture(texture, material_name)[source]

Creates a material based on a given texture, the texture can either be a path to a texture file on disc or a already loaded bpy.types.Image.

Parameters:
  • texture (Union[Path, str, Image]) – either a path to an image, or a loaded bpy.types.Image texture

  • material_name (str) – name of the newly created material

Return type:

Material

Returns:

the newly created material, which uses the texture as Base Color

blenderproc.python.material.MaterialLoaderUtility.create_new_cc_material(material_name, add_custom_properties)[source]

Creates a new material, which gets the given custom properties and the material name.

Parameters:
  • material_name (str) – The name of the material

  • add_custom_properties (dict) – The custom properties, which should be added to the material

Return type:

Material

Returns:

bpy.types.Material: Return the newly created material

blenderproc.python.material.MaterialLoaderUtility.create_procedural_texture(pattern_name=None)[source]

Creates a new procedural texture based on a specified pattern.

Parameters:

pattern_name (Optional[str]) – The name of the pattern. Available: [“CLOUDS”, “DISTORTED_NOISE”, “MAGIC”, “MARBLE”, “MUSGRAVE”, “NOISE”, “STUCCI”, “VORONOI”, “WOOD”]. If None is given, a random pattern is used.

Return type:

Texture

Returns:

The created texture

blenderproc.python.material.MaterialLoaderUtility.find_cc_material_by_name(material_name, custom_properties)[source]

Finds from all loaded materials the cc material, which has the given material_name and the given custom_properties.

Parameters:
  • material_name (str) – Name of the searched material

  • custom_properties (Dict[str, Any]) – Custom properties, which have been assigned before

Return type:

Material

Returns:

bpy.types.Material: Return the searched material, if not found returns None

blenderproc.python.material.MaterialLoaderUtility.is_material_used(material)[source]

Checks if the given material is used on any object.

Parameters:

material (Material) – Material, which should be checked

Returns:

True if the material is used