def addTangentMPTo(startMP, endMP, direction, default=0.5, reverse=False):
    '''
    add a "tangent" attribute to startLoc, and a tangentLoc to startLoc
    at 0, tangentLoc would be exactly on startLoc
    at 1, tangentLoc would be projected on direction vector onto endLoc's plane
    
    direction (string): 'x', 'y', or 'z'
    reverse (bool): reverse direction
    
    return tangentLoc
    '''
    # add tangentLoc
    tangentLoc = mc.spaceLocator(n=startMP+'_tangent_loc')[0]
    rt.parentSnap(tangentLoc, startMP)
    
    # add planeLoc - moves on plane of endMP, to help calculcate max distance
    planeLoc = mc.spaceLocator(n=endMP+'_plane_loc')[0]
    rt.parentSnap(planeLoc, endMP)
    
    # pointConstraint planeLoc to startMP
    # skip "direction" axis, to maintain sliding on endMP's plane
    mc.pointConstraint(startMP, planeLoc, skip=direction)
    
    # get distance between startMP and planeLoc
    # this is the maximum length for tangent
    maxDistance = cn.create_distanceBetween(startMP, planeLoc)
    
    # add "tangent" attribute to startMP
    mc.addAttr(startMP, ln='tangent', at='double', min=0, max=1, dv=default, k=True)
    
    # multiply tangent value by maxDistance
    tangentDistance = cn.create_multDoubleLinear(startMP+'.tangent', maxDistance)
    
    # reverse the direction if necessary
    if reverse:
        tangentDistance = cn.create_multDoubleLinear(tangentDistance, -1)
    
    # this will be used to drive the tangentLoc
    translatePlug = '%s.t%s' % (tangentLoc, direction)
    mc.connectAttr(tangentDistance, translatePlug, f=True)
    
    # connect locators for debug
    rt.connectVisibilityToggle((planeLoc, tangentLoc), startMP, 'debugTangentLocs', default=False)
    rt.connectVisibilityToggle(tangentLoc, startMP, 'tangentLoc', False)
    
    return tangentLoc
Exemple #2
0
def addProxyGeoToJnt(jnt, geo, child=None):
    """
    Parent-snaps geo under jnt
    If child=None, uses first child of jnt
    Distance between jnt & child drives scaleX (assuming X is downAxis)
    """
    geo = mc.duplicate(geo, n=jnt + "_proxy")[0]
    rt.parentSnap(geo, jnt)

    if not child:
        child = mc.listRelatives(jnt, c=True, type="joint")[0]

    # get distance between jnt and child

    dist = cn.create_distanceBetween(jnt, child)
    finalScale = cn.create_multiplyDivide(dist, jnt + ".scaleX", 2)
    mc.connectAttr(finalScale, geo + ".sx", f=True)

    return geo
def addProxyGeoToJnt(jnt, geo, child=None):
    '''
    Parent-snaps geo under jnt
    If child=None, uses first child of jnt
    Distance between jnt & child drives scaleX (assuming X is downAxis)
    '''
    geo = mc.duplicate(geo, n=jnt+'_proxy')[0]
    rt.parentSnap(geo, jnt)
    
    if not child:
        child = mc.listRelatives(jnt, c=True, type='joint')[0]
    
    # get distance between jnt and child
    
    dist = cn.create_distanceBetween(jnt, child)
    finalScale = cn.create_multiplyDivide(dist, jnt+'.scaleX', 2)
    mc.connectAttr(finalScale, geo+'.sx', f=True)
    
    return geo