Exemplo n.º 1
0
def setupFkCtls(bndJnts, rigCtls, descriptions, namer):
    """Set up fk controls from bndJnts.

    This will delete the original controls passed in and
    rebuild the control shapes on a duplicate of the bind joints passed in
    Zero nodes will be placed above the controls, so the control matrices will
    equal identiy

    @param bndJnts: the joints to duplicate as fk controls
    @param rigCtls: the controls that will be deleted and have their shapes reparented
    @param descriptions: names for the new controls

    @param namer: a Namer object used to rename the new joints (const)

    @return: list of new joint controls
    """

    if len(bndJnts) != len(rigCtls):
        raise RuntimeError("bind joint length must match rig ctls")
    if len(bndJnts) != len(descriptions):
        raise RuntimeError("bind joint length must match rig descriptions")

    fkCtls = []
    rebuildData = getStorableXformRebuildData(inNodeList = bndJnts)

    substitutions = []
    for i in range(len(rigCtls)):
        #get the position offsets for the new control data
        setEditable(rigCtls[i], True)
        editor = getEditor(rigCtls[i])
        MC.parent(editor, world=1)
        utils.snap(bndJnts[i], rigCtls[i])
        MC.parent(editor, rigCtls[i])
        ctlInfo = getInfo(rigCtls[i])
        rebuildData[bndJnts[i]]['controlArgs'] = ctlInfo

        #get name substituions for the new joints
        newName = namer(descriptions[i], r='fk')
        substitutions.append((bndJnts[i], newName))

        fkCtls.append(newName)

    MC.delete(rigCtls)
    rebuildData = substituteInData(rebuildData, *substitutions)
    makeStorableXformsFromData(rebuildData)

    for ctl in fkCtls:

        att = utils.insertNodeAbove(ctl)
        for node in [ctl, att]:
            MC.setAttr('%s.drawStyle' % node, 2)
    return fkCtls