コード例 #1
0
ファイル: path.py プロジェクト: miranbox/BlenderTools
def get_texture_path_from_tobj(tobj_filepath, raw_value=False):
    """Get absolute path of texture from given tobj filepath.
    If raw value is requested returned path is direct value written in TOBJ.
    NOTE: there is no safety check if file exists.

    :param tobj_filepath: absolute tobj file path
    :type tobj_filepath: str
    :param raw_value: flag for indicating if texture path shall be returned as it's written in TOBJ
    :type raw_value: bool
    :return: absolute texture file path if found or None
    :rtype: str | None
    """

    from io_scs_tools.internals.containers.tobj import TobjContainer

    container = TobjContainer.read_data_from_file(tobj_filepath, skip_validation=raw_value)
    tobj_dir, tobj_filename = os.path.split(tobj_filepath)

    if container is None:
        return None

    if raw_value:
        return container.map_names[0]

    if container.map_names[0][0] == "/":
        return get_abs_path("//" + container.map_names[0][1:])

    return os.path.join(tobj_dir, container.map_names[0])
コード例 #2
0
def get_texture_path_from_tobj(tobj_filepath, raw_value=False):
    """Get absolute path of texture from given tobj filepath.
    If raw value is requested returned path is direct value written in TOBJ.
    NOTE: there is no safety check if file exists.

    :param tobj_filepath: absolute tobj file path
    :type tobj_filepath: str
    :param raw_value: flag for indicating if texture path shall be returned as it's written in TOBJ
    :type raw_value: bool
    :return: absolute texture file path if found or None
    :rtype: str | None
    """

    from io_scs_tools.internals.containers.tobj import TobjContainer

    container = TobjContainer.read_data_from_file(tobj_filepath,
                                                  skip_validation=raw_value)
    tobj_dir, tobj_filename = os.path.split(tobj_filepath)

    if container is None:
        return None

    if raw_value:
        return container.map_names[0]

    if container.map_names[0][0] == "/":
        return get_abs_path("//" + container.map_names[0][1:])

    return os.path.join(tobj_dir, container.map_names[0])
コード例 #3
0
ファイル: tobj.py プロジェクト: miranbox/BlenderTools
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)
コード例 #4
0
ファイル: tobj.py プロジェクト: hanshuogang/Learnbgame
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
コード例 #5
0
ファイル: tobj.py プロジェクト: miranbox/BlenderTools
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
コード例 #6
0
ファイル: path.py プロジェクト: MariusMyburg/BlenderTools
def get_texture_paths_from_tobj(tobj_filepath, raw_value=False, first_only=False):
    """Get absolute path(s) of textures from given tobj filepath.
    If raw value is requested returned path(s) are direct values written in TOBJ.
    If first only is requested only first path is returned.

    :param tobj_filepath: absolute tobj file path
    :type tobj_filepath: str
    :param raw_value: flag for indicating if texture path(s) shall be returned as it's written in TOBJ
    :type raw_value: bool
    :param first_only: flag for requesting only first entry from TOBJ map names (only first texture)
    :type first_only: bool
    :return: absolute texture file path(s) if found or None
    :rtype: tuple[str] | None
    """
    from io_scs_tools.internals.containers.tobj import TobjContainer

    container = TobjContainer.read_data_from_file(tobj_filepath, skip_validation=raw_value)
    tobj_dir, tobj_filename = os.path.split(tobj_filepath)

    if container is None:
        return None

    if raw_value:
        if first_only:
            return container.map_names[0],

        return tuple(container.map_names)

    abs_texture_paths = []
    for map_name in container.map_names:
        if map_name[0] == "/":
            curr_abs_tobj_path = get_abs_path("//" + map_name[1:])
        else:
            curr_abs_tobj_path = os.path.join(tobj_dir, map_name)

        # directly intercept and return first texture path
        if first_only:
            return curr_abs_tobj_path,

        abs_texture_paths.append(curr_abs_tobj_path)

    return tuple(abs_texture_paths)
コード例 #7
0
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)