Exemple #1
0
def vizBlink(sel, firstFrame, duration, offset=0, inv=False):
    for obj in sel:
        if not inv:
            pm.cutKey(obj, at='v')
            onKey = pm.setKeyframe(obj, at='v', t=firstFrame, v=1, s=False)
            offKey = pm.setKeyframe(obj,
                                    at='v',
                                    t=(firstFrame + duration),
                                    v=0,
                                    s=False)
            holdkey = pm.setKeyframe(obj,
                                     at='v',
                                     t=(firstFrame + (2 * duration) + offset),
                                     v=0,
                                     s=False)
            pm.setInfinity(obj.visibility, poi='cycle')
        elif inv:
            pm.cutKey(obj, at='v')
            offKey = pm.setKeyframe(obj, at='v', t=firstFrame, v=0, s=False)
            onKey = pm.setKeyframe(obj,
                                   at='v',
                                   t=(firstFrame + duration),
                                   v=1,
                                   s=False)
            holdkey = pm.setKeyframe(obj,
                                     at='v',
                                     t=(firstFrame + (duration * 2) + offset),
                                     v=1,
                                     s=False)
            pm.setInfinity(obj.visibility, poi='cycle')
def cbsHookup(*args, **kwargs):

    base = kwargs.setdefault('base')  #(string) The base mesh for the character
    bs = kwargs.setdefault(
        'bs'
    )  #(string) The blendshape deformer to which the shape should be added (if blank, a new deformer will be created
    shape = kwargs.setdefault(
        'shape')  #(string) The new target to add to the blendshape
    driver = kwargs.setdefault(
        'driver'
    )  #(string) Node and attribute to have drive the blendshape target weight
    driveRange = kwargs.setdefault(
        'driveRange', [0, 1]
    )  #(2 float list) The range of the driver to go from 0-1. [0]=target weight of 0, [1]=weight of 1
    tan = kwargs.setdefault(
        'tan', ['spline', 'spline']
    )  # (2 string list) The tangent types for the set driven keys. [0]=start, [1]=end
    infinity = kwargs.setdefault(
        'infinity', [False, False]
    )  # (2 bool list) sets whether or not to give the set driven key pre or post infinity. [0]=pre, [1]=post

    #create a blendshape deformer if one hasn't been specified
    if not bs:
        bs = pm.blendShape(base,
                           frontOfChain=True,
                           n='%s_corrective_bs' % base)[0]

    #add the new target to the blendshape
    targs = pm.blendShape(bs, q=True, t=True)
    for targ in targs:
        if str(shape).split('|')[-1] == str(targ).split('|')[-1]:
            pm.error(
                'It appears you already have a blendshape target named %s in the node %s. Please rename the new target with a unique name.'
                % (shape, bs))
    pm.blendShape(bs, e=True, t=[base, len(targs), shape, 1])

    #set up the set driven key to drive the blendshape
    pm.setDrivenKeyframe('%s.%s' % (bs, shape),
                         cd=driver,
                         dv=driveRange[0],
                         v=0,
                         itt=tan[0],
                         ott=tan[0])
    pm.setDrivenKeyframe('%s.%s' % (bs, shape),
                         cd=driver,
                         dv=driveRange[1],
                         v=1,
                         itt=tan[1],
                         ott=tan[1])

    #set up infinity if requested
    if infinity[0]:
        pm.setInfinity('%s.%s' % (bs, shape), pri='linear')
    if infinity[1]:
        pm.setInfinity('%s.%s' % (bs, shape), poi='linear')

    return bs
Exemple #3
0
def infinity(type='linear'):
    pm.setInfinity(pri=type, poi=type)
    pm.keyTangent(itt='spline', ott='spline')
