def plasticConstraintsAndScaleFromObjectToTransform():
    selection = mc.ls(sl=True, flatten=True)
    for obj in selection:
        #Make a transform
        group = rigging.groupMeObject(obj,maintainParent = True)

        #Get scale connections
        objScaleConnections = []
        for s in 'sx','sy','sz':
            buffer =  attributes.returnDriverAttribute(obj+'.'+s)
            attributes.doBreakConnection(obj+'.'+s)
            attributes.doConnectAttr(buffer,(group+'.'+s))

        # Get constraint info from obj
        objConstraints = constraints.returnObjectConstraints(obj)

        for const in objConstraints:
            constraintTargets = constraints.returnConstraintTargets(const)
            mc.delete(const)

            mc.parentConstraint(constraintTargets,group, maintainOffset = True)
Beispiel #2
0
def plasticConstraintsAndScaleFromObjectToTransform():
    selection = mc.ls(sl=True, flatten=True)
    for obj in selection:
        #Make a transform
        group = rigging.groupMeObject(obj,maintainParent = True)

        #Get scale connections
        objScaleConnections = []
        for s in 'sx','sy','sz':
            buffer =  attributes.returnDriverAttribute(obj+'.'+s)
            attributes.doBreakConnection(obj+'.'+s)
            attributes.doConnectAttr(buffer,(group+'.'+s))

        # Get constraint info from obj
        objConstraints = constraints.returnObjectConstraints(obj)

        for const in objConstraints:
            constraintTargets = constraints.returnConstraintTargets(const)
            mc.delete(const)

            mc.parentConstraint(constraintTargets,group, maintainOffset = True)
