def export(filepath, texture_name, settings): """Exports TOBJ with settings. :param filepath: absolute file path with name for TOBJ :type filepath: str :param texture_name: name of texture file :type texture_name: str :param settings: settings of texture saved in material.scs_props :type settings: set :return: True if file was written successfully; False otherwise """ # try to load tobj container from file path # to be able to keep all the settings from before # and overwrite only what settings we support container = None if os.path.isfile(filepath): container = _TobjContainer.read_data_from_file(filepath) # if container for some reason wasn't loaded create new one if container is None: container = _TobjContainer() container.map_type = "2d" if texture_name is not None: container.map_names.append(texture_name) # change settings only on supported 2d texture type if container.map_type == "2d": # MAP NAMES # try to change map names with current texture name # otherwise add new value if len(container.map_names) > 0: container.map_names[0] = texture_name elif texture_name is not None: container.map_names.append(texture_name) # ADDR if "u_repeat" in settings: addr_u = "repeat" else: addr_u = "clamp_to_edge" if "v_repeat" in settings: addr_v = "repeat" else: addr_v = "clamp_to_edge" container.addr.clear() container.addr.append(addr_u) container.addr.append(addr_v) # USAGE container.usage = "tsnormal" if "tsnormal" in settings else "" else: lprint("D Ignoring TOBJ settings save as TOBJ is featuring non 2d map type!") return container.write_data_to_file(filepath)
def get_settings_and_type(filepath, as_set=False): """Loads TOBJ and gets setting and map type out of it. Settings should be used in "scs_props.shader_texture_XXX_settings" on material. Map type can be used to for identifying of visiblity of settings in UI NOTE: settings are read only if map type is "2d" for any other map types defaults are returened :param filepath: tobj filepath :type filepath: str :param as_set: optional flag indicating type of result :type as_set: bool :return: if as_set returns set and map type; otherwise binary representation of settings and map type is returned :rtype: tuple[string, str] | tuple[set, str] """ addr = "00" tsnormal = "0" color_space_linear = "0" container = _TobjContainer.read_data_from_file(filepath) if container and container.map_type == "2d": addr = "" for addr_value in container.addr: if addr_value == "clamp_to_edge": addr += "0" elif addr_value == "repeat": addr += "1" else: # NOTE: there are also other options for addr like: mirror etc. # But artists are not encouraged to really used them, so use default: "clamp_to_edge". addr += "0" addr = addr[::-1] if container.usage == "tsnormal": tsnormal = "1" if container and container.color_space == "linear": color_space_linear = "1" # if container is still empty create default one so map type can be returned if not container: container = _TobjContainer() # return result as set if as_set: return __get_as_set(addr, tsnormal, color_space_linear), container.map_type return color_space_linear + tsnormal + addr, container.map_type
def get_settings_and_type(filepath, as_set=False): """Loads TOBJ and gets setting and map type out of it. Settings should be used in "scs_props.shader_texture_XXX_settings" on material. Map type can be used to for identifying of visiblity of settings in UI NOTE: settings are read only if map type is "2d" for any other map types defaults are returened :param filepath: tobj filepath :type filepath: str :param as_set: optional flag indicating type of result :type as_set: bool :return: if as_set returns set and map type; otherwise binary representation of settings and map type is returned :rtype: tuple[string, str] | tuple[set, str] """ addr = "00" tsnormal = "0" container = _TobjContainer.read_data_from_file(filepath) if container and container.map_type == "2d": addr = "" for addr_value in container.addr: if addr_value == "clamp_to_edge": addr += "0" elif addr_value == "repeat": addr += "1" else: # NOTE: there are also other options for addr like: mirror etc. # But artists are not encouraged to really used them, so use default: "clamp_to_edge". addr += "0" addr = addr[::-1] if container.usage == "tsnormal": tsnormal = "1" # if container is still empty create default one so map type can be returned if not container: container = _TobjContainer() # return result as set if as_set: return __get_as_set(addr, tsnormal), container.map_type return tsnormal + addr, container.map_type
def export(filepath, texture_name, settings): """Exports TOBJ with settings. :param filepath: absolute file path with name for TOBJ :type filepath: str :param texture_name: name of texture file :type texture_name: str :param settings: settings of texture saved in material.scs_props :type settings: set :return: True if file was written successfully; False otherwise """ # try to load tobj container from file path # to be able to keep all the settings from before # and overwrite only what settings we support container = None if os.path.isfile(filepath): container = _TobjContainer.read_data_from_file(filepath) # if container for some reason wasn't loaded create new one if container is None: container = _TobjContainer() container.map_type = "2d" if texture_name is not None: container.map_names.append(texture_name) # change settings only on supported 2d texture type if container.map_type == "2d": # MAP NAMES # try to change map names with current texture name # otherwise add new value if len(container.map_names) > 0: container.map_names[0] = texture_name elif texture_name is not None: container.map_names.append(texture_name) # ADDR if "u_repeat" in settings: addr_u = "repeat" else: addr_u = "clamp_to_edge" if "v_repeat" in settings: addr_v = "repeat" else: addr_v = "clamp_to_edge" container.addr.clear() container.addr.append(addr_u) container.addr.append(addr_v) # USAGE container.usage = "tsnormal" if "tsnormal" in settings else "" else: lprint("D Ignoring TOBJ settings save as TOBJ is featuring non 2d map type!") container.color_space = "linear" if "color_space_linear" in settings else "" return container.write_data_to_file(filepath)