Esempio n. 1
0
def _draw_export_panel(scene, layout, scs_globals):
    """Draw Export panel."""
    layout_column = layout.column(align=True)
    layout_box = layout_column.box()  # header
    if scene.scs_props.export_panel_expand:
        box_row = layout_box.row()
        box_row.prop(scene.scs_props,
                     'export_panel_expand',
                     text="Export Panel:",
                     icon='TRIA_DOWN',
                     icon_only=True,
                     emboss=False)
        box_row.label('')

        layout_box = layout_column.box()  # body
        if not scs_globals.preview_export_selection_active:

            col = layout_box.column(align=True)
            col.row(align=True).prop(scs_globals, 'export_scope', expand=True)

            col_row = col.row(align=True)
            col_row.enabled = scs_globals.export_scope == "selection"
            icon = "FILE_TICK" if scs_globals.preview_export_selection else "X_VEC"
            col_row.prop(scs_globals,
                         'preview_export_selection',
                         text="Preview Selection",
                         icon=icon,
                         toggle=True)

            col_row = col.row(align=True)
            col_row.scale_y = 2
            col_row.operator('scene.export_scs_content_by_scope',
                             text="EXPORT")

        else:

            row = layout_box.box()
            row.prop(scs_globals,
                     "preview_export_selection_active",
                     text="Export preview mode is active!",
                     icon='ERROR',
                     icon_only=True,
                     emboss=False)
            row = row.column(align=True)
            row.label("Press ENTER to export selection!")
            row.label("Press ESC to cancel export!")

        box_row = layout_box.row()
        box = box_row.box()
        col = box.column()

        # Default Export Path (FILE_PATH - relative)
        col_row = col.row()
        col_row.label("Default Export Path:", icon="FILE_FOLDER")
        col_row = col.row(align=True)
        default_export_path = scene.scs_props.default_export_filepath
        col_row.alert = ((default_export_path != ""
                          and not default_export_path.startswith("//"))
                         or not os.path.isdir(
                             os.path.join(scs_globals.scs_project_path,
                                          default_export_path.strip("//"))))
        if col_row.alert:
            _shared.draw_warning_operator(
                col_row, "Default Export Path Warning",
                str("Current Default Export Path is unreachable, which may result into an error on export!\n"
                    "Make sure you did following:\n"
                    "1. Properly set \"SCS Project Base Path\"\n"
                    "2. Properly set \"Default Export Path\" which must be relative on \"SCS Project Base Path\""
                    ))

        col_row.prop(scene.scs_props,
                     'default_export_filepath',
                     text='',
                     icon='EXPORT')
        props = col_row.operator('scene.select_directory_inside_base',
                                 text='',
                                 icon='FILESEL')
        props.type = "DefaultExportPath"

        _shared.draw_export_panel(layout_box)
    else:
        box_row = layout_box.row()
        box_row.prop(scene.scs_props,
                     'export_panel_expand',
                     text="Export Panel:",
                     icon='TRIA_RIGHT',
                     icon_only=True,
                     emboss=False)
        box_row.label('')
Esempio n. 2
0
def _draw_shader_texture(layout, mat, split_perc, texture, read_only):
    """Draws texture box with it's properties.

    :param layout: layout to draw attribute to
    :type layout: bpy.types.UILayout
    :param mat: material from which data should be displayed
    :type mat: bpy.types.Material
    :param split_perc: split percentage for attribute name/value
    :type split_perc: float
    :param texture: texture data
    :type texture: dict
    :param read_only: if texture should be read only
    :type read_only: bool
    """

    tag = texture.get('Tag', None)
    hide_state = texture.get('Hide', None)
    tag_id = tag.split(':')
    tag_id_string = tag_id[1]
    texture_type = tag_id_string[8:]
    shader_texture_id = str('shader_' + tag_id_string)

    if hide_state == 'True':
        return

    texture_box = layout.box().column(
    )  # create column for compact display with alignment

    header_split = texture_box.row(align=True).split(percentage=0.5)
    header_split.label(texture_type.title(), icon="TEXTURE_SHADED")

    if hasattr(mat.scs_props, shader_texture_id):

        shader_texture = mat.scs_props.get(shader_texture_id, "")
        # imported tobj boolean switch (only for imported shaders)
        use_imported_tobj = getattr(mat.scs_props,
                                    shader_texture_id + "_use_imported", False)
        if read_only:
            row = header_split.row(align=True)
            row.alignment = 'RIGHT'
            row.prop(mat.scs_props, shader_texture_id + "_use_imported")

            if use_imported_tobj:

                texture_row = texture_box.row(align=True)
                item_space = texture_row.split(percentage=split_perc,
                                               align=True)
                item_space.label("TOBJ Path:")

                item_space = item_space.split(
                    percentage=1 / (1 - split_perc + 0.000001) * 0.1,
                    align=True)
                props = item_space.operator("material.scs_looks_wt", text="WT")
                props.property_str = shader_texture_id
                item_space.prop(mat.scs_props,
                                shader_texture_id + "_imported_tobj",
                                text="")

        # disable whole texture layout if it's locked
        texture_box.enabled = not mat.scs_props.get(
            shader_texture_id + "_locked", False)

        texture_row = texture_box.row(align=True)
        item_space = texture_row.split(percentage=split_perc, align=True)

        # in case of custom tobj value texture is used only for preview
        if read_only and use_imported_tobj:
            item_space.label("Preview Tex:")
        else:
            item_space.label("Texture:")

        layout_box_col = item_space.column(align=True)
        layout_box_row = layout_box_col.row(align=True)

        if shader_texture:
            texture_icon = 'TEXTURE'
        else:
            texture_icon = 'MATPLANE'

        # MARK INVALID SLOTS
        if _path_utils.is_valid_shader_texture_path(shader_texture):
            layout_box_row.alert = False
        else:
            layout_box_row.alert = True
            texture_icon = 'NONE'  # info operator will have icon, so texture path should use none

        # MARK EMPTY SLOTS
        if shader_texture == "":
            layout_box_row.alert = True

        layout_box_row = layout_box_row.split(
            percentage=1 / (1 - split_perc + 0.000001) * 0.1, align=True)
        props = layout_box_row.operator("material.scs_looks_wt", text="WT")
        props.property_str = shader_texture_id

        layout_box_row = layout_box_row.row(align=True)
        layout_box_row.prop(mat.scs_props,
                            shader_texture_id,
                            text='',
                            icon=texture_icon)

        if layout_box_row.alert:  # add info operator when texture path is invalid
            _shared.draw_warning_operator(
                layout_box_row,
                title="Texture Not Found",
                message=
                "Texture with given path doesn't exists or SCS Project Base Path is not properly set!"
            )

        props = layout_box_row.operator(
            'material.scs_select_shader_texture_filepath',
            text='',
            icon='FILESEL')
        props.shader_texture = shader_texture_id  # DYNAMIC ID SAVE (FOR FILE REQUESTER)

        # ADDITIONAL TEXTURE SETTINGS
        if (not read_only or
            (read_only and not use_imported_tobj)) and texture_box.enabled:

            tobj_filepath = _path_utils.get_tobj_path_from_shader_texture(
                shader_texture)

            if not tobj_filepath:
                layout_box_inner_col = layout_box_col.row(align=True)
                item_space = layout_box_inner_col.column(align=True)
                props = item_space.operator("material.scs_create_tobj",
                                            icon="NEW",
                                            text="")
                props.texture_type = texture_type
                # creating extra column->row so it can be properly disabled as tobj doesn't exists
                item_space = layout_box_inner_col.column(align=True).row(
                    align=True)
            else:
                item_space = layout_box_col.row(align=True)

            # enable settings only if tobj exists and map type of the tobj is 2d
            item_space.enabled = tobj_filepath is not None and getattr(
                mat.scs_props, shader_texture_id + "_map_type", "") == "2d"

            if tobj_filepath:
                mtime = str(os.path.getmtime(tobj_filepath))
                item_space.alert = (mtime != getattr(
                    mat.scs_props, shader_texture_id + "_tobj_load_time",
                    "NOT FOUND"))
            else:
                item_space.alert = True

            props = item_space.operator("material.scs_reload_tobj",
                                        icon="LOAD_FACTORY",
                                        text="")
            props.texture_type = texture_type

            item_space.prop_menu_enum(
                mat.scs_props,
                str('shader_' + tag_id_string + '_settings'),
                icon='SETTINGS',
            )

        # UV LAYERS FOR TEXTURE
        uv_mappings = getattr(mat.scs_props, "shader_" + tag_id_string + "_uv",
                              None)

        if len(uv_mappings) > 0:

            texture_row = texture_box.row(align=True)
            item_space = texture_row.split(percentage=split_perc, align=True)
            if read_only:
                item_space.label("Preview UV Map:")
            else:
                item_space.label("Mapping:")
            layout_box_col = item_space.column(align=True)

            for mapping in uv_mappings:

                item_space_row = layout_box_col.row(align=True)

                # add info about normal map uv mapping property in case of imported shader
                if read_only and tag_id_string == "texture_nmap":
                    preview_nmap_msg = str(
                        "Maping value for normal maps is in the case of imported shader\n"
                        "also used for defining uv map layer for tangent calculations!\n"
                        "If the uv map is not provided first entry from Mappings list above will be used!"
                    )
                    _shared.draw_warning_operator(item_space_row,
                                                  "Mapping Info",
                                                  preview_nmap_msg,
                                                  icon="INFO")

                # add ensuring operator for norma map uv mapping
                if tag_id_string == "texture_nmap":
                    props = item_space_row.operator(
                        "mesh.scs_ensure_active_uv",
                        text="",
                        icon="FILE_REFRESH")
                    props.mat_name = mat.name
                    props.uv_layer = uv_mappings[0].value

                if mapping.value and mapping.value != "" and mapping.value in bpy.context.active_object.data.uv_layers:
                    icon = "GROUP_UVS"
                else:
                    icon = "ERROR"

                item_space_row.prop_search(
                    data=mapping,
                    property="value",
                    search_data=bpy.context.active_object.data,
                    search_property='uv_layers',
                    text="",
                    icon=icon,
                )

    else:
        texture_box.row().label('Unsupported Shader Texture Type!',
                                icon="ERROR")
