コード例 #1
0
ファイル: pix.py プロジェクト: rridhan/BlenderTools
def _read_matrix(file, line_split):
    """Reads the other lines to make a matrix."""
    matrix = Matrix()
    for row in range(4):
        for col in range(4):
            matrix[row][col] = hex_string_to_float(line_split[col])
        if row < 3:
            data_type, line = next_line(file)
            line_split = re.split(" +", line.strip())
    return matrix
コード例 #2
0
ファイル: pix.py プロジェクト: tiagofer/BlenderTools
def _read_matrix(file, line_split):
    """Reads the other lines to make a matrix."""
    matrix = Matrix()
    for row in range(4):
        for col in range(4):
            matrix[row][col] = hex_string_to_float(line_split[col])
        if row < 3:
            data_type, line = next_line(file)
            line_split = re.split(' +', line.strip())
    return matrix
コード例 #3
0
ファイル: pix.py プロジェクト: rridhan/BlenderTools
def _get_prop(line):
    """Takes single data line and returns data properties.

    :param line: A single line from a file
    :type line: str
    :return: Data property value in appropriate data type
    :rtype: various
    """
    prop_split = re.split(r"[:\(\r\n]+", line, 1)
    prop = []
    if len(prop_split) == 2:
        # print('-prop_split: "%s"' % str(prop_split))
        prop.append(prop_split[0].strip())
        prop_value = prop_split[1].strip()
        if prop_value in ("FLOAT", "FLOAT2", "FLOAT3", "FLOAT4", "INT", "STRING"):
            prop.append(prop_value)
            return prop
        elif prop_value in ("FLOAT4x4",):
            # print('WARNING - UNHANDLED VALUE (prop_value: %s)' % str(prop_value))
            prop.append(prop_value)
            return prop
        else:
            try:
                if prop_value[0] == '"' and prop_value[-1] == '"':

                    # SINGLE STRING
                    prop_value = prop_value[1:-1]
                else:
                    try:

                        # SINGLE INTEGER
                        prop_value = int(prop_value)
                    except:
                        try:

                            # SINGLE FLOAT
                            prop_value = float(prop_value)
                        except:
                            if prop_value.count(" ") > 0:
                                # if prop_value.startswith("("):
                                if prop_value.endswith(")"):
                                    val_list = []
                                    prop_values_only = prop_value[1:-1]
                                    for string in re.split(r"[, ]+", prop_values_only):
                                        if string:
                                            val = "<error>"
                                            if string.startswith("&"):

                                                # LIST OF - HEX NUMBERS
                                                val = hex_string_to_float(string)
                                            else:
                                                try:

                                                    # LIST OF - INTEGERS
                                                    val = int(string)
                                                except:
                                                    try:

                                                        # LIST OF - FLOATS
                                                        val = float(string)
                                                    except:

                                                        # LIST OF - STRINGS
                                                        val = string[1:-1]
                                            val_list.append(val)

                                    # LIST OF HEX NUMBERS
                                    prop_value = tuple(val_list)
                                else:
                                    prop_values = re.split(r"[ ]+", prop_value)
                                    prop_value = []
                                    for val in prop_values:
                                        # SEQUENCE OF INTS (without brackets)
                                        prop_value.append(int(val))
                            else:
                                if prop_value.startswith("&"):

                                    # SINGLE HEX NUMBER
                                    prop_value = hex_string_to_float(prop_value)
                                elif prop_value in ("default", "true", "false"):

                                    # CERTAIN STRINGS WITHOUT ENCLOSING
                                    prop_value = str(prop_value)
                                else:

                                    # UNHANDLED DATA
                                    print(
                                        'WARNING - "internals/parsers/pix.py" - Unhandled case! (prop_value = %s)'
                                        % str(prop_value)
                                    )
            except:

                # NONE
                prop_value = None
            prop.append(prop_value)
    else:
        # print('WARNING - Unhandled case in "property" line "%s"! Skipped...' % line)
        return None
    return prop
