def preview_bake_texture(self, context):
    context = bpy.context
    bake_settings = context.scene.bake_settings
    preview_bake_texture = context.scene.texture_settings.preview_bake_texture
    vis_mats = material_functions.get_all_visible_materials()
    for mat in vis_mats:
        if (not mat.node_tree):
            continue
        nodes = mat.node_tree.nodes
        bake_texture_node = None
        if bake_settings.lightmap_bake:
            bake_texture_node = nodes.get(bake_settings.texture_node_lightmap)
        elif bake_settings.ao_bake:
            bake_texture_node = nodes.get(bake_settings.texture_node_ao)
        if (bake_texture_node is not None):
            if preview_bake_texture:
                node_functions.emission_setup(mat, bake_texture_node.outputs['Color'])
            else:
                pbr_node = node_functions.get_nodes_by_type(nodes, constants.Node_Types.pbr_node)
                if (len(pbr_node) == 0):
                    return
                pbr_node = pbr_node[0]
                node_functions.remove_node(mat, 'Emission Bake')
                node_functions.reconnect_PBR(mat, pbr_node)
def preview_bake_texture(self, context):
    context = bpy.context
    bake_settings = context.scene.bake_settings
    preview_bake_texture = context.scene.texture_settings.preview_bake_texture
    vis_mats = material_functions.get_all_visible_materials()
    for mat in vis_mats:
        if (not mat.node_tree):
            continue
        nodes = mat.node_tree.nodes
        bake_texture_node = None
        if bake_settings.lightmap_bake:
            bake_texture_node = nodes.get(bake_settings.texture_node_lightmap)
        elif bake_settings.ao_bake:
            bake_texture_node = nodes.get(bake_settings.texture_node_ao)
        if (bake_texture_node is not None):
            if preview_bake_texture:
                node_functions.emission_setup(mat, bake_texture_node.outputs['Color'])
            else:
                pbr_node = node_functions.get_nodes_by_type(nodes, constants.Node_Types.pbr_node)
                if (len(pbr_node) == 0):
                    return
                pbr_node = pbr_node[0]
                node_functions.remove_node(mat, 'Emission Bake')
                node_functions.reconnect_PBR(mat, pbr_node)