Esempio n. 3
0
def _draw_shader_parameters(layout,
                            mat,
                            scs_props,
                            scs_globals,
                            read_only=False):
    """Creates Shader Parameters sub-panel."""
    split_perc = scs_props.shader_item_split_percentage
    # panel_header = layout_box.split(percentage=0.5)
    # panel_header_1 = panel_header.row()
    # panel_header_1.prop(scene.scs_props, 'shader_presets_expand', text="Shader Parameters:", icon='TRIA_DOWN', icon_only=True, emboss=False)
    # panel_header_1.label('Shader Parameters:', icon='NONE')

    shader_data = mat.get("scs_shader_attributes", {})
    # print(' shader_data: %s' % str(shader_data))

    if len(shader_data) == 0:
        info_box = layout.box()
        info_box.label('Select a shader from the preset list.', icon='ERROR')
    else:

        # MISSING VERTEX COLOR
        active_vcolors = bpy.context.active_object.data.vertex_colors
        is_valid_vcolor = _MESH_consts.default_vcol in active_vcolors
        is_valid_vcolor_a = _MESH_consts.default_vcol + _MESH_consts.vcol_a_suffix in active_vcolors
        if not is_valid_vcolor or not is_valid_vcolor_a:

            vcol_missing_box = layout.box()

            title_row = vcol_missing_box.row(align=True)
            title_row.label("Vertex color layer(s) missing!", icon="ERROR")

            info_msg = "Currently active object is missing vertex color layers with names:\n"
            if not is_valid_vcolor:
                info_msg += "-> '" + _MESH_consts.default_vcol + "'\n"

            if not is_valid_vcolor_a:
                info_msg += "-> '" + _MESH_consts.default_vcol + _MESH_consts.vcol_a_suffix + "'\n"

            info_msg += "You can use 'Add Vertex Colors To (Active/All)' button to add needed layers or add layers manually."
            _shared.draw_warning_operator(title_row,
                                          "Vertex Colors Missing",
                                          info_msg,
                                          text="More Info",
                                          icon="INFO")

            col = vcol_missing_box.column(align=True)
            col.operator("mesh.scs_add_vcolors_to_active")
            col.operator("mesh.scs_add_vcolors_to_all")

        global_mat_attr = layout.column(align=True)

        # UI SPLIT PERCENTAGE PROPERTY
        global_mat_attr.row().prop(scs_props,
                                   "shader_item_split_percentage",
                                   slider=True)

        # PRESET INFO
        effect_name = mat.scs_props.mat_effect_name
        effect_name = str('"' + effect_name + '"')
        preset_info_row = global_mat_attr.row()
        preset_info_space = preset_info_row.split(percentage=split_perc,
                                                  align=True)
        preset_info_space.label("Effect:", icon='NONE')
        preset_info_space.label(effect_name, icon='NONE')

        # MATERIAL ALIASING
        alias_row = global_mat_attr.row()
        alias_row.enabled = not read_only
        alias_row = alias_row.split(percentage=split_perc)
        alias_row.label("Aliasing:")

        alias_row = alias_row.row(align=True)
        alias_text = "Enabled" if mat.scs_props.enable_aliasing else "Disabled"
        alias_icon = "FILE_TICK" if mat.scs_props.enable_aliasing else "X_VEC"
        alias_row.prop(mat.scs_props,
                       "enable_aliasing",
                       icon=alias_icon,
                       text=alias_text,
                       toggle=True)

        normalized_base_tex_path = mat.scs_props.shader_texture_base.replace(
            "\\", "/")
        is_aliasing_path = ("/material/road" in normalized_base_tex_path
                            or "/material/terrain" in normalized_base_tex_path
                            or "/material/custom" in normalized_base_tex_path)

        is_aliasable = ('textures' in shader_data
                        and (len(shader_data["textures"]) == 1 or
                             (len(shader_data["textures"]) == 2
                              and "dif.spec.weight.mult2" in effect_name)))

        if mat.scs_props.enable_aliasing:

            if not (is_aliasing_path and is_aliasable):

                aliasing_info_msg = str(
                    "Material aliasing will work only for materials which 'Base' texture\n"
                    "is loaded from this directories and their subdirectories:\n"
                    "-> '/material/road'\n"
                    "-> '/material/terrain'\n"
                    "-> '/material/custom'\n"
                    "Additional requirement for aliasing is also single texture material or\n"
                    "exceptionally multi texture material of 'dif.spec.weight.mult2' family.\n\n"
                    "Currently aliasing can not be done because:")

                if not is_aliasing_path:
                    aliasing_info_msg += "\n-> Your 'Base' texture doesn't point to any of this (sub)directories."
                if not is_aliasable:
                    aliasing_info_msg += "\n-> Current shader type use multiple textures or it's not 'dif.spec.weight.mult2' family type."

                _shared.draw_warning_operator(alias_row,
                                              "Aliasing Info",
                                              aliasing_info_msg,
                                              icon="INFO")

            alias_op_col = alias_row.column(align=True)
            alias_op_col.enabled = is_aliasing_path and is_aliasable
            alias_op_col.operator('material.load_aliased_material',
                                  icon="LOAD_FACTORY",
                                  text="")

        # MATERIAL SUBSTANCE
        substance_row = global_mat_attr.row()
        substance_row.enabled = not read_only
        substance_row = substance_row.split(percentage=split_perc)
        substance_row.label("Substance:")
        substance_row = substance_row.split(percentage=1 /
                                            (1 - split_perc + 0.000001) * 0.1,
                                            align=True)
        props = substance_row.operator("material.scs_looks_wt", text="WT")
        props.property_str = "substance"
        substance_row.prop_search(mat.scs_props,
                                  'substance',
                                  scs_globals,
                                  'scs_matsubs_inventory',
                                  icon='NONE',
                                  text="")

        if len(shader_data['attributes']) == 0 and len(
                shader_data['textures']) == 0:
            info_box = layout.box()
            if shader_data['effect'].endswith('mlaaweight'):
                info_box.label(
                    '"Multi Level Anti-Aliasing" shader has no parameters.',
                    icon='INFO')
            else:
                info_box.label('No shader parameters!', icon='INFO')

        if 'attributes' in shader_data and len(shader_data["attributes"]) > 0:

            attributes_box = layout.box()
            attributes_box.enabled = not read_only

            if scs_props.shader_attributes_expand:
                panel_header = attributes_box.split(percentage=0.5)
                panel_header_1 = panel_header.row()
                panel_header_1.prop(scs_props,
                                    'shader_attributes_expand',
                                    text="Material Attributes",
                                    icon='TRIA_DOWN',
                                    icon_only=True,
                                    emboss=False)

                attributes_data = shader_data['attributes']
                if attributes_data:
                    attrs_column = attributes_box.column(
                    )  # create column for compact display with alignment
                    for attribute_key in sorted(attributes_data.keys()):
                        _draw_shader_attribute(attrs_column, mat, split_perc,
                                               attributes_data[attribute_key])

            else:
                panel_header = attributes_box.split(percentage=0.5)
                panel_header_1 = panel_header.row()
                panel_header_1.prop(scs_props,
                                    'shader_attributes_expand',
                                    text="Material Attributes",
                                    icon='TRIA_RIGHT',
                                    icon_only=True,
                                    emboss=False)

        if 'textures' in shader_data and len(shader_data["textures"]) > 0:
            textures_box = layout.box()
            if scs_props.shader_textures_expand:
                panel_header = textures_box.split(percentage=0.5)
                panel_header_1 = panel_header.row()
                panel_header_1.prop(scs_props,
                                    'shader_textures_expand',
                                    text="Material Textures",
                                    icon='TRIA_DOWN',
                                    icon_only=True,
                                    emboss=False)

                textures_data = shader_data['textures']
                if textures_data:

                    if read_only:

                        mappings_box = textures_box.box()
                        row = mappings_box.row()
                        row.label("Mappings:", icon="GROUP_UVS")
                        row = mappings_box.row()
                        row.template_list(
                            'SCSMaterialCustomMappingSlot',
                            list_id="",
                            dataptr=mat.scs_props,
                            propname="custom_tex_coord_maps",
                            active_dataptr=mat.scs_props,
                            active_propname="active_custom_tex_coord",
                            rows=3,
                            maxrows=5,
                            type='DEFAULT',
                            columns=9)

                        col = row.column(align=True)
                        col.operator('material.add_custom_tex_coord_map',
                                     text="",
                                     icon='ZOOMIN')
                        col.operator('material.remove_custom_tex_coord_map',
                                     text="",
                                     icon='ZOOMOUT')

                    for texture_key in sorted(textures_data.keys()):
                        _draw_shader_texture(textures_box, mat, split_perc,
                                             textures_data[texture_key],
                                             read_only)
            else:
                panel_header = textures_box.split(percentage=0.5)
                panel_header_1 = panel_header.row()
                panel_header_1.prop(scs_props,
                                    'shader_textures_expand',
                                    text="Material Textures",
                                    icon='TRIA_RIGHT',
                                    icon_only=True,
                                    emboss=False)
