Example #1
0
    def set_nmap_flavor(node_tree, switch_on):
        """Set normal map flavor to this shader.

        :param node_tree: node tree of current shader
        :type node_tree: bpy.types.NodeTree
        :param switch_on: flag indication if normal map should be switched on or off
        :type switch_on: bool
        """

        if switch_on:

            # find minimal y position for input nodes and position flavor beneath it
            min_y = None
            for node in node_tree.nodes:
                if node.location.x <= 185 and (min_y is None
                                               or min_y > node.location.y):
                    min_y = node.location.y

            lighting_eval_n = node_tree.nodes[Dif.LIGHTING_EVAL_NODE]
            geom_n = node_tree.nodes[Dif.GEOM_NODE]
            location = (lighting_eval_n.location.x - 185, min_y - 400)

            nmap.init(node_tree, location,
                      lighting_eval_n.inputs['Normal Vector'],
                      geom_n.outputs['Normal'])
        else:
            nmap.delete(node_tree)
Example #2
0
    def set_nmap_flavor(node_tree, switch_on):
        """Set normal map flavor to this shader.

        :param node_tree: node tree of current shader
        :type node_tree: bpy.types.NodeTree
        :param switch_on: flag indication if normal map should be switched on or off
        :type switch_on: bool
        """

        if switch_on:
            out_node = node_tree.nodes[Dif.OUT_MAT_NODE]
            location = (out_node.location.x - 185, out_node.location.y - 400)

            nmap.init(node_tree, location, out_node.inputs['Normal'])
        else:
            nmap.delete(node_tree)
Example #3
0
    def set_nmap_flavor(node_tree, switch_on):
        """Set normal map flavor to this shader.

        :param node_tree: node tree of current shader
        :type node_tree: bpy.types.NodeTree
        :param switch_on: flag indication if normal map should be switched on or off
        :type switch_on: bool
        """

        if switch_on:
            out_node = node_tree.nodes[Dif.OUT_MAT_NODE]
            location = (out_node.location.x - 185, out_node.location.y - 400)

            nmap.init(node_tree, location, out_node.inputs['Normal'])
        else:
            nmap.delete(node_tree)
Example #4
0
def delete(node_tree, preserve_node=False):
    """Delete normal map nodes from node tree.

    :param node_tree: node tree from which normal map should be deleted
    :type node_tree: bpy.types.NodeTree
    :param preserve_node: if true node won't be deleted
    :type preserve_node: bool
    """

    if DET_NMAP_MAT_NODE in node_tree.nodes:
        nmap_mat_n = node_tree.nodes[DET_NMAP_MAT_NODE]
        material = nmap_mat_n.material

        # remove and clear if possible
        if material and material.users == 1:

            textures = {}
            # gather all used textures in this material
            for i, tex_slot in enumerate(material.texture_slots):
                if tex_slot and tex_slot.texture:
                    textures[i] = tex_slot.texture

            # remove textures from texture slots first and check if texture can be cleared
            for slot_i in textures.keys():
                material.texture_slots.clear(slot_i)

                if textures[slot_i].users <= 1:
                    textures[slot_i].user_clear()

            # as last delete actually nmap material
            node_tree.nodes[DET_NMAP_MAT_NODE].material = None
            material.user_clear()
            bpy.data.materials.remove(material)

        if not preserve_node:
            node_tree.nodes.remove(node_tree.nodes[DET_NMAP_UV_SCALE_NODE])
            node_tree.nodes.remove(node_tree.nodes[DET_NMAP_TEX_NODE])
            node_tree.nodes.remove(node_tree.nodes[DET_NMAP_MAT_NODE])
            node_tree.nodes.remove(node_tree.nodes[DET_NMAP_SCALE_GNODE])
            node_tree.nodes.remove(node_tree.nodes[DET_NMAP_STRENGTH_NODE])
            node_tree.nodes.remove(node_tree.nodes[DET_NMAP_MIX_NODE])
            node_tree.nodes.remove(node_tree.nodes[DET_NMAP_SEPARATE_NODE])
            node_tree.nodes.remove(node_tree.nodes[NMAP_SEPARATE_NODE])
            node_tree.nodes.remove(node_tree.nodes[NMAP_DET_NMAP_COMBINE_NODE])
            node_tree.nodes.remove(node_tree.nodes[NMAP_NORMALIZE_NODE])

    nmap.delete(node_tree, preserve_node=preserve_node)
Example #5
0
def delete(node_tree, preserve_node=False):
    """Delete normal map nodes from node tree.

    :param node_tree: node tree from which normal map should be deleted
    :type node_tree: bpy.types.NodeTree
    :param preserve_node: if true node won't be deleted
    :type preserve_node: bool
    """

    if DET_NMAP_NODE in node_tree.nodes and not preserve_node:
        node_tree.nodes.remove(node_tree.nodes[DET_NMAP_UV_SCALE_NODE])
        node_tree.nodes.remove(node_tree.nodes[DET_NMAP_TEX_NODE])
        node_tree.nodes.remove(node_tree.nodes[DET_NMAP_NODE])
        node_tree.nodes.remove(node_tree.nodes[DET_NMAP_SCALE_GNODE])
        node_tree.nodes.remove(node_tree.nodes[DET_NMAP_STRENGTH_NODE])
        node_tree.nodes.remove(node_tree.nodes[DET_NMAP_MIX_NODE])
        node_tree.nodes.remove(node_tree.nodes[DET_NMAP_SEPARATE_NODE])
        node_tree.nodes.remove(node_tree.nodes[NMAP_SEPARATE_NODE])
        node_tree.nodes.remove(node_tree.nodes[NMAP_DET_NMAP_COMBINE_NODE])
        node_tree.nodes.remove(node_tree.nodes[NMAP_NORMALIZE_NODE])

    nmap.delete(node_tree, preserve_node=preserve_node)
Example #6
0
    def set_nmap_flavor(node_tree, switch_on):
        """Set normal map flavor to this shader.

        :param node_tree: node tree of current shader
        :type node_tree: bpy.types.NodeTree
        :param switch_on: flag indication if normal map should be switched on or off
        :type switch_on: bool
        """

        if switch_on:

            # find minimal y position for input nodes and position flavor beneath it
            min_y = None
            for node in node_tree.nodes:
                if node.location.x <= 185 and (min_y is None or min_y > node.location.y):
                    min_y = node.location.y

            out_node = node_tree.nodes[Dif.OUT_MAT_NODE]
            location = (out_node.location.x - 185, min_y - 400)

            nmap.init(node_tree, location, out_node.inputs['Normal'])
        else:
            nmap.delete(node_tree)
Example #7
0
    def set_nmap_flavor(node_tree, switch_on):
        """Set normal map flavor to this shader.

        :param node_tree: node tree of current shader
        :type node_tree: bpy.types.NodeTree
        :param switch_on: flag indication if normal map should be switched on or off
        :type switch_on: bool
        """

        if switch_on:

            # find minimal y position for input nodes and position flavor beneath it
            min_y = None
            for node in node_tree.nodes:
                if node.location.x <= 185 and (min_y is None
                                               or min_y > node.location.y):
                    min_y = node.location.y

            out_node = node_tree.nodes[Dif.OUT_MAT_NODE]
            location = (out_node.location.x - 185, min_y - 400)

            nmap.init(node_tree, location, out_node.inputs['Normal'])
        else:
            nmap.delete(node_tree)