Example #1
0
    def set_tint(node_tree, color):
        """Set tint color to shader.

        :param node_tree: node tree of current shader
        :type node_tree: bpy.types.NodeTree
        :param color: tint color
        :type color: Color or tuple
        """

        color = _convert_utils.to_node_color(color)

        node_tree.nodes[Glass.TINT_COL_NODE].outputs[0].default_value = color
Example #2
0
    def set_env_factor(node_tree, color):
        """Set environment factor color to shader.

        :param node_tree: node tree of current shader
        :type node_tree: bpy.types.NodeTree
        :param color: environment color
        :type color: Color or tuple
        """

        color = _convert_utils.to_node_color(color)

        node_tree.nodes[Glass.ENV_COLOR_NODE].outputs[0].default_value = color
Example #3
0
    def set_diffuse(node_tree, color):
        """Set diffuse color to shader.

        :param node_tree: node tree of current shader
        :type node_tree: bpy.types.NodeTree
        :param color: diffuse color
        :type color: Color or tuple
        """

        color = _convert_utils.to_node_color(color)

        node_tree.nodes[UnlitTex.DIFF_COL_NODE].outputs['Color'].default_value = color
Example #4
0
    def set_diffuse(node_tree, color):
        """Set diffuse color to shader.

        :param node_tree: node tree of current shader
        :type node_tree: bpy.types.NodeTree
        :param color: diffuse color
        :type color: Color or tuple
        """

        color = _convert_utils.to_node_color(color)

        node_tree.nodes[
            UnlitVcolTex.DIFF_COL_NODE].outputs['Color'].default_value = color
Example #5
0
    def set_env_factor(node_tree, color):
        """Set environment factor color to shader.

        :param node_tree: node tree of current shader
        :type node_tree: bpy.types.NodeTree
        :param color: environment color
        :type color: Color or tuple
        """

        color = _convert_utils.to_node_color(color)

        node_tree.nodes[
            StdAddEnv.ENV_COLOR_NODE].outputs[0].default_value = color
Example #6
0
def __create_node__(node_tree):
    """Create node for paint node.

    :param node_tree: node tree on which paint flavor will be used
    :type node_tree: bpy.types.NodeTree
    """
    paint_mult_n = node_tree.nodes.new("ShaderNodeMixRGB")
    paint_mult_n.name = paint_mult_n.label = PAINT_MULT_NODE
    paint_mult_n.blend_type = "MULTIPLY"
    paint_mult_n.inputs['Fac'].default_value = 1

    color = _convert_utils.to_node_color(_get_scs_globals().base_paint_color)
    paint_mult_n.inputs['Color2'].default_value = color
Example #7
0
    def set_diffuse(node_tree, color):
        """Set diffuse color to shader.

        :param node_tree: node tree of current shader
        :type node_tree: bpy.types.NodeTree
        :param color: diffuse color
        :type color: Color or tuple
        """

        color = _convert_utils.to_node_color(color)

        node_tree.nodes[
            Glass.DIFF_COL_NODE].outputs['Color'].default_value = color
        node_tree.nodes[Glass.OUT_MAT_NODE].material.diffuse_intensity = 0.7
Example #8
0
    def set_base_paint_color(node_tree, color):
        """Set paint color to this node tree if basic truckpaint shader is used (no colormask or airbrush or altuv)

        :param node_tree: node tree to which paint color should be applied
        :type node_tree: bpy.types.NodeTree
        :param color: new color value
        :type color: mathutils.Color
        """

        if Truckpaint.BASE_PAINT_MULT_NODE not in node_tree.nodes:
            return

        color = _convert_utils.to_node_color(color)
        node_tree.nodes[Truckpaint.BASE_PAINT_MULT_NODE].inputs["Color2"].default_value = color
Example #9
0
    def set_specular(node_tree, color):
        """Set specular color to shader.

        :param node_tree: node tree of current shader
        :type node_tree: bpy.types.NodeTree
        :param color: specular color
        :type color: Color or tuple
        """

        color = _convert_utils.to_node_color(color)

        node_tree.nodes[Glass.SPEC_COL_NODE].outputs['Color'].default_value = color
        # fix intensity each time if user might changed it by hand directly on material
        node_tree.nodes[Glass.OUT_MAT_NODE].material.specular_intensity = 1.0