Esempio n. 4
0
def _draw_export_panel(scene, layout, scs_globals):
    """Draw Export panel."""
    layout_column = layout.column(align=True)
    layout_box = layout_column.box()  # header
    if scene.scs_props.export_panel_expand:
        box_row = layout_box.row()
        box_row.prop(scene.scs_props, 'export_panel_expand', text="Export Panel:", icon='TRIA_DOWN', icon_only=True, emboss=False)
        box_row.label('')

        layout_box = layout_column.box()  # body
        if not scs_globals.preview_export_selection_active:

            col = layout_box.column(align=True)
            col.row(align=True).prop(scs_globals, 'export_scope', expand=True)

            col_row = col.row(align=True)
            col_row.enabled = scs_globals.export_scope == "selection"
            icon = "FILE_TICK" if scs_globals.preview_export_selection else "X_VEC"
            col_row.prop(scs_globals, 'preview_export_selection', text="Preview Selection", icon=icon, toggle=True)

            col_row = col.row(align=True)
            col_row.scale_y = 2
            col_row.operator('scene.export_scs_content_by_scope', text="EXPORT")

        else:

            row = layout_box.box()
            row.prop(scs_globals, "preview_export_selection_active", text="Export preview mode is active!", icon='ERROR', icon_only=True,
                     emboss=False)
            row = row.column(align=True)
            row.label("Press ENTER to export selection!")
            row.label("Press ESC to cancel export!")

        box_row = layout_box.row()
        box = box_row.box()
        col = box.column()

        # Default Export Path (FILE_PATH - relative)
        col_row = col.row()
        col_row.label("Default Export Path:", icon="FILE_FOLDER")
        col_row = col.row(align=True)
        default_export_path = scene.scs_props.default_export_filepath
        col_row.alert = ((default_export_path != "" and not default_export_path.startswith("//")) or
                         not os.path.isdir(os.path.join(scs_globals.scs_project_path, default_export_path.strip("//"))))
        if col_row.alert:
            _shared.draw_warning_operator(
                col_row,
                "Default Export Path Warning",
                str("Current Default Export Path is unreachable, which may result into an error on export!\n"
                    "Make sure you did following:\n"
                    "1. Properly set \"SCS Project Base Path\"\n"
                    "2. Properly set \"Default Export Path\" which must be relative on \"SCS Project Base Path\"")
            )

        col_row.prop(scene.scs_props, 'default_export_filepath', text='', icon='EXPORT')
        props = col_row.operator('scene.select_directory_inside_base', text='', icon='FILESEL')
        props.type = "DefaultExportPath"

        _shared.draw_export_panel(layout_box)
    else:
        box_row = layout_box.row()
        box_row.prop(scene.scs_props, 'export_panel_expand', text="Export Panel:", icon='TRIA_RIGHT', icon_only=True, emboss=False)
        box_row.label('')