Exemple #4
0
def makeTreads(*args):
    try:
        if ('world_object_up'
            ):  # if locator exists from a previous attempt, delete it
            pm.delete('world_object_up')
            pm.spaceLocator(name='world_object_up')
            pm.addAttr(ln="Tread_Cycle",
                       at='double',
                       dv=0,
                       hidden=False,
                       k=True)
            pm.select(clear=True)
            pm.parentConstraint('treadCurve', 'world_object_up')
    except:
        pm.spaceLocator(name='world_object_up')  # or else just create it
        pm.addAttr(ln="Tread_Cycle", at='double', dv=0, hidden=False, k=True)
        pm.select(clear=True)
        pm.parentConstraint('treadCurve', 'world_object_up')

    try:
        for j in treadJnts:  # if motionPaths exist from a previous attempt, delete them
            if ('motionPath' + str(treadJnts.index(j) + 1)):
                pm.delete('motionPath' + str(treadJnts.index(j) + 1))
    except:
        pass

    # get the Max Value of the curve, so the treads loop properly
    curveMaxValue = pm.getAttr('treadCurve.maxValue')
    print curveMaxValue

    # this loop will go through each joint in the treadJnts list
    for i in treadJnts:
        # for the first joint, which has index '0'
        if treadJnts.index(str(i)) == 0:
            # select the first joint and then the curve
            pm.select(clear=True)
            pm.select(i)
            pm.select('treadCurve', add=True)
            # constrain the first joint to the curve using motion path animation
            pm.pathAnimation(fractionMode=False,
                             follow=True,
                             followAxis='y',
                             upAxis='z',
                             worldUpType='object',
                             worldUpObject='world_object_up',
                             inverseUp=True,
                             inverseFront=False,
                             bank=False)
            # delete useless nodes we're not gonna need
            pm.delete('addDoubleLinear1', 'addDoubleLinear2',
                      'addDoubleLinear3', 'motionPath1_uValue')
            # connect motionPath allCoordinates node into the joint's translates
            pm.connectAttr('motionPath1.allCoordinates',
                           str(i) + '.translate',
                           force=True)
            # set driven keys for the anim curve driving the joints around the curve
            pm.setAttr('world_object_up.Tread_Cycle', 0)
            pm.setAttr('motionPath1.uValue', 0)
            pm.setDrivenKeyframe('motionPath1.uValue',
                                 currentDriver='world_object_up.Tread_Cycle')
            pm.setAttr('world_object_up.Tread_Cycle', curveMaxValue)
            pm.setAttr('motionPath1.uValue', curveMaxValue)
            pm.setDrivenKeyframe('motionPath1.uValue',
                                 currentDriver='world_object_up.Tread_Cycle')
            pm.selectKey('motionPath1.uValue')
            pm.keyTangent(itt='linear',
                          ott='linear')  # make them linear and cycle
            pm.setInfinity(pri='cycle', poi='cycle')
            pm.select(clear=True)
            pm.rename(
                'motionPath1_uValue', 'setDrivenKeys_anim_1'
            )  # rename it to something with number at the end, easier to work with if it's duplicated

            # for the rest of the joints:
        else:
            # constrain the joint to the curve using motion path animation
            pm.select(clear=True)
            pm.select(i)
            pm.select('treadCurve', add=True)
            pm.pathAnimation(fractionMode=False,
                             follow=True,
                             followAxis='y',
                             upAxis='z',
                             worldUpType='object',
                             worldUpObject='world_object_up',
                             inverseUp=True,
                             inverseFront=False,
                             bank=False)
            pm.select(clear=True)
            # delete useless nodes we're not gonna need
            pm.delete('addDoubleLinear1', 'addDoubleLinear2',
                      'addDoubleLinear3',
                      'motionPath' + str(treadJnts.index(i) + 1) + '_uValue')
            # connect motionPath allCoordinates node into joint's translates
            pm.connectAttr('motionPath' + str(treadJnts.index(i) + 1) +
                           '.allCoordinates',
                           str(i) + '.translate',
                           force=True)
            pm.select(clear=True)
            # duplicate the previous set driven keys anim curve
            pm.select('setDrivenKeys_anim_' + str(treadJnts.index(i)))
            pm.duplicate()
            pm.select(clear=True)
            # connect the new duplicated setDrivenKeys anim's output into the joint's motionPath's uValue
            pm.connectAttr('setDrivenKeys_anim_' +
                           str(treadJnts.index(i) + 1) + '.output',
                           'motionPath' + str(treadJnts.index(i) + 1) +
                           '.uValue',
                           force=True)
            # connect the animation curve to the Tread Cycle attribute
            pm.connectAttr('world_object_up.Tread_Cycle',
                           'setDrivenKeys_anim_' +
                           str(treadJnts.index(i) + 1) + '.input',
                           force=True)
            # shift the animation curve to the side so the treads won't be on top of each other and move accordingly
            pm.select('setDrivenKeys_anim_' + str(treadJnts.index(i) + 1))
            pm.selectKey()
            num = spaceInput.getValue1()  # get the spacing the user wants
            pm.keyframe(option='over', relative=True, floatChange=(num))
            pm.select(clear=True)