コード例 #4
0
ファイル: pix.py プロジェクト: rridhan/BlenderTools
def _get_data(file, line):
    """Takes single data line and returns data index and list of its values."""
    data_split = re.split(r"[()]+", line)
    # print('data_split: "%s"' % data_split)

    # SKINNING DATA
    if len(data_split) > 3:
        try:
            data_index = int(data_split[0].strip())
            data_gap = data_split[1].strip()
            data_vec = re.split(" +", data_split[2].strip())  # This value is not used anymore.
            data = {}
            if data_gap == "" and len(data_vec) == 3:
                # print('  %i - %r - %s' % (data_index, data_gap, data_vec))

                # WEIGHTS
                data_type, line = next_line(file)
                line_split = re.split(" +", line.strip())
                if line_split[0] == "Weights:":
                    # print('%s  =-> "%s"' % (data_type, line_split))
                    data["weights"] = []
                    for cnt in range(int(line_split[1])):
                        w_index = int(line_split[(cnt * 2) + 2])
                        w_value = hex_string_to_float(line_split[(cnt * 2) + 3])
                        # print('  %i---%s' % (w_index, w_value))
                        data["weights"].append((w_index, w_value))

                # CLONES
                data_type, line = next_line(file)
                line_split = re.split(" +", line.strip())
                if line_split[0] == "Clones:":
                    # print('%s  =-> "%s"' % (data_type, line_split))
                    data["clones"] = []
                    for cnt in range(int(line_split[1])):
                        c_piece = int(line_split[(cnt * 2) + 2])
                        c_vertex = int(line_split[(cnt * 2) + 3])
                        # print('  %i---%s' % (c_piece, c_vertex))
                        data["clones"].append((c_piece, c_vertex))

                # CLOSING BRACKET
                data_type, line = next_line(file)
                # line_split = re.split(' +', line.strip())
                # print('%s  =-> "%s"' % (data_type, line_split))
        except:
            print('WARNING - Unhandled case in "Skinning Data" line "%s"! Skipped...' % line)
            return None, []
    else:
        try:
            data_index = int(data_split[0].strip())
            data_str_values = re.split(r"[ ]+", data_split[1].strip())
            # print('data_str_values: "%s"' % data_str_values)

            # BONE LIST
            if data_str_values[0].startswith('"') and data_str_values[0].endswith('"'):
                data = data_str_values[0][1:-1]
                # print('data: "%s"' % data)

            # ANIMATION MATRICES
            elif len(data_str_values) == 4 and line[-1] != ")":
                # print(' line: %s' % line)
                try:
                    data_index = int(data_split[0].strip())
                except:
                    print('WARNING - Unhandled case in "Animation Matrices" line "%s"! Skipped...' % line)
                    return None, []
                data = _read_matrix(file, data_str_values)

            # BONE STRUCTURE
            elif data_str_values[0] == "Name:":
                data = {}
                if data_str_values[1].startswith('"') and data_str_values[1].endswith('"'):
                    name = data_str_values[1][1:-1]
                    data["name"] = name
                    # print('    data_str_values: "%s"' % data_str_values)

                    # PARENT
                    data_type, line = next_line(file)
                    line_split = re.split(" +", line.strip())
                    if line_split[0] == "Parent:":
                        parent = line_split[1][1:-1]
                        data["parent"] = parent
                    # print('%s  =-> "%s"' % (data_type, line_split))

                    # MATRIX - LINE 1
                    data_type, line = next_line(file)
                    line_split = re.split(" +", line.strip())
                    if line_split[0] == "Matrix:":
                        matrix = _read_matrix(file, line_split[2:])

                        # CLOSING BRACKET
                        data_type, line = next_line(file)
                        data["matrix"] = matrix
            else:
                data = []
                for data_str in data_str_values:
                    if data_str[0] == "&":
                        val = hex_string_to_float(data_str)
                    elif "." in data_str:
                        val = float(data_str)
                    else:
                        val = int(data_str)
                    data.append(val)
        except:
            print('WARNING - Unhandled case in "Data" line "%s"! Skipped...' % line)
            return None, []
    return data_index, data
コード例 #5
0
ファイル: pix.py プロジェクト: tiagofer/BlenderTools
def _get_prop(line):
    """Takes single data line and returns data properties.

    :param line: A single line from a file
    :type line: str
    :return: Data property value in appropriate data type
    :rtype: various
    """
    prop_split = re.split(r'[:\(\r\n]+', line, 1)
    prop = []
    if len(prop_split) == 2:
        # print('-prop_split: "%s"' % str(prop_split))
        prop.append(prop_split[0].strip())
        prop_value = prop_split[1].strip()
        if prop_value in ("FLOAT", "FLOAT2", "FLOAT3", "FLOAT4", "INT",
                          "STRING"):
            prop.append(prop_value)
            return prop
        elif prop_value in ("FLOAT4x4", ):
            # print('WARNING - UNHANDLED VALUE (prop_value: %s)' % str(prop_value))
            prop.append(prop_value)
            return prop
        else:
            try:
                if prop_value[0] == '"' and prop_value[-1] == '"':

                    # SINGLE STRING
                    prop_value = prop_value[1:-1]
                else:
                    try:

                        # SINGLE INTEGER
                        prop_value = int(prop_value)
                    except:
                        try:

                            # SINGLE FLOAT
                            prop_value = float(prop_value)
                        except:
                            if prop_value.count(' ') > 0:
                                # if prop_value.startswith("("):
                                if prop_value.endswith(")"):
                                    val_list = []
                                    prop_values_only = prop_value[1:-1]
                                    for string in re.split(
                                            r'[, ]+', prop_values_only):
                                        if string:
                                            val = "<error>"
                                            if string.startswith("&"):

                                                # LIST OF - HEX NUMBERS
                                                val = hex_string_to_float(
                                                    string)
                                            else:
                                                try:

                                                    # LIST OF - INTEGERS
                                                    val = int(string)
                                                except:
                                                    try:

                                                        # LIST OF - FLOATS
                                                        val = float(string)
                                                    except:

                                                        # LIST OF - STRINGS
                                                        val = string[1:-1]
                                            val_list.append(val)

                                    # LIST OF HEX NUMBERS
                                    prop_value = tuple(val_list)
                                else:
                                    prop_values = re.split(r'[ ]+', prop_value)
                                    prop_value = []
                                    for val in prop_values:
                                        # SEQUENCE OF INTS (without brackets)
                                        prop_value.append(int(val))
                            else:
                                if prop_value.startswith("&"):

                                    # SINGLE HEX NUMBER
                                    prop_value = hex_string_to_float(
                                        prop_value)
                                elif prop_value in ("default", "true",
                                                    "false"):

                                    # CERTAIN STRINGS WITHOUT ENCLOSING
                                    prop_value = str(prop_value)
                                else:

                                    # UNHANDLED DATA
                                    print(
                                        'WARNING - "internals/parsers/pix.py" - Unhandled case! (prop_value = %s)'
                                        % str(prop_value))
            except:

                # NONE
                prop_value = None
            prop.append(prop_value)
    else:
        # print('WARNING - Unhandled case in "property" line "%s"! Skipped...' % line)
        return None
    return prop