Esempio n. 5
0
def _draw_shader_attribute(layout, mat, split_perc, attribute):
    """Draws one material attribute.

    :param layout: layout to draw attribute to
    :type layout: bpy.types.UILayout
    :param mat: material from which data should be displayed
    :type mat: bpy.types.Material
    :param split_perc: split percentage for attribute name/value
    :type split_perc: float
    :param attribute: attribute data
    :type attribute: dict
    """

    linked_vals = False  # DEBUG: Side by side display of values

    tag = attribute.get('Tag', "")
    frendly_tag = attribute.get('FriendlyTag', None)
    attribute_label = frendly_tag + ":" if frendly_tag else str(
        tag.replace('_', ' ').title() + ":")
    hide_state = attribute.get('Hide', None)
    lock_state = attribute.get('Lock', None)
    preview_only_state = attribute.get('PreviewOnly', None)

    # ignore substance from attributes because it's drawn before already
    if tag.lower() == "substance":
        return

    if hide_state == 'True':
        return

    attr_row = layout.row(align=True)
    item_space = attr_row.split(percentage=split_perc, align=True)

    label_icon = 'ERROR'
    if lock_state == 'True':
        item_space.enabled = False
        attribute_label = str(attribute_label[:-1] + " (locked):")
        label_icon = 'LOCKED'

    tag_layout = item_space.row()
    tag_layout.label(attribute_label)

    # create info operator for preview only attributes
    if preview_only_state == "True":
        _shared.draw_warning_operator(
            tag_layout,
            "Preview Attribute Info",
            "This attribute is used for preview only.\n"
            "It won't be exported so it doesn't matter what value is used.",
            icon="INFO")
    '''
    shader_attribute_id = str("shader_attribute_" + tag)
    if shader_attribute_id in mat.scs_props:
        item_space.prop(mat.scs_props, shader_attribute_id, text='')
    else:
        print(' %r is NOT defined in SCS Blender Tools...!' % shader_attribute_id)
    '''

    item_space = item_space.split(percentage=1 / (1 - split_perc + 0.000001) *
                                  0.1,
                                  align=True)
    props = item_space.operator("material.scs_looks_wt", text="WT")
    props.property_str = "shader_attribute_" + tag

    if tag == 'diffuse':
        item_space.prop(mat.scs_props, 'shader_attribute_diffuse', text='')
        if linked_vals:
            item_space.prop(mat, 'diffuse_color', text='')
    elif tag == 'specular':
        item_space.prop(mat.scs_props, 'shader_attribute_specular', text='')
        if linked_vals:
            item_space.prop(mat, 'specular_color', text='')
    elif tag == 'shininess':
        item_space.prop(mat.scs_props, 'shader_attribute_shininess', text='')
        # if linked_vals: item_space.prop(mat, 'specular_intensity', text='')
        if linked_vals:
            item_space.prop(mat, 'specular_hardness', text='')
    elif tag == 'add_ambient':
        item_space.prop(mat.scs_props, 'shader_attribute_add_ambient', text='')
        if linked_vals:
            item_space.prop(mat, 'ambient', text='')
    elif tag == 'reflection':
        item_space.prop(mat.scs_props, 'shader_attribute_reflection', text='')
        if linked_vals:
            item_space.prop(mat.raytrace_mirror, 'reflect_factor', text='')
    elif tag == 'reflection2':
        item_space.prop(mat.scs_props, 'shader_attribute_reflection2', text='')
    elif tag == 'shadow_bias':
        item_space.prop(mat.scs_props, 'shader_attribute_shadow_bias', text='')
        if linked_vals:
            item_space.prop(mat, 'shadow_buffer_bias', text='')
    elif tag == 'env_factor':
        item_space.prop(mat.scs_props, 'shader_attribute_env_factor', text='')
    elif tag == 'fresnel':
        item_space.column().prop(mat.scs_props,
                                 'shader_attribute_fresnel',
                                 text='')
    elif tag == 'tint':
        item_space.prop(mat.scs_props, 'shader_attribute_tint', text='')
    elif tag == 'tint_opacity':
        item_space.prop(mat.scs_props,
                        'shader_attribute_tint_opacity',
                        text='')
    elif tag.startswith("aux") and hasattr(mat.scs_props,
                                           "shader_attribute_" + tag):

        col = item_space.column().column(align=True)

        auxiliary_prop = getattr(mat.scs_props, "shader_attribute_" + tag,
                                 None)

        for item in auxiliary_prop:
            col.prop(item, 'value', text='')

    else:
        item_space.label('Undefined Shader Attribute Type!', icon=label_icon)
Esempio n. 6
0
    def draw_parameters(layout, mat, scs_inventories, split_perc, is_imported_shader=False):
        """Creates Shader Parameters sub-panel."""
        shader_data = mat.get("scs_shader_attributes", {})
        # print(' shader_data: %s' % str(shader_data))

        if len(shader_data) == 0:
            info_box = layout.column()
            info_box.label(text="Select a shader from the preset list.", icon='ERROR')
        else:

            # MISSING VERTEX COLOR
            active_vcolors = bpy.context.active_object.data.vertex_colors
            is_valid_vcolor = _MESH_consts.default_vcol in active_vcolors
            is_valid_vcolor_a = _MESH_consts.default_vcol + _MESH_consts.vcol_a_suffix in active_vcolors
            if not is_valid_vcolor or not is_valid_vcolor_a:

                vcol_missing_box = layout.box()

                title_row = vcol_missing_box.row(align=True)
                title_row.label(text="Vertex color layer(s) missing!", icon='ERROR')

                col = vcol_missing_box.column(align=True)

                info_msg = "Currently active object is missing vertex color layers with names:\n"
                if not is_valid_vcolor:
                    info_msg += "-> '" + _MESH_consts.default_vcol + "'\n"

                if not is_valid_vcolor_a:
                    info_msg += "-> '" + _MESH_consts.default_vcol + _MESH_consts.vcol_a_suffix + "'\n"

                info_msg += "You can use 'Add Vertex Colors To (Active/All)' button to add needed layers or add layers manually."
                _shared.draw_warning_operator(col, "Vertex Colors Missing", info_msg, text="More Info", icon='INFO')

                col.operator("mesh.scs_tools_add_vertex_colors_to_active")
                col.operator("mesh.scs_tools_add_vertex_colors_to_all")

            global_mat_attr = layout.column(align=True)
            # global_mat_attr.alignment = 'RIGHT'
            global_mat_attr.enabled = not is_imported_shader

            # PRESET INFO
            preset_info_row = global_mat_attr.row(align=True)
            preset_info_space = preset_info_row.split(factor=split_perc, align=True)
            preset_info_space.alignment = 'RIGHT'
            preset_info_space.label(text="Effect")
            preset_info_space.alignment = 'LEFT'
            preset_info_space.prop(mat.scs_props, "mat_effect_name", emboss=False, text="")

            # MATERIAL ALIASING
            alias_row = global_mat_attr.row()
            alias_row = alias_row.split(factor=split_perc)
            alias_row.alignment = 'RIGHT'
            alias_row.label(text="Aliasing")

            alias_row = alias_row.row(align=True)
            alias_text = "Enabled" if mat.scs_props.enable_aliasing else "Disabled"
            alias_icon = _shared.get_on_off_icon(mat.scs_props.enable_aliasing)
            alias_row.prop(mat.scs_props, "enable_aliasing", icon=alias_icon, text=alias_text, toggle=True)

            normalized_base_tex_path = mat.scs_props.shader_texture_base.replace("\\", "/")
            is_aliasing_path = ("/material/road" in normalized_base_tex_path or
                                "/material/terrain" in normalized_base_tex_path or
                                "/material/custom" in normalized_base_tex_path)

            is_aliasable = ('textures' in shader_data and
                            (
                                    len(shader_data["textures"]) == 1 or
                                    (len(shader_data["textures"]) == 2 and "dif.spec.weight.mult2" in mat.scs_props.mat_effect_name)
                            ))

            if mat.scs_props.enable_aliasing:

                if not (is_aliasing_path and is_aliasable):

                    aliasing_info_msg = str("Material aliasing will work only for materials which 'Base' texture\n"
                                            "is loaded from this directories and their subdirectories:\n"
                                            "-> '/material/road'\n"
                                            "-> '/material/terrain'\n"
                                            "-> '/material/custom'\n"
                                            "Additional requirement for aliasing is also single texture material or\n"
                                            "exceptionally multi texture material of 'dif.spec.weight.mult2' family.\n\n"
                                            "Currently aliasing can not be done because:")

                    if not is_aliasing_path:
                        aliasing_info_msg += "\n-> Your 'Base' texture doesn't point to any of this (sub)directories."
                    if not is_aliasable:
                        aliasing_info_msg += "\n-> Current shader type use multiple textures or it's not 'dif.spec.weight.mult2' family type."

                    _shared.draw_warning_operator(alias_row, "Aliasing Info", aliasing_info_msg, icon='INFO')

                alias_op_col = alias_row.column(align=True)
                alias_op_col.enabled = is_aliasing_path and is_aliasable
                alias_op_col.operator('material.scs_tools_load_aliased_material', icon='IMPORT', text="")

            # MATERIAL SUBSTANCE
            substance_row = global_mat_attr.split(factor=split_perc)
            tag_layout = substance_row.row()
            tag_layout.alignment = 'RIGHT'
            tag_layout.label(text="Substance")
            tag_value = substance_row.row(align=True)
            tag_value.prop_search(mat.scs_props, 'substance', scs_inventories, 'matsubs', icon='NONE', text="")
            props = tag_value.operator("material.scs_tools_material_item_extras", text="", icon="LAYER_USED")
            props.property_str = "substance"

            if len(shader_data['attributes']) == 0 and len(shader_data['textures']) == 0:
                if shader_data['effect'].endswith('mlaaweight'):
                    layout.label(text="'Multi Level Anti-Aliasing' shader has no parameters.", icon='INFO')
                else:
                    layout.label(text="No shader parameters!", icon='INFO')