Example #10
0
    def set_specular(node_tree, color):
        """Set specular color to shader.

        :param node_tree: node tree of current shader
        :type node_tree: bpy.types.NodeTree
        :param color: specular color
        :type color: Color or tuple
        """

        color = _convert_utils.to_node_color(color)

        node_tree.nodes[Glass.SPEC_COL_NODE].outputs["Color"].default_value = color
        # fix intensity each time if user might changed it by hand directly on material
        node_tree.nodes[Glass.OUT_MAT_NODE].material.specular_intensity = 1.0
Example #11
0
def set_color(node_tree, color):
    """Set paint color to this node tree if paint flavor is enabled

    :param node_tree: node tree which should be checked for existance of this flavor
    :type node_tree: bpy.types.NodeTree
    :param color: new color value
    :type color: mathutils.Color
    """

    if not is_set(node_tree):
        return

    color = _convert_utils.to_node_color(color)
    node_tree.nodes[PAINT_MULT_NODE].inputs["Color2"].default_value = color
Example #12
0
    def set_diffuse(node_tree, color):
        """Set diffuse color to shader.

        :param node_tree: node tree of current shader
        :type node_tree: bpy.types.NodeTree
        :param color: diffuse color
        :type color: Color or tuple
        """

        color = _convert_utils.to_node_color(color)

        node_tree.nodes[
            Dif.DIFF_COL_NODE].outputs['Color'].default_value = color
        # fix intensity each time if user might changed it by hand directly on material
        node_tree.nodes[Dif.OUT_MAT_NODE].material.diffuse_intensity = 0.7
Example #13
0
    def set_diffuse(node_tree, color):
        """Set diffuse color to shader.

        :param node_tree: node tree of current shader
        :type node_tree: bpy.types.NodeTree
        :param color: diffuse color
        :type color: Color or tuple
        """

        color = _convert_utils.to_node_color(color)

        node_tree.nodes[Glass.DIFF_COL_NODE].outputs["Color"].default_value = color
        node_tree.nodes[Glass.OUT_MAT_NODE].material.diffuse_intensity = Color(color[:3]).v * 0.7

        # fix emit color representing ambient.
        # NOTE: because emit works upon diffuse light we need to fake factors if diffuse drops
        ambient = node_tree.nodes[Glass.OUT_MAT_NODE].material.scs_props.shader_attribute_add_ambient
        node_tree.nodes[Glass.OUT_MAT_NODE].material.emit = (ambient / 10) * (1 / Color(color[:3]).v)
Example #14
0
    def set_diffuse(node_tree, color):
        """Set diffuse color to shader.

        :param node_tree: node tree of current shader
        :type node_tree: bpy.types.NodeTree
        :param color: diffuse color
        :type color: Color or tuple
        """

        color = _convert_utils.to_node_color(color)

        node_tree.nodes[
            Glass.DIFF_COL_NODE].outputs['Color'].default_value = color
        node_tree.nodes[Glass.OUT_MAT_NODE].material.diffuse_intensity = Color(
            color[:3]).v * 0.7

        # fix emit color representing ambient.
        # NOTE: because emit works upon diffuse light we need to fake factors if diffuse drops
        ambient = node_tree.nodes[
            Glass.OUT_MAT_NODE].material.scs_props.shader_attribute_add_ambient
        node_tree.nodes[Glass.OUT_MAT_NODE].material.emit = (ambient / 10) * (
            1 / Color(color[:3]).v)
Example #15
0
    def set_diffuse(node_tree, color):
        """Set diffuse color to shader.

        :param node_tree: node tree of current shader
        :type node_tree: bpy.types.NodeTree
        :param color: diffuse color
        :type color: Color or tuple
        """

        color = _convert_utils.to_node_color(color)

        node_tree.nodes[Dif.DIFF_COL_NODE].outputs['Color'].default_value = color

        # in the case of flat flavor (diffuse shader is set to FRESNEL)
        # intensity of diffuse has to be 1 for correct results
        if node_tree.nodes[Dif.OUT_MAT_NODE].material.diffuse_shader == "FRESNEL":
            node_tree.nodes[Dif.OUT_MAT_NODE].material.diffuse_intensity = 1
        else:
            node_tree.nodes[Dif.OUT_MAT_NODE].material.diffuse_intensity = Color(color[:3]).v * 0.7

        # fix emit color representing ambient.
        # NOTE: because emit works upon diffuse light we need to fake factors if diffuse drops
        ambient = node_tree.nodes[Dif.OUT_MAT_NODE].material.scs_props.shader_attribute_add_ambient
        node_tree.nodes[Dif.OUT_MAT_NODE].material.emit = (ambient / 10) * (1 / Color(color[:3]).v)
