Пример #1
0
    def insert_node_instead_existing_link(
            self, source_socket: bpy.types.NodeSocket,
            new_node_dest_socket: bpy.types.NodeSocket,
            new_node_src_socket: bpy.types.NodeSocket,
            dest_socket: bpy.types.NodeSocket):
        """ 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

        :param source_socket: The source socket.
        :param new_node_dest_socket: The new destination for the link starting from source_socket.
        :param new_node_src_socket: The new source for the link towards dest_socket.
        :param dest_socket: The destination socket
        """
        Utility.insert_node_instead_existing_link(self.links, source_socket,
                                                  new_node_dest_socket,
                                                  new_node_src_socket,
                                                  dest_socket)
def set_denoiser(denoiser: Optional[str]):
    """ Enables the specified denoiser.

    Automatically disables all previously activated denoiser.

    :param denoiser: The name of the denoiser which should be enabled. Options are "INTEL", "BLENDER" and None. \
                     If None is given, then no denoiser will be active.
    """
    # Make sure there is no denoiser active
    _disable_all_denoiser()
    if denoiser is None:
        pass
    elif denoiser.upper() == "INTEL":
        # The intel denoiser is activated via the compositor
        bpy.context.scene.use_nodes = True
        nodes = bpy.context.scene.node_tree.nodes
        links = bpy.context.scene.node_tree.links

        # The denoiser gets normal and diffuse color as input
        bpy.context.view_layer.use_pass_normal = True
        bpy.context.view_layer.use_pass_diffuse_color = True

        # Add denoiser node
        denoise_node = nodes.new("CompositorNodeDenoise")

        # Link nodes
        render_layer_node = Utility.get_the_one_node_with_type(nodes, 'CompositorNodeRLayers')
        composite_node = Utility.get_the_one_node_with_type(nodes, 'CompositorNodeComposite')
        Utility.insert_node_instead_existing_link(links,
                                                  render_layer_node.outputs['Image'],
                                                  denoise_node.inputs['Image'],
                                                  denoise_node.outputs['Image'],
                                                  composite_node.inputs['Image'])

        links.new(render_layer_node.outputs['DiffCol'], denoise_node.inputs['Albedo'])
        links.new(render_layer_node.outputs['Normal'], denoise_node.inputs['Normal'])
    elif denoiser.upper() == "BLENDER":
        bpy.context.view_layer.cycles.use_denoising = True
    else:
        raise Exception("No such denoiser: " + denoiser)