Esempio n. 7
0
    def draw(self, context):
        layout = self.layout
        scene = context.scene
        scs_globals = _get_scs_globals()

        # scs tools main panel if config is being updated
        layout.enabled = not scs_globals.config_update_lock

        if not scs_globals.preview_export_selection_active:

            col = layout.column(align=True)
            row = col.row(align=True)
            row.scale_y = 1.2

            if scs_globals.export_scope == "selection":
                icon = _shared.get_on_off_icon(
                    scs_globals.preview_export_selection)
                row.prop(scs_globals,
                         'preview_export_selection',
                         text="",
                         icon=icon,
                         toggle=False)

            row.prop(scs_globals, 'export_scope', expand=True)

            col_row = col.row(align=True)
            col_row.scale_y = 2
            col_row.operator('scene.scs_tools_export_by_scope', text="EXPORT")

        else:

            row = layout.box()
            row.prop(scs_globals,
                     "preview_export_selection_active",
                     text="Export preview mode is active!",
                     icon='ERROR',
                     icon_only=True,
                     emboss=False)
            row = row.column(align=True)
            row.label(text="Rotate view:")
            row.label(text="* Left Mouse Button + move")
            row.label(text="* Numpad 2, 4, 6, 8")
            row.label(text="Zoom in/out:")
            row.label(text="* Mouse Scroll")
            row.label(text="* Numpad '+', '-'")
            row.separator()
            row.label(text="Press ENTER to export selection!")
            row.label(text="Press ESC to cancel export!")

        col = layout.column()

        # Fallback Export Path (FILE_PATH - relative)
        col_row = _shared.create_row(col, use_split=True, enabled=True)
        default_export_path = scene.scs_props.default_export_filepath
        col_row.alert = ((default_export_path != ""
                          and not default_export_path.startswith("//"))
                         or not os.path.isdir(
                             os.path.join(scs_globals.scs_project_path,
                                          default_export_path.strip("//"))))
        col_row.prop(scene.scs_props, 'default_export_filepath', icon='EXPORT')
        if col_row.alert:
            _shared.draw_warning_operator(
                col_row, "Default Export Path Warning",
                str("Current Default Export Path is unreachable, which may result into an error on export!\n"
                    "Make sure you did following:\n"
                    "1. Properly set \"SCS Project Base Path\"\n"
                    "2. Properly set \"Default Export Path\" which must be relative on \"SCS Project Base Path\""
                    ))

        props = col_row.operator('scene.scs_tools_select_dir_inside_base',
                                 text="",
                                 icon='FILEBROWSER')
        props.type = "DefaultExportPath"

        _shared.draw_export_panel(layout, ignore_extra_boxes=True)
Esempio n. 8
0
def _draw_shader_texture(layout, mat, split_perc, texture, read_only):
    """Draws texture box with it's properties.

    :param layout: layout to draw attribute to
    :type layout: bpy.types.UILayout
    :param mat: material from which data should be displayed
    :type mat: bpy.types.Material
    :param split_perc: split percentage for attribute name/value
    :type split_perc: float
    :param texture: texture data
    :type texture: dict
    :param read_only: if texture should be read only
    :type read_only: bool
    """

    tag = texture.get("Tag", None)
    hide_state = texture.get("Hide", None)
    tag_id = tag.split(":")
    tag_id_string = tag_id[1]
    texture_type = tag_id_string[8:]
    shader_texture_id = str("shader_" + tag_id_string)

    if hide_state == "True":
        return

    texture_box = layout.box()

    header_split = texture_box.row().split(percentage=0.5)
    header_split.label(texture_type.title(), icon="TEXTURE_SHADED")

    if hasattr(mat.scs_props, shader_texture_id):

        shader_texture = mat.scs_props.get(shader_texture_id, "")
        # imported tobj boolean switch (only for imported shaders)
        use_imported_tobj = getattr(mat.scs_props, shader_texture_id + "_use_imported", False)
        if read_only:
            row = header_split.row(align=True)
            row.alignment = "RIGHT"
            row.prop(mat.scs_props, shader_texture_id + "_use_imported")

            if use_imported_tobj:

                texture_row = texture_box.row()
                item_space = texture_row.split(percentage=split_perc, align=True)
                item_space.label("TOBJ Path:")

                item_space = item_space.split(percentage=(1 - split_perc) * 0.2, align=True)
                props = item_space.operator("material.scs_looks_wt", text="WT")
                props.property_str = shader_texture_id
                item_space.prop(mat.scs_props, shader_texture_id + "_imported_tobj", text="")

        # disable whole texture layout if it's locked
        texture_box.enabled = not mat.scs_props.get(shader_texture_id + "_locked", False)

        texture_row = texture_box.row()
        item_space = texture_row.split(percentage=split_perc, align=True)

        # in case of custom tobj value texture is used only for preview
        if read_only and use_imported_tobj:
            item_space.label("Preview Tex:")
        else:
            item_space.label("Texture:")

        layout_box_col = item_space.column(align=True)
        layout_box_row = layout_box_col.row(align=True)

        if shader_texture:
            texture_icon = "TEXTURE"
        else:
            texture_icon = "MATPLANE"

        # MARK INVALID SLOTS
        if _material_utils.is_valid_shader_texture_path(shader_texture):
            layout_box_row.alert = False
        else:
            layout_box_row.alert = True
            texture_icon = "ERROR"

        # MARK EMPTY SLOTS
        if shader_texture == "":
            layout_box_row.alert = True

        layout_box_row = layout_box_row.split(percentage=(1 - split_perc) * 0.2, align=True)
        props = layout_box_row.operator("material.scs_looks_wt", text="WT")
        props.property_str = shader_texture_id

        layout_box_row = layout_box_row.row(align=True)
        layout_box_row.prop(mat.scs_props, shader_texture_id, text="", icon=texture_icon)
        props = layout_box_row.operator("scene.select_shader_texture_filepath", text="", icon="FILESEL")
        props.shader_texture = shader_texture_id  # DYNAMIC ID SAVE (FOR FILE REQUESTER)

        # ADDITIONAL TEXTURE SETTINGS
        if (not read_only or (read_only and not use_imported_tobj)) and texture_box.enabled:

            tobj_exists = _material_utils.is_valid_shader_texture_path(shader_texture, True)

            if not tobj_exists:
                item_split = layout_box_col.split(percentage=(1 - split_perc) * 0.2, align=True)

                item_space = item_split.row(align=True)
                props = item_space.operator("material.scs_create_tobj", icon="NEW", text="")
                props.texture_type = texture_type

                item_space = item_split.row(align=True)
            else:
                item_space = layout_box_col.row(align=True)

            item_space.enabled = tobj_exists

            if tobj_exists:
                mtime = str(os.path.getmtime(_path_utils.get_abs_path(shader_texture[:-4] + ".tobj")))
                item_space.alert = mtime != getattr(mat.scs_props, shader_texture_id + "_tobj_load_time", "NOT FOUND")
            else:
                item_space.alert = True

            props = item_space.operator("material.scs_reload_tobj", icon="LOAD_FACTORY", text="")
            props.texture_type = texture_type

            item_space.prop_menu_enum(mat.scs_props, str("shader_" + tag_id_string + "_settings"), icon="SETTINGS")

        # UV LAYERS FOR TEXTURE
        uv_mappings = getattr(mat.scs_props, "shader_" + tag_id_string + "_uv", None)

        if len(uv_mappings) > 0:

            texture_row = texture_box.row()
            item_space = texture_row.split(percentage=split_perc, align=True)
            if read_only:
                item_space.label("Preview UV Map:")
            else:
                item_space.label("Mapping:")
            layout_box_col = item_space.column(align=True)

            for mapping in uv_mappings:

                item_space_row = layout_box_col.row(align=True)

                # add info about normal map uv mapping property in case of imported shader
                if read_only and tag_id_string == "texture_nmap":
                    preview_nmap_msg = str(
                        "Maping value for normal maps is in the case of imported shader\n"
                        "also used for defining uv map layer for tangent calculations!\n"
                        "If the uv map is not provided first entry from Mappings list above will be used!"
                    )
                    _shared.draw_warning_operator(item_space_row, "Mapping Info", preview_nmap_msg, icon="INFO")

                # add ensuring operator for norma map uv mapping
                if tag_id_string == "texture_nmap":
                    props = item_space_row.operator("mesh.scs_ensure_active_uv", text="", icon="FILE_REFRESH")
                    props.mat_name = mat.name
                    props.uv_layer = uv_mappings[0].value

                if mapping.value and mapping.value != "" and mapping.value in bpy.context.active_object.data.uv_layers:
                    icon = "GROUP_UVS"
                else:
                    icon = "ERROR"

                item_space_row.prop_search(
                    data=mapping,
                    property="value",
                    search_data=bpy.context.active_object.data,
                    search_property="uv_layers",
                    text="",
                    icon=icon,
                )

    else:
        texture_box.row().label("Unsupported Shader Texture Type!", icon="ERROR")
