Exemple #1
0
def __compile_frame_list(range_type, frame_string, by_frame):
    assert isinstance(range_type, int)
    assert frame_string is None or isinstance(frame_string, basestring)
    assert isinstance(by_frame, int)
    frame_nums = []
    if range_type == const.RANGE_TYPE_TIMELINE_INNER_VALUE:
        start, end = utils_time.get_maya_timeline_range_inner()
        frame_nums = [f for f in xrange(start, end + 1, by_frame)]
    elif range_type == const.RANGE_TYPE_TIMELINE_OUTER_VALUE:
        start, end = utils_time.get_maya_timeline_range_outer()
        frame_nums = [f for f in xrange(start, end + 1, by_frame)]
    elif range_type == const.RANGE_TYPE_CUSTOM_FRAMES_VALUE:
        if frame_string is None:
            start, end = utils_time.get_maya_timeline_range_inner()
            frame_string = '{0}-{1}'.format(start, end)
        frame_nums = converttypes.stringToIntList(frame_string)

        # Apply 'by_frame' to custom frame ranges.
        start = min(frame_nums)
        frame_nums = [
            n for n in frame_nums if (float(n - start) % by_frame) == 0
        ]
    return frame_nums
Exemple #2
0
def compile_collection(col, prog_fn=None):
    """
    Compiles, checks and validates the collection, ready for a solve.

    :param col: Collection to execute.
    :type col: Collection

    :param prog_fn: Progress function that is called each time progress
                    is made. The function should take a single 'int'
                    argument, and the integer is expected to be a
                    percentage value, between 0 and 100.
    :type prog_fn: None or function
    """
    s = time.time()
    sol_list = []
    solver_tab = col_state.get_solver_tab_from_collection(col)
    assert isinstance(solver_tab, (str, unicode))
    if solver_tab == const.SOLVER_TAB_BASIC_VALUE:
        sol = mmapi.SolverBasic()
        range_type = col_state.get_solver_range_type_from_collection(col)
        if range_type == const.RANGE_TYPE_CURRENT_FRAME_VALUE:
            frame_num = lib_maya_utils.get_current_frame()
            frame = mmapi.Frame(frame_num)
            sol.set_use_single_frame(True)
            sol.set_single_frame(frame)
            sol_list.append(sol)
        else:
            by_frame = col_state.get_solver_increment_by_frame_from_collection(
                col)
            frame_string = col_state.get_solver_frames_from_collection(col)
            frame_nums = __compile_frame_list(range_type, frame_string,
                                              by_frame)
            frames = [mmapi.Frame(f) for f in frame_nums]
            sol.set_frame_list(frames)
            sol_list.append(sol)

    elif solver_tab == const.SOLVER_TAB_STANDARD_VALUE:
        sol = mmapi.SolverStandard()
        range_type = col_state.get_solver_range_type_from_collection(col)
        if range_type == const.RANGE_TYPE_CURRENT_FRAME_VALUE:
            frame_num = lib_maya_utils.get_current_frame()
            frame = mmapi.Frame(frame_num)
            sol.set_use_single_frame(True)
            sol.set_single_frame(frame)
            sol_list.append(sol)
        else:
            # Frame numbers
            by_frame = col_state.get_solver_increment_by_frame_from_collection(
                col)
            frame_string = col_state.get_solver_frames_from_collection(col)
            frame_nums = __compile_frame_list(range_type, frame_string,
                                              by_frame)

            # Root frame numbers
            root_frame_num_string = col_state.get_solver_root_frames_from_collection(
                col)
            if root_frame_num_string is None:
                start, end = utils_time.get_maya_timeline_range_inner()
                root_frame_num_string = '{0},{1}'.format(start, end)
            root_frame_nums = converttypes.stringToIntList(
                root_frame_num_string)

            frames = [
                mmapi.Frame(f) for f in frame_nums if f not in root_frame_nums
            ]
            root_frames = [mmapi.Frame(f) for f in root_frame_nums]
            sol.set_root_frame_list(root_frames)
            sol.set_frame_list(frames)

            global_solve = col_state.get_solver_global_solve_from_collection(
                col)
            only_root = col_state.get_solver_only_root_frames_from_collection(
                col)
            sol.set_global_solve(global_solve)
            sol.set_only_root_frames(only_root)
            sol_list.append(sol)

    elif solver_tab.lower() == const.SOLVER_TAB_LEGACY_VALUE:
        step_list = get_solver_steps_from_collection(col)
        sol_list = compile_solvers_from_steps(col, step_list, prog_fn=prog_fn)

    else:
        msg = 'Solver tab value is invalid: %r'
        raise TypeError(msg % solver_tab)
    col.set_solver_list(sol_list)
    e = time.time()
    LOG.debug('Compile time (GUI): %r seconds', e - s)
    return