Example #16
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        start_pos_x = 0
        start_pos_y = 0

        pos_x_shift = 185

        # init parent
        DifSpecAddEnv.init(node_tree)

        base_tex_n = node_tree.nodes[DifSpecAddEnv.BASE_TEX_NODE]
        env_color_n = node_tree.nodes[DifSpecAddEnv.ENV_COLOR_NODE]
        spec_color_n = node_tree.nodes[DifSpecAddEnv.SPEC_COL_NODE]
        diff_mult_n = node_tree.nodes[DifSpecAddEnv.DIFF_MULT_NODE]
        add_refl_gn = node_tree.nodes[DifSpecAddEnv.ADD_ENV_GROUP_NODE]
        spec_mult_n = node_tree.nodes[DifSpecAddEnv.SPEC_MULT_NODE]
        vcol_scale_n = node_tree.nodes[DifSpecAddEnv.VCOLOR_SCALE_NODE]
        opacity_n = node_tree.nodes[DifSpecAddEnv.OPACITY_NODE]
        out_mat_n = node_tree.nodes[DifSpecAddEnv.OUT_MAT_NODE]
        out_add_refl_n = node_tree.nodes[DifSpecAddEnv.OUT_ADD_REFL_NODE]
        output_n = node_tree.nodes[DifSpecAddEnv.OUTPUT_NODE]

        # move existing
        add_refl_gn.location.x += pos_x_shift * 3
        spec_mult_n.location.x += pos_x_shift * 3
        out_mat_n.location.x += pos_x_shift * 2
        out_add_refl_n.location.x += pos_x_shift * 2
        output_n.location.x += pos_x_shift * 2

        # set fresnel factor to 0
        node_tree.nodes[DifSpecAddEnv.ADD_ENV_GROUP_NODE].inputs['Apply Fresnel'].default_value = 0.0

        # node creation - level 3
        env_vcol_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        env_vcol_mix_n.name = Truckpaint.ENV_VCOL_MULT_NODE
        env_vcol_mix_n.label = Truckpaint.ENV_VCOL_MULT_NODE
        env_vcol_mix_n.location = (start_pos_x + pos_x_shift * 4, start_pos_y + 2000)
        env_vcol_mix_n.blend_type = "MULTIPLY"
        env_vcol_mix_n.inputs['Fac'].default_value = 1

        spec_vcol_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        spec_vcol_mix_n.name = Truckpaint.SPEC_VCOL_MULT_NODE
        spec_vcol_mix_n.label = Truckpaint.SPEC_VCOL_MULT_NODE
        spec_vcol_mix_n.location = (start_pos_x + pos_x_shift * 4, start_pos_y + 1750)
        spec_vcol_mix_n.blend_type = "MULTIPLY"
        spec_vcol_mix_n.inputs['Fac'].default_value = 1

        opacity_vcol_n = node_tree.nodes.new("ShaderNodeMath")
        opacity_vcol_n.name = Truckpaint.OPACITY_VCOL_MULT_NODE
        opacity_vcol_n.label = Truckpaint.OPACITY_VCOL_MULT_NODE
        opacity_vcol_n.location = (start_pos_x + pos_x_shift * 4, start_pos_y + 1300)
        opacity_vcol_n.operation = "MULTIPLY"

        # node creation - level 5
        base_paint_mult_n = node_tree.nodes.new("ShaderNodeMixRGB")
        base_paint_mult_n.name = Truckpaint.BASE_PAINT_MULT_NODE
        base_paint_mult_n.label = Truckpaint.BASE_PAINT_MULT_NODE
        base_paint_mult_n.location = (start_pos_x + pos_x_shift * 6, start_pos_y + 1500)
        base_paint_mult_n.blend_type = "MULTIPLY"
        base_paint_mult_n.inputs['Fac'].default_value = 1
        base_paint_mult_n.inputs['Color2'].default_value = _convert_utils.to_node_color(_get_scs_globals().base_paint_color)

        # node creation - level 6
        paint_mult_n = node_tree.nodes.new("ShaderNodeMixRGB")
        paint_mult_n.name = Truckpaint.PAINT_MULT_NODE
        paint_mult_n.label = Truckpaint.PAINT_MULT_NODE
        paint_mult_n.location = (start_pos_x + pos_x_shift * 7, start_pos_y + 1400)
        paint_mult_n.blend_type = "MULTIPLY"
        paint_mult_n.inputs['Fac'].default_value = 0

        # make links - level 2
        node_tree.links.new(env_vcol_mix_n.inputs['Color1'], env_color_n.outputs['Color'])
        node_tree.links.new(env_vcol_mix_n.inputs['Color2'], vcol_scale_n.outputs['Color'])

        node_tree.links.new(spec_vcol_mix_n.inputs['Color1'], base_tex_n.outputs['Value'])
        node_tree.links.new(spec_vcol_mix_n.inputs['Color2'], vcol_scale_n.outputs['Color'])

        # make links - level 3
        node_tree.links.new(add_refl_gn.inputs['Env Factor Color'], env_vcol_mix_n.outputs['Color'])

        node_tree.links.new(spec_mult_n.inputs['Color1'], spec_color_n.outputs['Color'])
        node_tree.links.new(spec_mult_n.inputs['Color2'], spec_vcol_mix_n.outputs['Color'])

        node_tree.links.new(opacity_vcol_n.inputs[0], vcol_scale_n.outputs['Color'])
        node_tree.links.new(opacity_vcol_n.inputs[1], opacity_n.outputs[0])

        # make links - level 4
        node_tree.links.new(base_paint_mult_n.inputs['Color1'], diff_mult_n.outputs['Color'])

        # make links - level 5
        node_tree.links.new(paint_mult_n.inputs['Color1'], base_paint_mult_n.outputs['Color'])

        # make links - output
        node_tree.links.new(out_mat_n.inputs['Color'], paint_mult_n.outputs['Color'])