Esempio n. 9
0
    def draw(self, context):
        """UI draw function."""
        scs_globals = _get_scs_globals()
        scs_inventories = _get_scs_inventories()

        if self.is_popover:
            header_row = self.layout.row()
            header_row.prop(scs_globals,
                            "use_scs_lighting",
                            text="SCS Lighting")
            layout = self.layout.box().column()
        else:
            layout = self.get_layout()

        layout.enabled = _get_scs_globals().use_scs_lighting

        # prepare main layout containing header and body
        header = layout.column()
        body = layout.column()

        # 1. header
        # library path
        row = _shared.create_row(header, use_split=True, enabled=True)
        row.alert = not _path_utils.is_valid_sun_profiles_library_path()
        row.prop(scs_globals, "sun_profiles_lib_path", icon='FILE_CACHE')
        row.operator("scene.scs_tools_select_sun_profiles_lib_path",
                     text="",
                     icon='FILEBROWSER')

        # 2. body
        # lighting scene east direction
        row = body.row(align=True)

        left_col = row.row(align=True)
        left_col.enabled = not scs_globals.lighting_east_lock
        left_col.label(text="", icon='LIGHT_SPOT')
        left_col.prop(scs_globals,
                      "lighting_scene_east_direction",
                      slider=True)

        right_col = row.row(align=True)
        icon = 'LOCKED' if scs_globals.lighting_east_lock else 'UNLOCKED'
        right_col.prop(scs_globals,
                       "lighting_east_lock",
                       icon=icon,
                       icon_only=True)

        # now if we have multiple 3D views locking has to be disabled,
        # as it can not work properly with multiple views because all views share same SCS Lighting lamps
        if _view_3d_utils.has_multiple_view3d_spaces(screen=context.screen):
            right_col.enabled = False
            _shared.draw_warning_operator(
                row.row(align=True),
                "SCS Lighting East Lock Disabled!",
                "East lock can not be used, because you are using multiple 3D views and\n"
                "tools can not decide on which view you want to lock the east.",
                icon='INFO')

        # disable any UI from now on if active sun profile is not valid
        body.enabled = (0 <= scs_globals.sun_profiles_active < len(
            scs_inventories.sun_profiles))

        # loaded sun profiles list
        body.template_list(SCS_TOOLS_UL_SunProfileSlot.__name__,
                           list_id="",
                           dataptr=scs_inventories,
                           propname="sun_profiles",
                           active_dataptr=scs_globals,
                           active_propname="sun_profiles_active",
                           rows=3,
                           maxrows=5,
                           type='DEFAULT',
                           columns=9)