Beispiel #3
0
def surfRigger(objectNull,anchor,worldScale,mirror,mode,jointsPerChain,deformChains,ctrlChains):
    """ Get variables"""
    nullBase = names.stripSuffixObj (objectNull)
    templateNull = (nullBase + '_templateNull')
    moverNull = (nullBase + '_mover')
    templateNullMessageData = []
    templateNullMessageData = attributes.returnMessageAttrs (templateNull)
    templateObjects = []
    coreNamesList = []
    spineJointNumber = int(mc.getAttr (objectNull+'.rollJoints'))
    #spineChainList = search.returnChildrenJoints (spineChain)
    spineChainList = []
    spineChainList.append (anchor)
    jointChains = []
    for set in templateNullMessageData:
        templateObjects.append (set[1])
        coreNamesList.append (set[0])
    #>>>>>>>>>>>>>>>>>>>>>Store skin joint data
    """ check for master skin info group """
    if mc.objExists ('master_skinJntList_grp'):
        masterSkinJointList = ('master_skinJntList_grp')
    else:
        masterSkinJointList = mc.group (n= ('master_skinJntList_grp'), w=True, empty=True)
        mc.parent(masterSkinJointList,'rigStuff_grp')
    """ check for segment skin info group """
    if mc.objExists (nullBase+'_skinJntList_grp'):
        skinJointListGrp = (nullBase+'_skinJntList_grp')
    else:
        skinJointListGrp = mc.group (n= (nullBase+'_skinJntList_grp'), w=True, empty=True)
    attributes.storeObjNameToMessage (skinJointListGrp,masterSkinJointList)
    mc.parent (skinJointListGrp,masterSkinJointList)
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """ Rebuild curve - with actual curve in it!"""
    mc.rebuildCurve ((templateObjects[3]), ch=0, rpo=1, rt=0, end=0, kr=0, kcp=0, kep=1, kt=0, s=jointsPerChain, d=1, tol=5)
    mc.rebuildCurve ((templateObjects[7]), ch=0, rpo=1, rt=0, end=0, kr=0, kcp=0, kep=1, kt=0, s=jointsPerChain, d=1, tol=5)
    mc.rebuildCurve ((templateObjects[11]), ch=0, rpo=1, rt=0, end=0, kr=0, kcp=0, kep=1, kt=0, s=jointsPerChain, d=1, tol=5)
    """ Reverse the curve """
    mc.reverseCurve ((templateObjects[3]),ch=False,rpo=True)
    mc.reverseCurve ((templateObjects[7]),ch=False,rpo=True)
    mc.reverseCurve ((templateObjects[11]),ch=False,rpo=True)
    """ loft our surface to figure out joint positions, then delete it"""
    controlSurface = mc.loft ([templateObjects[3],templateObjects[7],templateObjects[11]],name=(nullBase+'_surf'),ss=(ctrlChains-mode),ch=1,u=1,c=0,ar=1,d=3,rn=0,po=0,rsn=True)
    mc.select (cl=True)
    jointChains = joints.createJointChainsFromLoftSurface (nullBase,controlSurface[0],2,False)
    frontChain = jointChains[0]
    backChain = jointChains[-1]
    """ Chain - orienting, sizing """
    for chain in jointChains:
        joints.orientJointChain (chain, 'xyz', 'zup')
        joints.setGoodJointRadius(chain,.5)
    #IF we have mode 0, gotta make a main ctrl
    if mode == 0:
        midChain = []
        if (len(jointChains)) > 3:
            midChain = jointChains[int(len(jointChains)/2)]
        else:
            midChain = jointChains[1]
            jointChains.remove(midChain)
        if ctrlChains > 2:
            masterCtrlBuffer = mc.duplicate (midChain[0],parentOnly=True)
        else:
            masterCtrlBuffer = midChain[0]
            mc.delete (midChain[1])
        masterCtrl = mc.rename (masterCtrlBuffer,(nullBase+'_master_anim'))
        position.movePointSnap(masterCtrl,moverNull)
        """ temp parenting the master control for mirroring purposes """
        spineHookJoint = distance.returnClosestObject (masterCtrl, spineChainList)
        mc.parent (masterCtrl,spineHookJoint)
    mc.delete (controlSurface[0])
    #>>>>>>>>>>>>Parent time
    """ Get closest joint """
    if mode == 0:
        for chain in jointChains:
            mc.parent (chain[0],masterCtrl)
    else:
        for chain in jointChains:
            tailHookJoint = distance.returnClosestObject (chain[0], spineChainList)
            mc.parent (chain[0],tailHookJoint)
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>> Ctrl Joints to Ctrls
    cnt = 0
    for chain in jointChains:
        ctrlSize = (distance.returnAverageDistanceBetweenObjects (chain)/2)
        for jnt in chain[0:-1]:
            rigging.makeObjCtrl (jnt,ctrlSize)
        """ adds our Anim tag """
        chainBuffer = []
        chainBuffer = names.addSuffixList ('anim', chain)
        jointChains[cnt]= chainBuffer
        cnt +=1
    #>>>>>>>>>>>>>>>>>>>Mirroring while getting chain info
    """ If mirroring ...."""
    if mirror == True:
        # if we have a main control
        leftSkinChains = []
        rightSkinChains = []
        masterCtrls = []
        if mode == 0:
            leftChain = []
            rightChain = []
            finHeirarchy = []
            finHeirarchy.append (masterCtrl)
            children = search.returnChildrenJoints (masterCtrl)
            finHeirarchy += children
            leftChain = names.addPrefixList ('left',finHeirarchy)
            masterCtrl = leftChain [0]
            rightChainBuffer = mc.mirrorJoint (masterCtrl,mirrorYZ=True,mirrorBehavior=True, searchReplace =['left','right'])
            rightChainJointBuffer = mc.ls (rightChainBuffer,type='joint')
            rightChain = rightChainJointBuffer
            leftSkinChains.append(leftChain)
            rightSkinChains.append(rightChain)
            masterCtrls.append(leftChain[0])
            masterCtrls.append(rightChain[0])
        else:
            for chain in jointChains:
                leftChain =[]
                leftChain = names.addPrefixList ('left',chain)
                rightChainBuffer = (mc.mirrorJoint (leftChain[0],mirrorYZ=True,mirrorBehavior=True, searchReplace =['left','right']))
                rightChainJointBuffer = mc.ls (rightChainBuffer,type='joint')
                rightChain = rightChainJointBuffer
                rightSkinChains.append (rightChainJointBuffer)
                leftSkinChains.append (leftChain)
        """ complile our chains to lists of skin joints """
        leftSkinJointList=[]
        rightSkinJointList=[]
        for chain in leftSkinChains:
            for jnt in chain:
                leftSkinJointList.append (jnt)
        for chain in rightSkinChains:
            for jnt in chain:
                rightSkinJointList.append (jnt)
        """if we're not mirroring, let's return our skin joints for the deformation surface"""
    else:
        skinJointList = []
        skinChains = []
        for chain in jointChains:
            skinChains.append (chain)
            for jnt in chain:
                skinJointList.append (jnt)
                
    #>>>>>>>>>>>>>>>>>>>>>>>>>>Time to make the deformation surface stuff
    """ Rebuild curve - with actual curve in it!"""
    #mc.rebuildCurve ((templateObjects[3]), ch=0, rpo=1, rt=0, end=0, kr=0, kcp=0, kep=1, kt=0, s=(3), d=1, tol=5)
    #mc.rebuildCurve ((templateObjects[7]), ch=0, rpo=1, rt=0, end=0, kr=0, kcp=0, kep=1, kt=0, s=(3), d=1, tol=5)
    """ loft our surface to figure out joint positions, then delete it"""
    deformSurface = mc.loft ([templateObjects[3],templateObjects[7],templateObjects[11]],name=(nullBase+'_surf'),ss=(deformChains-1),ch=0,u=1,c=0,ar=1,d=3,rn=0,po=0,rsn=True)
    if mirror == True:
        deformSurfaceNameBuffer = deformSurface[0]
        """we have a surface to mirror..."""
        surfaceMirrorBuffer = mc.duplicate (deformSurface[0])
        mc.setAttr ((surfaceMirrorBuffer[0]+'.sx'),-1)
        leftBuffer = mc.rename (deformSurface[0],('left_'+deformSurfaceNameBuffer))
        rightBuffer = mc.rename (surfaceMirrorBuffer[0],('right_'+deformSurfaceNameBuffer))
        deformSurface[0]=leftBuffer
        deformSurface.append(rightBuffer)
        leftDeformJointChains = joints.createJointChainsFromLoftSurface (('left_'+nullBase),deformSurface[0],2,False)
        rightDeformJointChains = joints.createJointChainsFromLoftSurface (('right_'+nullBase),deformSurface[1],2,False)
        """ Connecting to surface """
        for chain in leftDeformJointChains:
            attachSurfaceReturn = joints.attachJointChainToSurface (chain,deformSurface[0],'xyz','zup')
            tailHookJoint = distance.returnClosestObject (chain[0], spineChainList)
            """ break the connection so we can parent it"""
            """first return the original thing to follow"""
            parentBuffer = attributes.returnDriverObject ((chain[0]+'.translate'))
            attributes.doBreakConnection (chain[0]+'.translate')
            #mc.parent (chain[0],tailHookJoint)
            """ reconstrain it to the driver"""
            constraintBuffer = mc.pointConstraint (parentBuffer,chain[0], maintainOffset = True)
            mc.rename (constraintBuffer[0],(chain[0]+'_pointConst'))
            """ store the skin joint data """
            for jnt in chain:
                attributes.storeObjNameToMessage (jnt,skinJointListGrp)

        for chain in rightDeformJointChains:
            attachSurfaceMirrorReturn = joints.attachJointChainToSurface (chain,deformSurface[1],'xyz','zup')
            tailHookJoint = distance.returnClosestObject (chain[0], spineChainList)
            """ break the connection s we can parent it"""
            """first return the original thing to follow"""
            parentBuffer = attributes.returnDriverObject ((chain[0]+'.translate'))
            attributes.doBreakConnection (chain[0]+'.translate')
            #mc.parent (chain[0],tailHookJoint)
            """ reconstrain it to the driver"""
            constraintBuffer = mc.pointConstraint (parentBuffer,chain[0], maintainOffset = True)
            mc.rename (constraintBuffer[0],(chain[0]+'_pointConst'))
            """ store the skin joint data """
            for jnt in chain:
                attributes.storeObjNameToMessage (jnt,skinJointListGrp)

        """ parent the scale stuff to rig stuff grp"""
        mc.select (cl=True)
        for item in attachSurfaceReturn[0]:
            mc.parent(item,'rigStuff_grp')
        for item in attachSurfaceMirrorReturn[0]:
            mc.parent(item,'rigStuff_grp')
        """ hook up world scale """
        mc.connectAttr (worldScale,attachSurfaceReturn[1])
        mc.connectAttr (worldScale,attachSurfaceMirrorReturn[1])
        #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Skin in the control joints
        """ Time to set skin our surface to our control joints """
        mc.skinCluster (leftSkinJointList,deformSurface[0],tsb=True, n=(deformSurface[0]+'_skinCluster'),maximumInfluences = 8, normalizeWeights = 1, dropoffRate=1,smoothWeights=.5,obeyMaxInfluences=True, weight = 1)
        mc.skinCluster (rightSkinJointList,deformSurface[1],tsb=True, n=(deformSurface[1]+'_skinCluster'),maximumInfluences = 8, normalizeWeights = 1, dropoffRate=1,smoothWeights=.5,obeyMaxInfluences=True, weight = 1)
    #>>>>>If we,re not mirrored, let's make our deform setup
    else:
        deformJointChains = []
        deformJointChains = joints.createJointChainsFromLoftSurface (nullBase,deformSurface[0],2,False)
        """ Connecting to surface """
        for chain in deformJointChains:
            attachSurfaceReturn = joints.attachJointChainToSurface (chain,deformSurface[0],'xyz','zup')
            tailHookJoint = distance.returnClosestObject (chain[0], spineChainList)
            """ break the connection so we can parent it"""
            """first return the original thing to follow"""
            parentBuffer = attributes.returnDriverObject ((chain[0]+'.translate'))
            attributes.doBreakConnection (chain[0]+'.translate')
            #mc.parent (chain[0],tailHookJoint)
            """ reconstrain it to the driver"""
            constraintBuffer = mc.pointConstraint (parentBuffer,chain[0], maintainOffset = True)
            mc.rename (constraintBuffer[0],(chain[0]+'_pointConst'))
            """ store the skin joint data """
            for jnt in chain:
                attributes.storeObjNameToMessage (jnt,skinJointListGrp)
        """ hook up world scale  """
        partScaleBuffer = attachSurfaceReturn[1]
        mc.connectAttr (worldScale, partScaleBuffer)
        """ parent the scale stuff to rig stuff grp"""
        mc.select (cl=True)
        for item in attachSurfaceReturn[0]:
            mc.parent(item,'rigStuff_grp')
        """ Time to set skin our surface to our control joints """
        mc.skinCluster (skinJointList,deformSurface[0],tsb=True, n=(deformSurface[0]+'_skinCluster'),maximumInfluences = 8, normalizeWeights = 1, dropoffRate=1,smoothWeights=.5,obeyMaxInfluences=True, weight = 1)
        
        
    """ Setting up the joint starts"""
    if mode == 0:
        if mirror == True:
            for ctrl in masterCtrls:
                rigging.makeObjCtrl (ctrl,(ctrlSize*4))
                masterCtrlGrp = rigging.groupMeObject (ctrl,True)
                """ Get closest joint and connect the Cntrl """
                spineHookJoint = distance.returnClosestObject (masterCtrlGrp, spineChainList)
                mc.parent(masterCtrlGrp,spineHookJoint)
        else:
            rigging.makeObjCtrl (masterCtrl,(ctrlSize*4))
            masterCtrlGrp = rigging.groupMeObject (masterCtrl,True)
            """ Get closest joint and connect the Cntrl """
            spineHookJoint = distance.returnClosestObject (masterCtrlGrp, spineChainList)
            mc.parent(masterCtrlGrp,spineHookJoint)
    #else we need to connect the individual chains to the spine
    else:
        if mirror == True:
            for chain in leftSkinChains:
                chainCtrlGrp = rigging.groupMeObject (chain[0],True)
                spineHookJoint = distance.returnClosestObject (chainCtrlGrp, spineChainList)
                mc.parent(chainCtrlGrp,spineHookJoint)
            for chain in rightSkinChains:
                chainCtrlGrp = rigging.groupMeObject (chain[0],True)
                spineHookJoint = distance.returnClosestObject (chainCtrlGrp, spineChainList)
                mc.parent(chainCtrlGrp,spineHookJoint)
        else:
            for chain in skinChains:
                chainCtrlGrp = rigging.groupMeObject (chain[0],True)
                spineHookJoint = distance.returnClosestObject (chainCtrlGrp, spineChainList)
                mc.parent(chainCtrlGrp,spineHookJoint)