Example #17
0
    def init(node_tree):
        """Initialize node tree with links for this shader.

        :param node_tree: node tree on which this shader should be created
        :type node_tree: bpy.types.NodeTree
        """

        start_pos_x = 0
        start_pos_y = 0

        pos_x_shift = 185

        # init parent
        DifSpecAddEnv.init(node_tree)

        base_tex_n = node_tree.nodes[DifSpecAddEnv.BASE_TEX_NODE]
        env_color_n = node_tree.nodes[DifSpecAddEnv.ENV_COLOR_NODE]
        spec_color_n = node_tree.nodes[DifSpecAddEnv.SPEC_COL_NODE]
        diff_mult_n = node_tree.nodes[DifSpecAddEnv.DIFF_MULT_NODE]
        add_refl_gn = node_tree.nodes[DifSpecAddEnv.ADD_ENV_GROUP_NODE]
        spec_mult_n = node_tree.nodes[DifSpecAddEnv.SPEC_MULT_NODE]
        vcol_scale_n = node_tree.nodes[DifSpecAddEnv.VCOLOR_SCALE_NODE]
        opacity_n = node_tree.nodes[DifSpecAddEnv.OPACITY_NODE]
        out_mat_n = node_tree.nodes[DifSpecAddEnv.OUT_MAT_NODE]
        compose_lighting_n = node_tree.nodes[
            DifSpecAddEnv.COMPOSE_LIGHTING_NODE]
        output_n = node_tree.nodes[DifSpecAddEnv.OUTPUT_NODE]

        # move existing
        add_refl_gn.location.x += pos_x_shift * 3
        spec_mult_n.location.x += pos_x_shift * 3
        out_mat_n.location.x += pos_x_shift * 2
        compose_lighting_n.location.x += pos_x_shift * 2
        output_n.location.x += pos_x_shift * 2

        # set fresnel factor to 1
        node_tree.nodes[DifSpecAddEnv.ADD_ENV_GROUP_NODE].inputs[
            'Apply Fresnel'].default_value = 1.0

        # node creation - level 3
        env_vcol_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        env_vcol_mix_n.name = Truckpaint.ENV_VCOL_MULT_NODE
        env_vcol_mix_n.label = Truckpaint.ENV_VCOL_MULT_NODE
        env_vcol_mix_n.location = (start_pos_x + pos_x_shift * 4,
                                   start_pos_y + 2000)
        env_vcol_mix_n.blend_type = "MULTIPLY"
        env_vcol_mix_n.inputs['Fac'].default_value = 1

        spec_vcol_mix_n = node_tree.nodes.new("ShaderNodeMixRGB")
        spec_vcol_mix_n.name = Truckpaint.SPEC_VCOL_MULT_NODE
        spec_vcol_mix_n.label = Truckpaint.SPEC_VCOL_MULT_NODE
        spec_vcol_mix_n.location = (start_pos_x + pos_x_shift * 4,
                                    start_pos_y + 1750)
        spec_vcol_mix_n.blend_type = "MULTIPLY"
        spec_vcol_mix_n.inputs['Fac'].default_value = 1

        opacity_vcol_n = node_tree.nodes.new("ShaderNodeMath")
        opacity_vcol_n.name = Truckpaint.OPACITY_VCOL_MULT_NODE
        opacity_vcol_n.label = Truckpaint.OPACITY_VCOL_MULT_NODE
        opacity_vcol_n.location = (start_pos_x + pos_x_shift * 4,
                                   start_pos_y + 1300)
        opacity_vcol_n.operation = "MULTIPLY"

        # node creation - level 5
        base_paint_mult_n = node_tree.nodes.new("ShaderNodeMixRGB")
        base_paint_mult_n.name = Truckpaint.BASE_PAINT_MULT_NODE
        base_paint_mult_n.label = Truckpaint.BASE_PAINT_MULT_NODE
        base_paint_mult_n.location = (start_pos_x + pos_x_shift * 6,
                                      start_pos_y + 1500)
        base_paint_mult_n.blend_type = "MULTIPLY"
        base_paint_mult_n.inputs['Fac'].default_value = 1
        base_paint_mult_n.inputs[
            'Color2'].default_value = _convert_utils.to_node_color(
                _get_scs_globals().base_paint_color)

        # node creation - level 6
        paint_mult_n = node_tree.nodes.new("ShaderNodeMixRGB")
        paint_mult_n.name = Truckpaint.PAINT_MULT_NODE
        paint_mult_n.label = Truckpaint.PAINT_MULT_NODE
        paint_mult_n.location = (start_pos_x + pos_x_shift * 7,
                                 start_pos_y + 1400)
        paint_mult_n.blend_type = "MULTIPLY"
        paint_mult_n.inputs['Fac'].default_value = 0

        # make links - level 2
        node_tree.links.new(env_vcol_mix_n.inputs['Color1'],
                            env_color_n.outputs['Color'])
        node_tree.links.new(env_vcol_mix_n.inputs['Color2'],
                            vcol_scale_n.outputs['Color'])

        node_tree.links.new(spec_vcol_mix_n.inputs['Color1'],
                            base_tex_n.outputs['Value'])
        node_tree.links.new(spec_vcol_mix_n.inputs['Color2'],
                            vcol_scale_n.outputs['Color'])

        # make links - level 3
        node_tree.links.new(add_refl_gn.inputs['Env Factor Color'],
                            env_vcol_mix_n.outputs['Color'])

        node_tree.links.new(spec_mult_n.inputs['Color1'],
                            spec_color_n.outputs['Color'])
        node_tree.links.new(spec_mult_n.inputs['Color2'],
                            spec_vcol_mix_n.outputs['Color'])

        node_tree.links.new(opacity_vcol_n.inputs[0],
                            vcol_scale_n.outputs['Color'])
        node_tree.links.new(opacity_vcol_n.inputs[1], opacity_n.outputs[0])

        # make links - level 4
        node_tree.links.new(base_paint_mult_n.inputs['Color1'],
                            diff_mult_n.outputs['Color'])

        # make links - level 5
        node_tree.links.new(paint_mult_n.inputs['Color1'],
                            base_paint_mult_n.outputs['Color'])

        # make links - output
        node_tree.links.new(out_mat_n.inputs['Color'],
                            paint_mult_n.outputs['Color'])
        node_tree.links.new(compose_lighting_n.inputs['Diffuse Color'],
                            paint_mult_n.outputs['Color'])