splinecraft
3/25/2017 - 1:58 AM

get scaling values

get scaling values

import pymel.core as pm

attribute = 'rotateX'
ease = 'flat'
hard = 'linear'

curve_types = {'ease_out_ease_in': [{'at': attribute,
                                     'itt': ease,
                                     'ott': ease,
                                     'value': 0},
                                    {'at': attribute,
                                     'itt': ease,
                                     'ott': ease,
                                     'value': 1.0}],
               'hard_out_ease_in': [{'at': attribute,
                                     'itt': hard,
                                     'ott': hard,
                                     'value': 0},
                                    {'at': attribute,
                                     'itt': ease,
                                     'ott': ease,
                                     'value': 1.0}],
               'ease_out_hard_in': [{'at': attribute,
                                     'itt': ease,
                                     'ott': ease,
                                     'value': 0},
                                    {'at': attribute,
                                     'itt': hard,
                                     'ott': hard,
                                     'value': 1.0}],
               'hard_out_hard_in': [{'at': attribute,
                                     'itt': hard,
                                     'ott': hard,
                                     'value': 0},
                                    {'at': attribute,
                                     'itt': hard,
                                     'ott': hard,
                                     'value': 1.0}]
               }

key_tangents = {'ease_out_ease_in': [0.5, 0.5],
                'hard_out_ease_in': [0.01, 0.8],
                'ease_out_hard_in': [0.8, 0.01],
                'hard_out_hard_in': [0.01, 0.01]}


def generate_multipliers(iterations, curve_type='ease_out_ease_in'):
    """Generates a list of scaling values based on various curves"""
    curve_args = curve_types[curve_type]  # which curve to use
    values = []
    loc = pm.spaceLocator(name='gen_loc')  # temp locator on which to generate an anim curve
    times = [1, iterations + 1]  # start/end frame of the curve

    for args, frame, tangent in zip(curve_args, times, key_tangents[curve_type]):
        pm.setKeyframe(loc, time=(frame,), **args)
    # pm.setKeyframe(loc, at='rotateX', time=(n + 1,), v=1.0, itt='flat', ott='flat')
        pm.keyTangent(loc, edit=True, at=attribute, time=(frame,), weightLock=False, lock=False,
                      inWeight=(iterations * tangent), outWeight=(iterations * tangent))

    for frame in xrange(2, iterations + 2):
        v = pm.keyframe(loc, q=True, at=attribute, eval=True, time=(frame,), vc=True)[0]
        values.append(v)

    print(values)
    print(len(values))

    pm.delete(loc)

    return values


#generate_multipliers(iterations, 'hard_out_hard_in')