Beispiel #4
0
def bakeBlendShapeNode(sourceObject, blendShapeNode, baseNameToUse = False, stripPrefix = False, ignoreInbetweens = False, ignoreTargets = False):
    """
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    DESCRIPTION:
    Function for exporting an object's blendshapes

    ARGUMENTS:
    targetObject(string)
    sourceObject(string)
    blendShapeNode(string) the node to bake from
    baseName(bool/string) - if it's False, it uses the target Object name, else, it uses what is supplied
    stripPrefix(bool) - whether to strip the first '_' segment
    ignoreInbetweens(bool)
    ignoreTargets(list) - targets to ignore in the processing

    RETURNS:
    Success(bool)
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Prep
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """ declare variables """
    returnList = []
    blendShapeNamesBaked = []
    blendShapeConnections = []
    currentConnections = []

    """ base name """
    if baseNameToUse == False:
        baseName = ''
    else:
        baseName = baseNameToUse + '_'


    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Meat of it
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    targetDict = returnBlendShapeTargetsAndWeights(sourceObject,blendShapeNode)
    targetSets = []
    blendShapeNodeChannels = []

    for key in targetDict.keys():
        targetSetBuffer = targetDict.get(key)
        targetSets.append(targetSetBuffer)

        baseSet = targetSetBuffer[-1]
        blendShapeNodeChannels.append(baseSet[0])

    blendShapeShortNames = []

    """ first loop gets connections, breaks them and sets everything to 0 """
    for shape in blendShapeNodeChannels:
        blendShapeBuffer = (blendShapeNode+'.'+shape)
        """ get the connection """
        blendShapeConnections.append(attributes.returnDriverAttribute(blendShapeBuffer))
        print blendShapeConnections
        """break it """
        attributes.doBreakConnection(blendShapeBuffer)
        attributes.doSetAttr(blendShapeBuffer,0)


    # Bake it
    bakedGeo = bakeBlendShapes(sourceObject, sourceObject, blendShapeNode, baseNameToUse, stripPrefix, ignoreInbetweens, ignoreTargets)


    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Finish out
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """ restore connections """
    for shape in blendShapeNodeChannels:
        currentIndex = blendShapeNodeChannels.index(shape)
        blendShapeBuffer = (blendShapeNode+'.'+shape)
        """ Restore the connection """
        if blendShapeConnections[currentIndex] != False:
            attributes.doConnectAttr(blendShapeConnections[currentIndex],blendShapeBuffer)

    """ group for geo """
    meshGroup = mc.group( em=True)
    if baseNameToUse != False:
        attributes.storeInfo(meshGroup,'cgmName', baseNameToUse)
    attributes.storeInfo(meshGroup,'cgmTypeModifier', 'blendShapeGeo')
    meshGroup = NameFactory.doNameObject(meshGroup)

    for geo in bakedGeo:
        rigging.doParentReturnName(geo,meshGroup)

    returnList.append(meshGroup)
    returnList.append(bakedGeo)

    return returnList
Beispiel #5
0
def bakeCombinedBlendShapeNode(sourceObject, blendShapeNode, baseNameToUse = False, directions=['left','right']):
    """
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    DESCRIPTION:
    Function for baking a series of blendshapes out from one object that have a split type

    ARGUMENTS:
    sourceObject(string)
    sourceObject(string)
    blendShapeNode(string) the node to bake from
    baseName(bool/string) - if it's False, it uses the target Object name, else, it uses what is supplied
    directions[list] = (['left','right'])

    RETURNS:
    Success(bool)
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Prep
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """ declare variables """
    returnList = []
    blendShapeNamesBaked = []
    blendShapeConnections = []
    currentConnections = []
    bakedGeo = []

    """ size """
    sizeBuffer = distance.returnBoundingBoxSize(sourceObject)
    sizeX = sizeBuffer[0]
    sizeY = sizeBuffer[1]

    """ base name """
    if baseNameToUse == False:
        baseName = ''
    else:
        baseName = baseNameToUse + '_'


    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Meat of it
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    blendShapeNodeChannels = search.returnBlendShapeAttributes(blendShapeNode)
    blendShapeShortNames = []

    """ first loop stores and sets everything to 0 """
    for shape in blendShapeNodeChannels:
        blendShapeBuffer = (blendShapeNode+'.'+shape)
        blendShapeConnections.append(attributes.returnDriverAttribute(blendShapeBuffer))
        """break it """
        attributes.doBreakConnection(blendShapeBuffer)
        attributes.doSetAttr(blendShapeBuffer,0)

    """ Find pairs """
    blendshapePairs = lists.returnMatchedStrippedEndList(blendShapeNodeChannels,directions)

    """ first loop stores and sets everything to 0 """
    for pair in blendshapePairs:
        blendShapeBuffer = (blendShapeNode+'.'+pair[0])
        splitBuffer = pair[0].split('_')
        nameBuffer = splitBuffer[:-1]
        pairBaseName = '_'.join(nameBuffer)

        if '_' in list(pairBaseName):
            newSplitBuffer = pair[0].split('_')
            newNameBuffer = newSplitBuffer[1:]
            blendShapeShortNames.append('_'.join(newNameBuffer))
        else:
            blendShapeShortNames.append(pairBaseName)

    t=1
    pair = 0
    for i in range (len(blendshapePairs)):
        row = i//5
        if t>5:
            t=1
        """ start extracting """
        blendShapeNodeChannelsBuffer = blendshapePairs[pair]
        shape1 = blendShapeNodeChannelsBuffer[0]
        shape2 = blendShapeNodeChannelsBuffer[1]
        blendShape1Buffer = (blendShapeNode+'.'+shape1)
        blendShape2Buffer = (blendShapeNode+'.'+shape2)
        attributes.doSetAttr(blendShape1Buffer,1)
        attributes.doSetAttr(blendShape2Buffer,1)
        dupBuffer = mc.duplicate(sourceObject)


        splitBuffer = blendShapeShortNames[pair].split('_')
        if len(splitBuffer)>1:
            nameBuffer = splitBuffer[:-1]
        else:
            nameBuffer = splitBuffer
        shortName = '_'.join(nameBuffer)

        dupBuffer = mc.rename (dupBuffer,(baseName+shortName))
        """ Unlock it """
        attributes.doSetLockHideKeyableAttr(dupBuffer,False,True,True)

        mc.xform(dupBuffer,r=True,t=[((sizeX*(t+1.2))*1.5),(sizeY*row*-1.5),0])
        bakedGeo.append(dupBuffer)

        attributes.doSetAttr(blendShape1Buffer,0)
        attributes.doSetAttr(blendShape2Buffer,0)
        pair +=1
        t+=1

    """ restore connections """
    for shape in blendShapeNodeChannels:
        currentIndex = blendShapeNodeChannels.index(shape)
        blendShapeBuffer = (blendShapeNode+'.'+shape)
        """ Restore the connection """
        if blendShapeConnections[currentIndex] != False:
            attributes.doConnectAttr(blendShapeConnections[currentIndex],blendShapeBuffer)


    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Finish out
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """ group for geo """
    meshGroup = mc.group( em=True)
    attributes.storeInfo(meshGroup,'cgmName', baseNameToUse)
    attributes.storeInfo(meshGroup,'cgmTypeModifier', 'blendShapeGeo')
    meshGroup = NameFactory.doNameObject(meshGroup)

    for geo in bakedGeo:
        rigging.doParentReturnName(geo,meshGroup)

    returnList.append(meshGroup)
    returnList.append(bakedGeo)

    return returnList
