コード例 #1
0
def match_color_to_matrix(node):
    vcol_start = Vector(node.color_start)
    vcol_end = Vector(node.color_end)

    def element_iterated(matrix, theta, index):
        return matrix, Color(vcol_start.lerp(vcol_end, index * theta))[:]

    data = node.inputs['Matrix'].sv_get()
    data_out = []
    get_mat_theta_idx = data_out.append

    if len(data) > 0:
        if is_matrix(data[0]):
            # 0. likely stores [matrix, matrix, matrix, ..]
            theta = 1 / len(data)
            for idx, matrix in enumerate(data):
                get_mat_theta_idx([matrix, theta, idx])

        elif is_matrix(data[0][0]):

            if all(
                    isinstance(m, list) and len(m) == 1 and is_matrix(m[0])
                    for m in data):
                # 1. stores [[matrix],[matrix],..]
                theta = 1 / len(data)
                for idx, m in enumerate(data):
                    matrix = m[0]
                    get_mat_theta_idx([matrix, theta, idx])

            else:
                # 2. stores [[matrix, matrix, matrix],[matrix, matrix, matrix],..]
                for matrix_list in data:
                    if len(matrix_list) == 0:
                        continue
                    theta = 1 / len(matrix_list)
                    for idx, matrix in enumerate(matrix_list):
                        get_mat_theta_idx([matrix, theta, idx])

    if not node.simple:
        return [element_iterated(*values) for values in data_out]
    else:
        return [element_iterated(*values) for values in data_out]
    return data_out
コード例 #2
0
ファイル: viewer_matrix.py プロジェクト: elfnor/sverchok
def match_color_to_matrix(node):
    vcol_start = Vector(node.color_start)
    vcol_end = Vector(node.color_end)

    def element_iterated(matrix, theta, index):
        return matrix, Color(vcol_start.lerp(vcol_end, index*theta))[:]

    data = node.inputs['Matrix'].sv_get()
    data_out = []
    get_mat_theta_idx = data_out.append

    if len(data) > 0:
        if is_matrix(data[0]):
            # 0. likely stores [matrix, matrix, matrix, ..]
            theta = 1 / len(data)
            for idx, matrix in enumerate(data):
                get_mat_theta_idx([matrix, theta, idx])

        elif is_matrix(data[0][0]):

            if all(isinstance(m, list) and len(m) == 1 and is_matrix(m[0]) for m in data):
                # 1. stores [[matrix],[matrix],..]
                theta = 1 / len(data)
                for idx, m in enumerate(data):
                    matrix = m[0]
                    get_mat_theta_idx([matrix, theta, idx])

            else:
                # 2. stores [[matrix, matrix, matrix],[matrix, matrix, matrix],..]
                for matrix_list in data:
                    if len(matrix_list) == 0:
                        continue
                    theta = 1 / len(matrix_list)
                    for idx, matrix in enumerate(matrix_list):
                        get_mat_theta_idx([matrix, theta, idx])


    if not node.simple:
         return [element_iterated(*values) for values in data_out]
    else:
         return [element_iterated(*values) for values in data_out]
    return data_out
コード例 #3
0
def get_matrix(socket):
    matrix_in_data = socket.sv_get()
    try:
        first_matrix = is_matrix(matrix_in_data[0])
        if first_matrix:
            matrix = matrix_in_data[0]
        else:
            matrix = matrix_in_data[0][0]
        return matrix

    except Exception as err:
        print(repr(err))
コード例 #4
0
ファイル: sv_3dview_tools.py プロジェクト: elfnor/sverchok
def get_matrix(socket):
    matrix_in_data = socket.sv_get()
    try:
        first_matrix = is_matrix(matrix_in_data[0])
        if first_matrix:
            matrix = matrix_in_data[0]
        else:
            matrix = matrix_in_data[0][0]
        return matrix
        
    except Exception as err:
        print(repr(err))