blenderproc.python.types.MaterialUtility module
The material class containing the texture and material properties.
- class blenderproc.python.types.MaterialUtility.Material(material)[source]
Bases:
Struct
The material class containing the texture and material properties, which are assigned to the surfaces of MeshObjects.
- duplicate()[source]
Duplicates the material.
- Return type:
- Returns:
The new material which is a copy of this one.
- get_node_connected_to_the_output_and_unlink_it()[source]
Searches for the OutputMaterial in the material and finds the connected node to it, removes the connection between this node and the output and returns this node and the material_output
- get_nodes_created_in_func(created_in_func)[source]
Returns all nodes which are of the given node_type
- Parameters:
created_in_func (
str
) – return all nodes created in the given function- Return type:
List
[Node
]- Returns:
The list of nodes with the given type.
- get_nodes_with_type(node_type, created_in_func='')[source]
Returns all nodes which are of the given node_type
- Parameters:
node_type (
str
) – The note type to look for.created_in_func (
str
) – only return nodes created by the specified function
- Return type:
List
[Node
]- Returns:
The list of nodes with the given type.
- get_principled_shader_value(input_name)[source]
Gets the default value or the connected node socket to an input socket of the principled shader node of the material.
- Parameters:
input_name (
str
) – The name of the input socket of the principled shader node.- Return type:
Union
[float
,NodeSocket
]- Returns:
the connected socket to the input socket or the default_value of the given input_name
- get_the_one_node_with_type(node_type, created_in_func='')[source]
Returns the one node which is of the given node_type
This function will only work if there is only one of the nodes of this type.
- Parameters:
node_type (
str
) – The node type to look for.created_in_func (
str
) – only return node created by the specified function
- Return type:
Node
- Returns:
The node.
- get_users()[source]
Returns the number of users of the material.
- Return type:
int
- Returns:
The number of users.
- infuse_material(material, mode='mix', mix_strength=0.5)[source]
Infuse a material inside another material. The given material, will be adapted and the used material, will be added, depending on the mode either as add or as mix. This change is applied to all outputs of the material, this includes the Surface (Color) and also the displacement and volume. For displacement mix means multiply.
- Parameters:
material (
Material
) – Material to infuse.mode (
str
) – The mode determines how the two materials are mixed. There are two options “mix” in which the preexisting material is mixed with the selected one in “used_material” or “add” in which they are just added on top of each other. Available: [“mix”, “add”]mix_strength (
float
) – In the “mix” mode a strength can be set to determine how much of each material is going to be used. A strength of 1.0 means that the new material is going to be used completely.
- infuse_texture(texture, mode='overlay', connection='Base Color', texture_scale=0.05, strength=0.5, invert_texture=False)[source]
Overlays the selected material with a texture, this can be either a color texture like for example dirt or it can be a texture, which is used as an input to the Principled BSDF of the given material.
- Parameters:
texture (
Texture
) – A texture which should be infused in the material.mode (
str
) – The mode determines how the texture is used. There are three options: “overlay” in which the selected texture is overlayed over a preexisting one. If there is none, nothing happens. The second option: “mix” is similar to overlay, just that the textures are mixed there. The last option: “set” replaces any existing texture and is even added if there was none before.connection (
str
) – By default the “Base Color” input of the principled shader will be used. This can be changed to any valid input of a principled shader. Default: “Base Color”. For available check the blender documentation.texture_scale (
float
) – The used texture can be scaled down or up by a factor, to make it match the preexisting UV mapping. Make sure that the object has a UV mapping beforehand.strength (
float
) – The strength determines how much the newly generated texture is going to be used.invert_texture (
bool
) – It might be sometimes useful to invert the input texture, this can be done by setting this to True.
- insert_node_instead_existing_link(source_socket, new_node_dest_socket, new_node_src_socket, dest_socket)[source]
Replaces the node between source_socket and dest_socket with a new node.
Before: source_socket -> dest_socket After: source_socket -> new_node_dest_socket and new_node_src_socket -> dest_socket
- Parameters:
source_socket (
NodeSocket
) – The source socket.new_node_dest_socket (
NodeSocket
) – The new destination for the link starting from source_socket.new_node_src_socket (
NodeSocket
) – The new source for the link towards dest_socket.dest_socket (
NodeSocket
) – The destination socket
- link(source_socket, dest_socket)[source]
Creates a new link between the two given sockets.
- Parameters:
source_socket (
NodeSocket
) – The source socket.dest_socket (
NodeSocket
) – The destination socket
- make_emissive(emission_strength, replace=False, emission_color=None, non_emissive_color_socket=None)[source]
Makes the material emit light.
- Parameters:
emission_strength (
float
) – The strength of the emitted light.replace (
bool
) – When replace is set to True, the existing material will be completely replaced by the emission shader, otherwise it still looks the same, while emitting light.emission_color (
Optional
[List
[float
]]) – The color of the light to emit. Default: Color of the original object.non_emissive_color_socket (
Optional
[NodeSocket
]) – An output socket that defines how the material should look like. By default, that is the output of the principled shader node. Has no effect if replace is set to True.
- map_vertex_color(layer_name='Col', active_shading=True)[source]
Maps existing vertex color to the base color of the principled bsdf node or a new background color node.
- Parameters:
layer_name (
str
) – Name of the vertex color layer. Type: string.active_shading (
bool
) – Whether to keep the principled bsdf shader. If True, the material properties influence light reflections such as specularity, roughness, etc. alter the object’s appearance. Type: bool.
- new_node(node_type, created_in_func='')[source]
Creates a new node in the material’s node tree.
- Parameters:
node_type (
str
) – The desired type of the new node.created_in_func (
str
) – Save the function name in which this node was created as a custom property. Allows to later retrieve and delete specific nodes again.
- Return type:
Node
- Returns:
The new node.
- remove_node(node)[source]
Removes the node from the material’s node tree.
- Parameters:
node (
Node
) – The node to remove.
- set_displacement_from_principled_shader_value(input_name, multiply_factor)[source]
Connects the node that is connected to the specified input of the principled shader node with the displacement output of the material.
- Parameters:
input_name (
str
) – The name of the input socket of the principled shader node.multiply_factor (
float
) – A factor by which the displacement should be multiplied.
- set_principled_shader_value(input_name, value)[source]
Sets value of an input to the principled shader node.
- Parameters:
input_name (
str
) – The name of the input socket of the principled shader node.value (
Union
[float
,Image
,NodeSocket
]) – The value to set. Can be a simple value to use as default_value, a socket which will be connected to the input or an image which will be used for a new TextureNode connected to the input.