Esempio n. 10
0
def _draw_shader_parameters(layout, mat, scs_props, scs_globals, read_only=False):
    """Creates Shader Parameters sub-panel."""
    split_perc = scs_props.shader_item_split_percentage
    # panel_header = layout_box.split(percentage=0.5)
    # panel_header_1 = panel_header.row()
    # panel_header_1.prop(scene.scs_props, 'shader_presets_expand', text="Shader Parameters:", icon='TRIA_DOWN', icon_only=True, emboss=False)
    # panel_header_1.label('Shader Parameters:', icon='NONE')

    shader_data = mat.get("scs_shader_attributes", {})
    # print(' shader_data: %s' % str(shader_data))

    if len(shader_data) == 0:
        info_box = layout.box()
        info_box.label('Select a shader from the preset list.', icon='ERROR')
    else:

        # MISSING VERTEX COLOR
        active_vcolors = bpy.context.active_object.data.vertex_colors
        is_valid_vcolor = _MESH_consts.default_vcol in active_vcolors
        is_valid_vcolor_a = _MESH_consts.default_vcol + _MESH_consts.vcol_a_suffix in active_vcolors
        if not is_valid_vcolor or not is_valid_vcolor_a:

            vcol_missing_box = layout.box()

            title_row = vcol_missing_box.row(align=True)
            title_row.label("Vertex color layer(s) missing!", icon="ERROR")

            info_msg = "Currently active object is missing vertex color layers with names:\n"
            if not is_valid_vcolor:
                info_msg += "-> '" + _MESH_consts.default_vcol + "'\n"

            if not is_valid_vcolor_a:
                info_msg += "-> '" + _MESH_consts.default_vcol + _MESH_consts.vcol_a_suffix + "'\n"

            info_msg += "You can use 'Add Vertex Colors To (Active/All)' button to add needed layers or add layers manually."
            _shared.draw_warning_operator(title_row, "Vertex Colors Missing", info_msg, text="More Info", icon="INFO")

            col = vcol_missing_box.column(align=True)
            col.operator("mesh.scs_add_vcolors_to_active")
            col.operator("mesh.scs_add_vcolors_to_all")

        global_mat_attr = layout.column(align=True)

        # UI SPLIT PERCENTAGE PROPERTY
        global_mat_attr.row().prop(scs_props, "shader_item_split_percentage", slider=True)

        # PRESET INFO
        effect_name = mat.scs_props.mat_effect_name
        effect_name = str('"' + effect_name + '"')
        preset_info_row = global_mat_attr.row()
        preset_info_space = preset_info_row.split(percentage=split_perc, align=True)
        preset_info_space.label("Effect:", icon='NONE')
        preset_info_space.label(effect_name, icon='NONE')

        # MATERIAL ALIASING
        alias_row = global_mat_attr.row()
        alias_row.enabled = not read_only
        alias_row = alias_row.split(percentage=split_perc)
        alias_row.label("Aliasing:")

        alias_row = alias_row.row(align=True)
        alias_text = "Enabled" if mat.scs_props.enable_aliasing else "Disabled"
        alias_icon = "FILE_TICK" if mat.scs_props.enable_aliasing else "X_VEC"
        alias_row.prop(mat.scs_props, "enable_aliasing", icon=alias_icon, text=alias_text, toggle=True)

        normalized_base_tex_path = mat.scs_props.shader_texture_base.replace("\\", "/")
        is_aliasing_path = ("/material/road" in normalized_base_tex_path or
                            "/material/terrain" in normalized_base_tex_path or
                            "/material/custom" in normalized_base_tex_path)

        is_aliasable = ('textures' in shader_data and
                        (
                            len(shader_data["textures"]) == 1 or
                            (len(shader_data["textures"]) == 2 and "dif.spec.weight.mult2" in effect_name)
                        ))

        if mat.scs_props.enable_aliasing:

            if not (is_aliasing_path and is_aliasable):

                aliasing_info_msg = str("Material aliasing will work only for materials which 'Base' texture\n"
                                        "is loaded from this directories and their subdirectories:\n"
                                        "-> '/material/road'\n"
                                        "-> '/material/terrain'\n"
                                        "-> '/material/custom'\n"
                                        "Additional requirement for aliasing is also single texture material or\n"
                                        "exceptionally multi texture material of 'dif.spec.weight.mult2' family.\n\n"
                                        "Currently aliasing can not be done because:")

                if not is_aliasing_path:
                    aliasing_info_msg += "\n-> Your 'Base' texture doesn't point to any of this (sub)directories."
                if not is_aliasable:
                    aliasing_info_msg += "\n-> Current shader type use multiple textures or it's not 'dif.spec.weight.mult2' family type."

                _shared.draw_warning_operator(alias_row, "Aliasing Info", aliasing_info_msg, icon="INFO")

            alias_op_col = alias_row.column(align=True)
            alias_op_col.enabled = is_aliasing_path and is_aliasable
            alias_op_col.operator('material.load_aliased_material', icon="LOAD_FACTORY", text="")

        # MATERIAL SUBSTANCE
        substance_row = global_mat_attr.row()
        substance_row.enabled = not read_only
        substance_row = substance_row.split(percentage=split_perc)
        substance_row.label("Substance:")
        substance_row = substance_row.split(percentage=1 / (1 - split_perc + 0.000001) * 0.1, align=True)
        props = substance_row.operator("material.scs_looks_wt", text="WT")
        props.property_str = "substance"
        substance_row.prop_search(mat.scs_props, 'substance', scs_globals, 'scs_matsubs_inventory', icon='NONE', text="")

        if len(shader_data['attributes']) == 0 and len(shader_data['textures']) == 0:
            info_box = layout.box()
            if shader_data['effect'].endswith('mlaaweight'):
                info_box.label('"Multi Level Anti-Aliasing" shader has no parameters.', icon='INFO')
            else:
                info_box.label('No shader parameters!', icon='INFO')

        if 'attributes' in shader_data and len(shader_data["attributes"]) > 0:

            attributes_box = layout.box()
            attributes_box.enabled = not read_only

            if scs_props.shader_attributes_expand:
                panel_header = attributes_box.split(percentage=0.5)
                panel_header_1 = panel_header.row()
                panel_header_1.prop(
                    scs_props,
                    'shader_attributes_expand',
                    text="Material Attributes",
                    icon='TRIA_DOWN',
                    icon_only=True,
                    emboss=False
                )

                attributes_data = shader_data['attributes']
                if attributes_data:
                    attrs_column = attributes_box.column()  # create column for compact display with alignment
                    for attribute_key in sorted(attributes_data.keys()):
                        _draw_shader_attribute(attrs_column, mat, split_perc, attributes_data[attribute_key])

            else:
                panel_header = attributes_box.split(percentage=0.5)
                panel_header_1 = panel_header.row()
                panel_header_1.prop(
                    scs_props,
                    'shader_attributes_expand',
                    text="Material Attributes",
                    icon='TRIA_RIGHT',
                    icon_only=True,
                    emboss=False
                )

        if 'textures' in shader_data and len(shader_data["textures"]) > 0:
            textures_box = layout.box()
            if scs_props.shader_textures_expand:
                panel_header = textures_box.split(percentage=0.5)
                panel_header_1 = panel_header.row()
                panel_header_1.prop(
                    scs_props,
                    'shader_textures_expand',
                    text="Material Textures",
                    icon='TRIA_DOWN',
                    icon_only=True,
                    emboss=False
                )

                textures_data = shader_data['textures']
                if textures_data:

                    if read_only:

                        mappings_box = textures_box.box()
                        row = mappings_box.row()
                        row.label("Mappings:", icon="GROUP_UVS")
                        row = mappings_box.row()
                        row.template_list(
                            'SCSMaterialCustomMappingSlot',
                            list_id="",
                            dataptr=mat.scs_props,
                            propname="custom_tex_coord_maps",
                            active_dataptr=mat.scs_props,
                            active_propname="active_custom_tex_coord",
                            rows=3,
                            maxrows=5,
                            type='DEFAULT',
                            columns=9
                        )

                        col = row.column(align=True)
                        col.operator('material.add_custom_tex_coord_map', text="", icon='ZOOMIN')
                        col.operator('material.remove_custom_tex_coord_map', text="", icon='ZOOMOUT')

                    for texture_key in sorted(textures_data.keys()):
                        _draw_shader_texture(textures_box, mat, split_perc, textures_data[texture_key], read_only)
            else:
                panel_header = textures_box.split(percentage=0.5)
                panel_header_1 = panel_header.row()
                panel_header_1.prop(scs_props, 'shader_textures_expand', text="Material Textures", icon='TRIA_RIGHT', icon_only=True, emboss=False)