Beispiel #6
0
def bakeCombinedBlendShapeNodeToTargetObject(targetObject,sourceObject, blendShapeNode, baseName = False, directions=['left','right']):
    """
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    DESCRIPTION:
    Function for baking a series of blendshapes from one object to another when you have a left/right variant

    ARGUMENTS:
    targetObject(string)
    sourceObject(string)
    blendShapeNode(string) the node to bake from
    baseName(bool/string) - if it's False, it uses the target Object name, else, it uses what is supplied
    directions[list] = (['left','right'])

    RETURNS:
    Success(bool)
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Prep
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """ declare variables """
    returnList = []
    blendShapeNamesBaked = []
    blendShapeConnections = []
    currentConnections = []
    bakedGeo = []

    """ size """
    sizeBuffer = distance.returnBoundingBoxSize(targetObject)
    sizeX = sizeBuffer[0]
    sizeY = sizeBuffer[1]

    """ base name """
    if baseName == False:
        baseName = ''
    else:
        baseName = baseName + '_'

    """reference check """
    refPrefix = search.returnReferencePrefix(sourceObject)
    if refPrefix != False:
        referencePrefix = (search.returnReferencePrefix(sourceObject) + ':')
    else:
        referencePrefix = ''

    """ wrap deform object """
    wrapBuffer = wrapDeformObject(targetObject,sourceObject,True)
    targetObjectBaked = wrapBuffer[1]

    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Meat of it
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    #setAttr ($wrapDeformer[0] + ".autoWeightThreshold") 1;
    """ cause maya is stupid and doesn't have a python equivalent"""
    mc.select(targetObjectBaked,r=True)
    mc.select(sourceObject,tgl=True)
    mel.eval('AddWrapInfluence')
    mc.select(cl=True)

    """
    may need to add this in later
    //reorders deformation order for proper baking of skinned mesh
    //reorderDeformers "tweak1" "face_skinCluster" $deformerGeo;
    """

    blendShapeNodeChannels = search.returnBlendShapeAttributes(blendShapeNode)
    blendShapeShortNames = []

    """ first loop stores and sets everything to 0 """
    for shape in blendShapeNodeChannels:
        blendShapeBuffer = (blendShapeNode+'.'+shape)
        blendShapeConnections.append(attributes.returnDriverAttribute(blendShapeBuffer))
        """break it """
        attributes.doBreakConnection(blendShapeBuffer)
        attributes.doSetAttr(blendShapeNode,shape,0)

    """ Find pairs """
    blendshapePairs = lists.returnMatchedStrippedEndList(blendShapeNodeChannels,directions)

    """ first loop stores and sets everything to 0 """
    for pair in blendshapePairs:
        blendShapeBuffer = (blendShapeNode+'.'+pair[0])
        splitBuffer = pair[0].split('_')
        nameBuffer = splitBuffer[:-1]
        pairBaseName = '_'.join(nameBuffer)

        if '_' in list(pairBaseName):
            newSplitBuffer = pair[0].split('_')
            newNameBuffer = newSplitBuffer[1:]
            blendShapeShortNames.append('_'.join(newNameBuffer))
        else:
            blendShapeShortNames.append(pairBaseName)

    t=1
    pair = 0
    for i in range (len(blendshapePairs)):
        row = i//5
        if t>5:
            t=1
        """ start extracting """
        blendShapeNodeChannelsBuffer = blendshapePairs[pair]
        shape1 = blendShapeNodeChannelsBuffer[0]
        shape2 = blendShapeNodeChannelsBuffer[1]
        attributes.doSetAttr(blendShapeNode,shape1,1)
        attributes.doSetAttr(blendShapeNode,shape2,1)
        dupBuffer = mc.duplicate(targetObjectBaked)
        splitBuffer = blendShapeShortNames[pair].split('_')
        nameBuffer = splitBuffer[:-1]
        shortName = '_'.join(nameBuffer)

        dupBuffer = mc.rename (dupBuffer,(baseName+shortName))
        mc.xform(dupBuffer,r=True,t=[((sizeX*(t+1.2))*1.5),(sizeY*row*-1.5),0])
        bakedGeo.append(dupBuffer)

        attributes.doSetAttr(blendShapeNode,shape1,0)
        attributes.doSetAttr(blendShapeNode,shape2,0)
        pair +=1
        t+=1

    """ restore connections """
    for shape in blendShapeNodeChannels:
        currentIndex = blendShapeNodeChannels.index(shape)
        blendShapeBuffer = (blendShapeNode+'.'+shape)
        """ Restore the connection """
        if blendShapeConnections[currentIndex] != False:
            attributes.doConnectAttr(blendShapeConnections[currentIndex],blendShapeBuffer)

    """delete the wrap"""
    mc.delete(wrapBuffer[0])

    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Finish out
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """ group for geo """
    meshGroup = mc.group( em=True)
    attributes.storeInfo(meshGroup,'cgmName', baseName)
    attributes.storeInfo(meshGroup,'cgmTypeModifier', 'blendShapeGeo')
    meshGroup = NameFactory.doNameObject(meshGroup)

    for geo in bakedGeo:
        rigging.doParentReturnName(geo,meshGroup)

    returnList.append(meshGroup)
    returnList.append(bakedGeo)

    mc.delete(targetObjectBaked)
    return returnList