コード例 #6
0
ファイル: pix.py プロジェクト: tiagofer/BlenderTools
def _get_data(file, line):
    """Takes single data line and returns data index and list of its values."""
    data_split = re.split(r'[()]+', line)
    # print('data_split: "%s"' % data_split)

    # SKINNING DATA
    if len(data_split) > 3:
        try:
            data_index = int(data_split[0].strip())
            data_gap = data_split[1].strip()
            data_vec = re.split(
                ' +', data_split[2].strip())  # This value is not used anymore.
            data = {}
            if data_gap == "" and len(data_vec) == 3:
                # print('  %i - %r - %s' % (data_index, data_gap, data_vec))

                # WEIGHTS
                data_type, line = next_line(file)
                line_split = re.split(' +', line.strip())
                if line_split[0] == "Weights:":
                    # print('%s  =-> "%s"' % (data_type, line_split))
                    data['weights'] = []
                    for cnt in range(int(line_split[1])):
                        w_index = int(line_split[(cnt * 2) + 2])
                        w_value = hex_string_to_float(line_split[(cnt * 2) +
                                                                 3])
                        # print('  %i---%s' % (w_index, w_value))
                        data['weights'].append((w_index, w_value))

                # CLONES
                data_type, line = next_line(file)
                line_split = re.split(' +', line.strip())
                if line_split[0] == "Clones:":
                    # print('%s  =-> "%s"' % (data_type, line_split))
                    data['clones'] = []
                    for cnt in range(int(line_split[1])):
                        c_piece = int(line_split[(cnt * 2) + 2])
                        c_vertex = int(line_split[(cnt * 2) + 3])
                        # print('  %i---%s' % (c_piece, c_vertex))
                        data['clones'].append((c_piece, c_vertex))

                # CLOSING BRACKET
                data_type, line = next_line(file)
                # line_split = re.split(' +', line.strip())
                # print('%s  =-> "%s"' % (data_type, line_split))
        except:
            print(
                'WARNING - Unhandled case in "Skinning Data" line "%s"! Skipped...'
                % line)
            return None, []
    else:
        try:
            data_index = int(data_split[0].strip())
            data_str_values = re.split(r'[ ]+', data_split[1].strip())
            # print('data_str_values: "%s"' % data_str_values)

            # BONE LIST
            if data_str_values[0].startswith(
                    '"') and data_str_values[0].endswith('"'):
                data = data_str_values[0][1:-1]
                # print('data: "%s"' % data)

            # ANIMATION MATRICES
            elif len(data_str_values) == 4 and line[-1] != ")":
                # print(' line: %s' % line)
                try:
                    data_index = int(data_split[0].strip())
                except:
                    print(
                        'WARNING - Unhandled case in "Animation Matrices" line "%s"! Skipped...'
                        % line)
                    return None, []
                data = _read_matrix(file, data_str_values)

            # BONE STRUCTURE
            elif data_str_values[0] == "Name:":
                data = {}
                if data_str_values[1].startswith(
                        '"') and data_str_values[1].endswith('"'):
                    name = data_str_values[1][1:-1]
                    data['name'] = name
                    # print('    data_str_values: "%s"' % data_str_values)

                    # PARENT
                    data_type, line = next_line(file)
                    line_split = re.split(' +', line.strip())
                    if line_split[0] == "Parent:":
                        parent = line_split[1][1:-1]
                        data['parent'] = parent
                    # print('%s  =-> "%s"' % (data_type, line_split))

                    # MATRIX - LINE 1
                    data_type, line = next_line(file)
                    line_split = re.split(' +', line.strip())
                    if line_split[0] == "Matrix:":
                        matrix = _read_matrix(file, line_split[2:])

                        # CLOSING BRACKET
                        data_type, line = next_line(file)
                        data['matrix'] = matrix
            else:
                data = []
                for data_str in data_str_values:
                    if data_str[0] == '&':
                        val = hex_string_to_float(data_str)
                    elif "." in data_str:
                        val = float(data_str)
                    else:
                        val = int(data_str)
                    data.append(val)
        except:
            print('WARNING - Unhandled case in "Data" line "%s"! Skipped...' %
                  line)
            return None, []
    return data_index, data