def execute(self, context): material = context.active_object.active_material if material: shader_texture_filepath = getattr( material.scs_props, "shader_texture_" + self.texture_type) if _path_utils.is_valid_shader_texture_path( shader_texture_filepath): tex_filepath = _path_utils.get_abs_path( shader_texture_filepath) if tex_filepath and (tex_filepath.endswith(".tga") or tex_filepath.endswith(".png")): if _tobj_exp.export(tex_filepath[:-4] + ".tobj", os.path.basename(tex_filepath), set()): _material_utils.reload_tobj_settings( material, self.texture_type) else: self.report({'ERROR'}, "Please load texture properly first!") return {'FINISHED'}
def execute(self, context): material = context.active_object.active_material if material: shader_texture_filepath = getattr(material.scs_props, "shader_texture_" + self.texture_type) if _path_utils.is_valid_shader_texture_path(shader_texture_filepath): tex_filepath = _path_utils.get_abs_path(shader_texture_filepath) if tex_filepath and (tex_filepath.endswith(".tga") or tex_filepath.endswith(".png")): if _tobj_exp.export(tex_filepath[:-4] + ".tobj", os.path.basename(tex_filepath), set()): _material_utils.reload_tobj_settings(material, self.texture_type) else: self.report({'ERROR'}, "Please load texture properly first!") return {'FINISHED'}
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")
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 = 'ERROR' # 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) 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")