Beispiel #7
0
def bakeBlendShapeNodeToTargetObject(targetObject,sourceObject, blendShapeNode, baseNameToUse = False, stripPrefix = False,ignoreInbetweens = False, ignoreTargets = False, transferConnections = True):
    """
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    DESCRIPTION:
    Function for baking a series of blendshapes from one object to another

    ARGUMENTS:
    targetObject(string)
    sourceObject(string)
    blendShapeNode(string) the node to bake from
    baseNameToUse(bool/string) - if it's False, it uses the target Object name, else, it uses what is supplied
    stripPrefix(bool)
    ignoreInbetweens(bool)
    ignoreTargets(list) - list of targets to ignore
    transferConnections(bool) - if True, builds a new blendshape node and transfers the connections from our base objects

    RETURNS:
    Success(bool)
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Prep
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """ declare variables """
    returnList = []
    blendShapeNamesBaked = []
    blendShapeConnections = []
    currentConnections = []
    bakedGeo = []

    """ size """
    sizeBuffer = distance.returnBoundingBoxSize(targetObject)
    sizeX = sizeBuffer[0]
    sizeY = sizeBuffer[1]

    """ base name """
    if baseNameToUse == False:
        baseName = ''
    else:
        baseName = baseNameToUse + '_'

    """ wrap deform object """
    wrapBuffer = wrapDeformObject(targetObject,sourceObject,True)
    targetObjectBaked = wrapBuffer[1]

    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Meat of it
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    blendShapeNodeChannels = returnBlendShapeAttributes(blendShapeNode)

    blendShapeShortNames = []
    """ first loop stores and sets everything to 0 """

    for shape in blendShapeNodeChannels:
        keepGoing = True
        if ignoreTargets != False:
            if shape in ignoreTargets:
                keepGoing = False
            else:
                keepGoing = True

        blendShapeBuffer = (blendShapeNode + '.' + shape)
        """ get the connection """
        blendShapeConnections.append(attributes.returnDriverAttribute(blendShapeBuffer))

        if keepGoing == True:
            print ('breaking....' + blendShapeBuffer)
            """break it """
            attributes.doBreakConnection(blendShapeBuffer)
            attributes.doSetAttr(blendShapeNode,shape,0)

    # Bake it
    bakedGeo = bakeBlendShapes(sourceObject, targetObjectBaked, blendShapeNode, baseNameToUse, stripPrefix, ignoreInbetweens, ignoreTargets)


    """ restore connections """
    for shape in blendShapeNodeChannels:
        keepGoing = True
        if ignoreTargets != False:
            if shape in ignoreTargets:
                keepGoing = False
            else:
                keepGoing = True

        currentIndex = blendShapeNodeChannels.index(shape)
        blendShapeBuffer = (blendShapeNode+'.'+shape)
        """ Restore the connection """
        if keepGoing == True:
            print ('connecting....' + blendShapeBuffer)
            print blendShapeConnections[currentIndex]
            if blendShapeConnections[currentIndex] != False:
                attributes.doConnectAttr(blendShapeConnections[currentIndex],blendShapeBuffer)


    # Need to build a new blendshape node?
    if transferConnections == True:
        # Build it
        newBlendShapeNode = buildBlendShapeNode(targetObject, bakedGeo, baseNameToUse)

        newBlendShapeChannels = returnBlendShapeAttributes(newBlendShapeNode)

        for shape in newBlendShapeChannels:
            blendShapeBuffer = (newBlendShapeNode+'.'+shape)
            currentIndex = newBlendShapeChannels.index(shape)
            if blendShapeConnections[currentIndex] != False:
                attributes.doConnectAttr(blendShapeConnections[currentIndex],blendShapeBuffer)

    """delete the wrap"""
    mc.delete(wrapBuffer[0])

    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Finish out
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """ group for geo """
    meshGroup = mc.group( em=True)
    if baseNameToUse != False:
        attributes.storeInfo(meshGroup,'cgmName', baseNameToUse)
    attributes.storeInfo(meshGroup,'cgmTypeModifier', 'blendShapeGeo')
    meshGroup = NameFactory.doNameObject(meshGroup)

    for geo in bakedGeo:
        rigging.doParentReturnName(geo,meshGroup)

    returnList.append(meshGroup)
    returnList.append(bakedGeo)

    mc.delete(targetObjectBaked)
    return returnList
m1 = r9Meta.MetaClass('l_ring_part')
m1 = r9Meta.MetaClass('l_thumb_part')
m1 = r9Meta.MetaClass('l_pinky_part')
for m in [
        'r_index_part', 'r_middle_part', 'r_ring_part', 'r_thumb_part',
        'r_pinky_part'
]:
    m1 = r9Meta.MetaClass(m).doRig()
for m in [
        'l_index_part', 'l_middle_part', 'l_ring_part', 'l_thumb_part',
        'l_pinky_part'
]:
    m1 = r9Meta.MetaClass(m).doRig()
reload(rigging)
from cgm.lib import attributes
attributes.doBreakConnection('l_wrist_fk_anim', 'inverseScale')
i_rig.buildModule.__build__(i_rig)
m1.rigConnect()
m1.rig_getReport()
i_rig = Rig.go(m1, forceNew=False, autoBuild=False)  #call to do general rig
m1.setState('skeleton', forceNew=True)
m1.doRig()
i_rig = Rig.go(m1, forceNew=False)  #call to do general rig
m1.templateNull.handles
reload(Rig)
range(4, 5)
cgmMeta.validateAttrArg([i_rig._i_rigNull.controlIK, 'length'],
                        noneValid=False)
m1.rigNull.controlIK.select()
i_rig.build(i_rig, buildTo='')
i_rig.build(i_rig, buildTo='skeleton')