Пример #1
0
def __create_nodes__(node_tree, location=None, normal_to=None):
    """Create node for alpha test.

    :param node_tree: node tree on which normal map will be used
    :type node_tree: bpy.types.NodeTree
    """

    # try to recover location
    if not location:
        if NMAP_MAT_NODE in node_tree.nodes:
            location = node_tree.nodes[NMAP_MAT_NODE].location

    # try to recover normal to link node socket
    if not normal_to:
        if NMAP_MAT_NODE in node_tree.nodes:
            for link in node_tree.links:
                if link.from_node == node_tree.nodes[NMAP_MAT_NODE] and link.from_socket.name == "Normal":
                    normal_to = link.to_socket

    frame = node_tree.nodes.new("NodeFrame")
    frame.name = frame.label = NMAP_FLAVOR_FRAME_NODE

    nmap_geom_n = node_tree.nodes.new("ShaderNodeGeometry")
    nmap_geom_n.parent = frame
    nmap_geom_n.name = nmap_geom_n.label = NMAP_GEOM_NODE
    nmap_geom_n.uv_layer = _MESH_consts.none_uv

    nmap_tex_n = node_tree.nodes.new("ShaderNodeTexture")
    nmap_tex_n.parent = frame
    nmap_tex_n.name = nmap_tex_n.label = NMAP_TEX_NODE

    nmap_mat_n = node_tree.nodes.new("ShaderNodeMaterial")
    nmap_mat_n.parent = frame
    nmap_mat_n.name = nmap_mat_n.label = NMAP_MAT_NODE
    nmap_mat_n.use_diffuse = False
    nmap_mat_n.use_specular = False

    nmap_scale_gn = node_tree.nodes.new("ShaderNodeGroup")
    nmap_scale_gn.parent = frame
    nmap_scale_gn.name = nmap_scale_gn.label = NMAP_SCALE_GNODE
    nmap_scale_gn.node_tree = scale_ng.get_node_group()

    # position nodes
    if location:
        nmap_geom_n.location = (location[0] - 185 * 3, location[1])
        nmap_tex_n.location = (location[0] - 185 * 2, location[1])
        nmap_mat_n.location = (location[0] - 185, location[1] - 200)
        nmap_scale_gn.location = (location[0], location[1])

    # links creation
    nodes = node_tree.nodes

    node_tree.links.new(nodes[NMAP_TEX_NODE].inputs["Vector"], nodes[NMAP_GEOM_NODE].outputs["UV"])

    node_tree.links.new(nodes[NMAP_SCALE_GNODE].inputs["NMap Tex Color"], nodes[NMAP_TEX_NODE].outputs["Color"])
    node_tree.links.new(nodes[NMAP_SCALE_GNODE].inputs["Original Normal"], nodes[NMAP_GEOM_NODE].outputs["Normal"])
    node_tree.links.new(nodes[NMAP_SCALE_GNODE].inputs["Modified Normal"], nodes[NMAP_MAT_NODE].outputs["Normal"])

    node_tree.links.new(normal_to, nodes[NMAP_SCALE_GNODE].outputs["Normal"])
Пример #2
0
    def __init_nmap__(node_tree, uid, location, position_from, stream_from,
                      normal_from, normal_to):
        """Initialize nodes for normal map for given unique id water layer.

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        :param uid: unique id of water layer to which all nmap nodes will be prefixed
        :type uid: str
        :param location: location where nmap should start creating it's nodes
        :type location: tuple[int, int]
        :param position_from: socket to take position vector from
        :type position_from: bpy.types.NodeSocket
        :param stream_from: socket to take water stream vector from
        :type stream_from: bpy.types.NodeSocket
        :param normal_from: socket from which original normal should be taken
        :type normal_from: bpy.types.NodeSocket
        :param normal_to: socket to which this water layer normal should be put to
        :type normal_to: bpy.types.NodeSocket
        """

        _STREAM_MIX_NODE = uid + Water.POSTFIX_STREAM_MIX
        _MAPPING_NODE = uid + Water.POSTFIX_MAPPING_NODE
        _NMAP_TEX_NODE = uid + Water.POSTFIX_NMAP_TEX_NODE
        _NMAP_NODE = uid + Water.POSTFIX_NMAP_NODE
        _NMAP_SCALE_NODE = uid + Water.POSTFIX_NMAP_SCALE_NODE

        # nodes
        stream_mix_n = node_tree.nodes.new("ShaderNodeVectorMath")
        stream_mix_n.name = stream_mix_n.label = Water.LAY0_LAY1_NORMAL_MIX_NODE
        stream_mix_n.location = location
        stream_mix_n.operation = "ADD"

        vector_mapping_n = node_tree.nodes.new("ShaderNodeMapping")
        vector_mapping_n.name = vector_mapping_n.label = _MAPPING_NODE
        vector_mapping_n.location = (location[0] + 185, location[1])
        vector_mapping_n.vector_type = "POINT"
        vector_mapping_n.inputs[
            'Location'].default_value = vector_mapping_n.inputs[
                'Rotation'].default_value = (0.0, ) * 3
        vector_mapping_n.inputs['Scale'].default_value = (1.0, ) * 3
        vector_mapping_n.width = 140

        nmap_tex_n = node_tree.nodes.new("ShaderNodeTexImage")
        nmap_tex_n.name = nmap_tex_n.label = _NMAP_TEX_NODE
        nmap_tex_n.location = (location[0] + 185 * 2, location[1])
        nmap_tex_n.width = 140

        nmap_n = node_tree.nodes.new("ShaderNodeNormalMap")
        nmap_n.name = nmap_n.label = _NMAP_NODE
        nmap_n.location = (location[0] + 185 * 3, location[1] - 150)
        nmap_n.space = "WORLD"
        nmap_n.inputs["Strength"].default_value = 1

        nmap_scale_n = node_tree.nodes.new("ShaderNodeGroup")
        nmap_scale_n.name = nmap_scale_n.label = _NMAP_SCALE_NODE
        nmap_scale_n.location = (location[0] + 185 * 4, location[1])
        nmap_scale_n.node_tree = scale_ng.get_node_group()

        # links
        node_tree.links.new(stream_mix_n.inputs[0], position_from)
        node_tree.links.new(stream_mix_n.inputs[1], stream_from)

        node_tree.links.new(vector_mapping_n.inputs['Vector'],
                            stream_mix_n.outputs['Vector'])

        node_tree.links.new(nmap_tex_n.inputs['Vector'],
                            vector_mapping_n.outputs['Vector'])

        node_tree.links.new(nmap_n.inputs['Color'],
                            nmap_tex_n.outputs['Color'])

        node_tree.links.new(nmap_scale_n.inputs['NMap Tex Color'],
                            nmap_tex_n.outputs['Color'])
        node_tree.links.new(nmap_scale_n.inputs['Original Normal'],
                            normal_from)
        node_tree.links.new(nmap_scale_n.inputs['Modified Normal'],
                            nmap_n.outputs['Normal'])

        node_tree.links.new(normal_to, nmap_scale_n.outputs['Normal'])