Esempio n. 11
0
def _draw_shader_attribute(layout, mat, split_perc, attribute):
    """Draws one material attribute.

    :param layout: layout to draw attribute to
    :type layout: bpy.types.UILayout
    :param mat: material from which data should be displayed
    :type mat: bpy.types.Material
    :param split_perc: split percentage for attribute name/value
    :type split_perc: float
    :param attribute: attribute data
    :type attribute: dict
    """

    linked_vals = False  # DEBUG: Side by side display of values

    tag = attribute.get('Tag', "")
    frendly_tag = attribute.get('FriendlyTag', None)
    attribute_label = frendly_tag + ":" if frendly_tag else str(tag.replace('_', ' ').title() + ":")
    hide_state = attribute.get('Hide', None)
    lock_state = attribute.get('Lock', None)
    preview_only_state = attribute.get('PreviewOnly', None)

    # ignore substance from attributes because it's drawn before already
    if tag.lower() == "substance":
        return

    if hide_state == 'True':
        return

    attr_row = layout.row(align=True)
    item_space = attr_row.split(percentage=split_perc, align=True)

    label_icon = 'ERROR'
    if lock_state == 'True':
        item_space.enabled = False
        attribute_label = str(attribute_label[:-1] + " (locked):")
        label_icon = 'LOCKED'

    tag_layout = item_space.row()
    tag_layout.label(attribute_label)

    # create info operator for preview only attributes
    if preview_only_state == "True":
        _shared.draw_warning_operator(tag_layout,
                                      "Preview Attribute Info",
                                      "This attribute is used for preview only.\n"
                                      "It won't be exported so it doesn't matter what value is used.",
                                      icon="INFO")

    '''
    shader_attribute_id = str("shader_attribute_" + tag)
    if shader_attribute_id in mat.scs_props:
        item_space.prop(mat.scs_props, shader_attribute_id, text='')
    else:
        print(' %r is NOT defined in SCS Blender Tools...!' % shader_attribute_id)
    '''

    item_space = item_space.split(percentage=1 / (1 - split_perc + 0.000001) * 0.1, align=True)
    props = item_space.operator("material.scs_looks_wt", text="WT")
    props.property_str = "shader_attribute_" + tag

    if tag == 'diffuse':
        item_space.prop(mat.scs_props, 'shader_attribute_diffuse', text='')
        if linked_vals:
            item_space.prop(mat, 'diffuse_color', text='')
    elif tag == 'specular':
        item_space.prop(mat.scs_props, 'shader_attribute_specular', text='')
        if linked_vals:
            item_space.prop(mat, 'specular_color', text='')
    elif tag == 'shininess':
        item_space.prop(mat.scs_props, 'shader_attribute_shininess', text='')
        # if linked_vals: item_space.prop(mat, 'specular_intensity', text='')
        if linked_vals:
            item_space.prop(mat, 'specular_hardness', text='')
    elif tag == 'add_ambient':
        item_space.prop(mat.scs_props, 'shader_attribute_add_ambient', text='')
        if linked_vals:
            item_space.prop(mat, 'ambient', text='')
    elif tag == 'reflection':
        item_space.prop(mat.scs_props, 'shader_attribute_reflection', text='')
        if linked_vals:
            item_space.prop(mat.raytrace_mirror, 'reflect_factor', text='')
    elif tag == 'reflection2':
        item_space.prop(mat.scs_props, 'shader_attribute_reflection2', text='')
    elif tag == 'shadow_bias':
        item_space.prop(mat.scs_props, 'shader_attribute_shadow_bias', text='')
        if linked_vals:
            item_space.prop(mat, 'shadow_buffer_bias', text='')
    elif tag == 'env_factor':
        item_space.prop(mat.scs_props, 'shader_attribute_env_factor', text='')
    elif tag == 'fresnel':
        item_space.column().prop(mat.scs_props, 'shader_attribute_fresnel', text='')
    elif tag == 'tint':
        item_space.prop(mat.scs_props, 'shader_attribute_tint', text='')
    elif tag == 'tint_opacity':
        item_space.prop(mat.scs_props, 'shader_attribute_tint_opacity', text='')
    elif tag.startswith("aux") and hasattr(mat.scs_props, "shader_attribute_" + tag):

        col = item_space.column().column(align=True)

        auxiliary_prop = getattr(mat.scs_props, "shader_attribute_" + tag, None)

        for item in auxiliary_prop:
            col.prop(item, 'value', text='')

    else:
        item_space.label('Undefined Shader Attribute Type!', icon=label_icon)
Esempio n. 12
0
    def draw(self, context):
        """UI draw function."""
        layout = self.layout
        scs_globals = _get_scs_globals()

        is_active_sun_profile_valid = (
            0 <= scs_globals.sun_profiles_inventory_active < len(
                scs_globals.sun_profiles_inventory))
        is_ligting_scene_used = (context.scene and context.scene.background_set
                                 and context.scene.background_set.name
                                 == _LIGHTING_consts.scene_name)

        # draw operator for disabling lighting scene
        if is_ligting_scene_used:
            layout.operator("world.scs_disable_lighting_in_scene", icon="QUIT")

        # draw warning if lighting scene is not used as background set in current scene
        if is_active_sun_profile_valid and not is_ligting_scene_used:
            _shared.draw_warning_operator(
                layout,
                "SCS Lighting Not Used",
                "Current scene is not using SCS Ligthing.\n"
                "If you want to enable it, you either press icon beside sun profile name in the list or\n"
                "use 'Apply Values to SCS Lighting' button located on the bottom of selected sun profile details.",
                text="SCS Lighting Not Used: Click For Info",
                icon="INFO")

        # prepare main box containing header and body
        col = layout.column(align=True)
        header = col.box()
        body = col.box()

        # 1. header
        # library path
        row = header.row(align=True)
        split = row.split(percentage=0.35)
        split.label("Sun Profiles Library:", icon="FILE_TEXT")
        row = split.row(align=True)
        row.alert = not _path_utils.is_valid_sun_profiles_library_path()
        row.prop(scs_globals, "sun_profiles_lib_path", text="")
        row.operator("scene.select_sun_profiles_lib_path",
                     text="",
                     icon='FILESEL')

        # 2. body
        # lighting scene east direction
        row = body.row(align=True)

        left_col = row.row(align=True)
        left_col.enabled = not scs_globals.lighting_east_lock
        left_col.label("", icon="LAMP_SPOT")
        left_col.separator()
        left_col.prop(scs_globals,
                      "lighting_scene_east_direction",
                      slider=True)

        right_col = row.row(align=True)
        right_col.prop(scs_globals,
                       "lighting_east_lock",
                       icon="LOCKED",
                       icon_only=True)

        # now if we have multiple 3D views locking has to be disabled,
        # as it can not work properly with multiple views because all views share same SCS Lighting lamps
        if _view_3d_utils.has_multiple_view3d_spaces(screen=context.screen):
            right_col.enabled = False
            _shared.draw_warning_operator(
                row.row(align=True),
                "SCS Lighting East Lock Disabled!",
                "East lock can not be used, because you are using multiple 3D views and\n"
                "tools can not decide on which view you want to lock the east.",
                icon="INFO")

        # disable any UI from now on if active sun profile is not valid
        body.enabled = is_active_sun_profile_valid

        # loaded sun profiles list
        body.template_list('SCSSunProfileSlots',
                           list_id="",
                           dataptr=scs_globals,
                           propname="sun_profiles_inventory",
                           active_dataptr=scs_globals,
                           active_propname="sun_profiles_inventory_active",
                           rows=3,
                           maxrows=5,
                           type='DEFAULT',
                           columns=9)

        # active/selected sun profile props
        if is_active_sun_profile_valid:

            layout = body.box().column()

            layout.label("Selected Sun Profile Details:", icon='LAMP')
            layout.separator()

            active_sun_profile = scs_globals.sun_profiles_inventory[
                scs_globals.sun_profiles_inventory_active]

            layout.row(align=True).prop(active_sun_profile, "low_elevation")
            layout.row(align=True).prop(active_sun_profile, "high_elevation")

            layout.row(align=True).prop(active_sun_profile, "ambient")
            layout.row(align=True).prop(active_sun_profile, "ambient_hdr_coef")

            layout.row(align=True).prop(active_sun_profile, "diffuse")
            layout.row(align=True).prop(active_sun_profile, "diffuse_hdr_coef")

            layout.row(align=True).prop(active_sun_profile, "specular")
            layout.row(align=True).prop(active_sun_profile,
                                        "specular_hdr_coef")

            # layout.row(align=True).prop(active_sun_profile, "sun_color")
            # layout.row(align=True).prop(active_sun_profile, "sun_color_hdr_coef")

            layout.row(align=True).prop(active_sun_profile, "env")
            layout.row(align=True).prop(active_sun_profile, "env_static_mod")

            layout.separator()
            row = layout.row()
            row.scale_y = 1.5
            props = row.operator("world.scs_use_sun_profile",
                                 icon="SAVE_PREFS",
                                 text="Apply Values to SCS Lighting")
            props.sun_profile_index = scs_globals.sun_profiles_inventory_active