Пример #3
0
def __create_nodes__(node_tree,
                     location=None,
                     normal_to=None,
                     normal_from=None):
    """Create node for normal maps.

    :param node_tree: node tree on which normal map will be used
    :type node_tree: bpy.types.NodeTree
    """

    # try to recover location
    if not location:
        if NMAP_NODE in node_tree.nodes:
            location = node_tree.nodes[NMAP_NODE].location

    # try to recover normals to link node socket
    if not normal_to and NMAP_NODE in node_tree.nodes:
        for link in node_tree.links:
            if link.from_node == node_tree.nodes[
                    NMAP_NODE] and link.from_socket.name == "Normal":
                normal_to = link.to_socket

    if not normal_from and NMAP_SCALE_GNODE in node_tree.nodes:
        for link in node_tree.links:
            if link.to_node == node_tree.nodes[
                    NMAP_SCALE_GNODE] and link.to_socket.name == "Original Normal":
                normal_from = link.from_socket

    frame = node_tree.nodes.new("NodeFrame")
    frame.name = frame.label = NMAP_FLAVOR_FRAME_NODE

    nmap_uvs_n = node_tree.nodes.new("ShaderNodeUVMap")
    nmap_uvs_n.parent = frame
    nmap_uvs_n.name = nmap_uvs_n.label = NMAP_UVMAP_NODE
    nmap_uvs_n.uv_map = _MESH_consts.none_uv

    nmap_tex_n = node_tree.nodes.new("ShaderNodeTexImage")
    nmap_tex_n.parent = frame
    nmap_tex_n.name = nmap_tex_n.label = NMAP_TEX_NODE
    nmap_tex_n.width = 140

    nmap_n = node_tree.nodes.new("ShaderNodeNormalMap")
    nmap_n.parent = frame
    nmap_n.name = nmap_n.label = NMAP_NODE
    nmap_n.space = "TANGENT"
    nmap_n.inputs["Strength"].default_value = 1

    nmap_scale_n = node_tree.nodes.new("ShaderNodeGroup")
    nmap_scale_n.parent = frame
    nmap_scale_n.name = nmap_scale_n.label = NMAP_SCALE_GNODE
    nmap_scale_n.node_tree = scale_ng.get_node_group()

    # position nodes
    if location:
        nmap_uvs_n.location = (location[0] - 185 * 3, location[1])
        nmap_tex_n.location = (location[0] - 185 * 2, location[1])
        nmap_n.location = (location[0] - 185, location[1] - 200)
        nmap_scale_n.location = (location[0], location[1])

    # links creation
    nodes = node_tree.nodes

    node_tree.links.new(nodes[NMAP_UVMAP_NODE].outputs["UV"],
                        nodes[NMAP_TEX_NODE].inputs["Vector"])

    node_tree.links.new(nodes[NMAP_NODE].inputs["Color"],
                        nodes[NMAP_TEX_NODE].outputs["Color"])

    node_tree.links.new(nodes[NMAP_SCALE_GNODE].inputs["NMap Tex Color"],
                        nodes[NMAP_TEX_NODE].outputs["Color"])
    if normal_from:
        node_tree.links.new(nodes[NMAP_SCALE_GNODE].inputs["Original Normal"],
                            normal_from)
    node_tree.links.new(nodes[NMAP_SCALE_GNODE].inputs["Modified Normal"],
                        nodes[NMAP_NODE].outputs["Normal"])

    # set normal only if we know where to
    if normal_to:
        node_tree.links.new(normal_to,
                            nodes[NMAP_SCALE_GNODE].outputs["Normal"])