Пример #1
0
    def orientSkeletonTemplate():
        #First unparent the parts so we can orient properly
        hip = rigging.doParentToWorld('hip_l')
        heel = rigging.doParentToWorld('heel_l')
        clav = rigging.doParentToWorld('clavicle_l')
        palm = rigging.doParentToWorld('palm_l')

        spineChain = ['root']
        spineChain.extend(search.returnChildrenJoints('root'))
        for j in spineChain:
            joints.orientJoint(j, 'xzy', 'zup')

        hipChain = [hip]
        hipChain.extend(search.returnChildrenJoints(hip))
        for j in hipChain:
            #joints.orientJoint(j,'xzy','zup')
            joints.orientJoint(j, 'xzy', 'zup')

        armChain = [clav]
        armChain.extend(search.returnChildrenJoints(clav))
        for j in armChain:
            joints.orientJoint(j, 'xyz', 'yup')

        footChain = [heel]
        footChain.extend(search.returnChildrenJoints(heel))
        for j in footChain:
            #joints.orientJoint(j,'yzx','yup')
            #joints.orientJoint(j,'xyz','yup')
            joints.orientJoint(j, 'zyx', 'yup')

        handChain = [palm]
        handChain.extend(search.returnChildrenJoints(palm))
        for j in handChain:
            joints.orientJoint(j, 'xzy', 'zup')

        #Fix the thumb
        thumbChain = ['thumb1_l']
        thumbChain.extend(search.returnChildrenJoints('thumb1_l'))
        for j in thumbChain:
            #tweak - taken from Comet's orient
            mc.xform(j, r=True, os=True, ra=(-20, 0, 0))
            mc.joint(j, e=True, zso=True)
            mc.makeIdentity(j, apply=True)

        #Fix the Head
        headChain = ['head1']
        headChain.extend(search.returnChildrenJoints('head1'))
        for j in headChain:
            joints.orientJoint(j, 'yzx', 'zup')

        #Reconnect
        rigging.doParentReturnName(hip, 'root')
        rigging.doParentReturnName(clav, 'spine5')
        rigging.doParentReturnName(heel, 'ankle_l')
        rigging.doParentReturnName(palm, 'wrist_l')

        return spineChain
Пример #2
0
    def orientSkeletonTemplate():
	#First unparent the parts so we can orient properly
	hip = rigging.doParentToWorld('hip_l')
	heel = rigging.doParentToWorld('heel_l')
	clav = rigging.doParentToWorld('clavicle_l')
	palm = rigging.doParentToWorld('palm_l')
	
	spineChain = ['root']
	spineChain.extend(search.returnChildrenJoints('root'))
	for j in spineChain:        
	    joints.orientJoint(j,'xzy','zup')    
	
	hipChain = [hip]
	hipChain.extend(search.returnChildrenJoints(hip))
	for j in hipChain:
	    #joints.orientJoint(j,'xzy','zup')
	    joints.orientJoint(j,'xzy','zup')
	    
	armChain = [clav]
	armChain.extend(search.returnChildrenJoints(clav))
	for j in armChain:
	    joints.orientJoint(j,'xyz','yup')  
	    
	footChain = [heel]
	footChain.extend(search.returnChildrenJoints(heel))
	for j in footChain:
	    #joints.orientJoint(j,'yzx','yup') 
	    #joints.orientJoint(j,'xyz','yup')
	    joints.orientJoint(j,'zyx','yup')
	
	handChain = [palm]
	handChain.extend(search.returnChildrenJoints(palm))
	for j in handChain:
	    joints.orientJoint(j,'xzy','zup') 
		
	#Fix the thumb
	thumbChain = ['thumb1_l']
	thumbChain.extend(search.returnChildrenJoints('thumb1_l'))
	for j in thumbChain:
	    #tweak - taken from Comet's orient 
	    mc.xform(j,r=True,os=True,ra= (-20,0,0))
	    mc.joint(j,e=True,zso = True)
	    mc.makeIdentity(j,apply=True)
	    
	#Fix the Head
	headChain = ['head1']
	headChain.extend(search.returnChildrenJoints('head1'))
	for j in headChain:
	    joints.orientJoint(j,'yzx','zup') 	
	    
	#Reconnect
	rigging.doParentReturnName(hip,'root')
	rigging.doParentReturnName(clav,'spine5')
	rigging.doParentReturnName(heel,'ankle_l')
	rigging.doParentReturnName(palm,'wrist_l')
	
	return spineChain
Пример #3
0
    def doParent(self,p = False):
        """
        Function for parenting a maya instanced object while maintaining a correct object instance.

        Keyword arguments:
        p(string) -- Whether to run a full scene dictionary check or the faster just objExists check

        """ 
        assert self.transform,"'%s' has no transform"%obj	
        
        if p: #if we have a target parent
            try:
                #If we have an Object Factory instance, link it
                p.nameShort
                p = p.nameShort
            except:
                #If it fails, check that the object name exists and if so, initialize a new Object Factory instance
                assert mc.objExists(p) is True, "'%s' - parent object doesn't exist" %p     

            buffer = rigging.doParentReturnName(self.nameLong,p)
            
        else:#If not, do so to world
            buffer = rigging.doParentToWorld(self.nameLong)
            
        self.update(buffer)
Пример #4
0
    def checkGeo(self):
        """
        Check a puppet's geo that it is actually geo
        """
        assert self.msgGeoGroup.get() is not False, "No geo group found!"

        children = search.returnAllChildrenObjects(self.msgGeoGroup.get())
        if not children:
            return False

        for o in children:
            if search.returnObjectType(o) in geoTypes:
                buff = mc.ls(o, long=True)
                self.geo.append(buff[0])
            else:
                rigging.doParentToWorld(o)
                guiFactory.warning("'%s' isn't geo, removing from group." % o)
        return True
Пример #5
0
 def removeModule(self, moduleName):
     """
     Removes a module from a puppet
     
     module(string)
     """
     if moduleName in self.ModulesBuffer.bufferList:
         #Clear our instanced module
         index = self.ModulesBuffer.bufferList.index(moduleName)
         if index is not False:
             self.Module[index] = False
         self.ModulesBuffer.remove(moduleName)
         buffer = rigging.doParentToWorld(moduleName)
         self.getModules()
     else:
         guiFactory.warning(
             "'%s' doesn't seem to be a connected module. Cannot remove" %
             moduleName)
Пример #6
0
def removePolyUniteNode(polyUniteNode):
    rawDrivers = returnPolyUniteSourceShapes(polyUniteNode)

    if not mc.objExists(polyUniteNode):
        return guiFactory.warning('%s does not exist' %polyUniteNode)
    mc.delete(polyUniteNode)
    
    for obj in rawDrivers:
        if search.returnObjectType(obj) is 'shape':
            transform = mc.listRelatives (obj,parent=True, type ='transform')
            nameBuffer = mc.listRelatives (obj,parent=True, type ='transform')
            mc.setAttr((transform[0]+'.visibility'),1)
            mc.setAttr((obj+'.intermediateObject'),0)
            
            
            if not mc.referenceQuery(obj, isNodeReferenced=True):
                buffer = rigging.doParentToWorld(transform[0])
                mc.rename(buffer,nameBuffer[0])
Пример #7
0
def wrapDeformObject(targetObject,sourceObject,duplicateObject = False):
    """
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    DESCRIPTION:
    Function for baking a series of blendshapes from one object to another

    ARGUMENTS:
    targetObject(string)
    sourceObject(string)
    duplicateObject(bool) whether to duplicate the object or not

    RETURNS:
    returnList(list) - [wrapDeformer,wrappedTargetObject]
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """

    """ make a dup to bake """
    if duplicateObject == True:
        wrappedTargetObject = mc.duplicate(targetObject)
        wrappedTargetObject = rigging.doParentToWorld(wrappedTargetObject)
        wrappedTargetObject = mc.rename(wrappedTargetObject,(targetObject+'_baked'))

        """ Freeze """
        mc.makeIdentity(wrappedTargetObject,apply=True, t=True,r=True,s=True)
        mc.delete(wrappedTargetObject,ch=True)
    else:
        wrappedTargetObject = targetObject

    """ wrap deformer"""
    wrapDeformerBuffer = mc.deformer(wrappedTargetObject,type='wrap',n=(targetObject+'_wrapDeformer'))
    wrapDeformer = wrapDeformerBuffer[0]

    """ cause maya is stupid and doesn't have a python equivalent"""
    mc.select(wrappedTargetObject,r=True)
    mc.select(sourceObject,tgl=True)
    mel.eval('AddWrapInfluence')
    mc.select(cl=True)

    return ([wrapDeformer,wrappedTargetObject])
Пример #8
0
def rigSpine(moduleNull):
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    #>>>Get our info
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    partName = NameFactory.returnUniqueGeneratedName(moduleNull,
                                                     ignore='cgmType')
    """ template null """
    templateNull = modules.returnTemplateNull(moduleNull)
    templateNullData = attributes.returnUserAttrsToDict(templateNull)
    jointOrientation = modules.returnSettingsData('jointOrientation')
    templateRoot = modules.returnInfoNullObjects(moduleNull,
                                                 'templatePosObjects',
                                                 types='templateRoot')
    """ AutonameStuff """
    divider = NameFactory.returnCGMDivider()
    """ control helper objects """
    controlTemplateObjects = modules.returnInfoNullObjects(
        moduleNull, 'templateControlObjects', types='all')
    controlTemplateObjects = distance.returnDistanceSortedList(
        templateRoot, controlTemplateObjects)

    print 'controlTemplateObjects...'
    print controlTemplateObjects
    """size list of template control objects """
    controlTemplateObjectsSizes = []
    for obj in controlTemplateObjects:
        controlTemplateObjectsSizes.append(
            distance.returnAbsoluteSizeCurve(obj))
    print 'sizes...'
    print controlTemplateObjectsSizes
    """ Skin Joints """
    skinJoints = modules.returnInfoNullObjects(moduleNull,
                                               'skinJoints',
                                               types='all')
    skinJoints = distance.returnDistanceSortedList(templateRoot, skinJoints)
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    #>>> Make Controls
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """ control options """
    fk = templateNullData.get('fk')
    ik = templateNullData.get('ik')
    stretch = templateNullData.get('stretch')
    bend = templateNullData.get('bend')
    """controls to make """
    controlsToMake = []
    controlsToMake.append('cog')

    if fk == True:
        controlsToMake.append('segmentControls')
        controlsToMake.append('hips')

    if ik == True:
        controlsToMake.append('vectorHandles')
        controlsToMake.append('spineIKHandle')

    controlsDict = modules.limbControlMaker(moduleNull, controlsToMake)

    print controlsDict
    #>>> Organize em
    segmentControls = controlsDict.get('segmentControls')
    spineIKHandle = controlsDict.get('spineIKHandle')
    cog = controlsDict.get('cog')
    hips = controlsDict.get('hips')
    vectorHandles = controlsDict.get('vectorHandles')

    for handle in vectorHandles[-1:]:
        mc.delete(handle)
        vectorHandles.remove(handle)

    #>>> Parent em
    rigging.parentListToHeirarchy(segmentControls)
    mc.parent(spineIKHandle, segmentControls[-1])
    mc.parent(segmentControls[0], cog)
    mc.parent(hips, cog)

    for obj in segmentControls:
        rigging.zeroTransformMeObject(obj)
        mc.makeIdentity(obj, apply=True, translate=True)

    for obj in vectorHandles:
        mc.makeIdentity(obj, apply=True, translate=True)
    """ hips anchor locator """
    locBuffer = locators.locMeObject(hips)
    attributes.storeInfo(locBuffer, 'cgmName', hips)
    attributes.storeInfo(locBuffer, 'cgmTypeModifier', 'anchor')
    hipsAnchor = NameFactory.doNameObject(locBuffer)

    mc.setAttr((hipsAnchor + '.rotateOrder'), 5)

    pointConstraintBuffer = mc.pointConstraint(hips,
                                               hipsAnchor,
                                               maintainOffset=False,
                                               weight=1)
    orientConstraintBuffer = mc.orientConstraint(hips,
                                                 hipsAnchor,
                                                 maintainOffset=False,
                                                 skip=['x', 'y'],
                                                 weight=1)
    """ hips anchor group constraint """
    groupBuffer = rigging.groupMeObject(hipsAnchor)
    attributes.storeInfo(groupBuffer, 'cgmName', hipsAnchor)
    attributes.storeInfo(groupBuffer, 'cgmTypeModifier', 'orient')
    hipsAnchorOrGroup = NameFactory.doNameObject(groupBuffer)
    orientConstraintBuffer = mc.orientConstraint(segmentControls[0],
                                                 hipsAnchorOrGroup,
                                                 maintainOffset=False,
                                                 weight=1)
    """ end anchor locator """
    locBuffer = locators.locMeObject(segmentControls[-1])
    attributes.storeInfo(locBuffer, 'cgmName', segmentControls[-1])
    attributes.storeInfo(locBuffer, 'cgmTypeModifier', 'anchor')
    endAnchor = NameFactory.doNameObject(locBuffer)

    mc.setAttr((endAnchor + '.rotateOrder'), 5)

    mc.parent(endAnchor, spineIKHandle)

    #>>> set up follow chains
    constraintChain = []
    constraintChain.append(hipsAnchor)
    constraintChain = constraintChain + vectorHandles
    constraintChain.append(endAnchor)

    constraintChainReturn = constraints.doSegmentAimPointConstraint(
        constraintChain)
    print constraintChainReturn
    vectorHandlesZeroGroups = []
    for obj in vectorHandles:
        vectorHandlesZeroGroups.append(rigging.zeroTransformMeObject(obj))
    """ parent the last group to our IK handle """
    #mc.parent(vectorHandlesZeroGroups[-1],spineIKHandle)

    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    #>>> Joint Chains
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """ surface chain """
    dupJointsBuffer = mc.duplicate(skinJoints[:-1], po=True, rc=True)
    surfaceJoints = []
    for joint in dupJointsBuffer:
        attributes.storeInfo(joint, 'cgmType', 'surfaceJoint')
        surfaceJoints.append(NameFactory.doNameObject(joint))
    """ firm start """
    startJointsBuffer = mc.duplicate(skinJoints[0], po=True, rc=True)
    startJoints = []
    for joint in startJointsBuffer:
        attributes.storeInfo(joint, 'cgmType', 'deformationJoint')
        startJoints.append(NameFactory.doNameObject(joint))
    """ firm end """
    endJointsBuffer = mc.duplicate(skinJoints[-2:], po=True, rc=True)
    endJoints = []
    for joint in endJointsBuffer:
        attributes.storeInfo(joint, 'cgmType', 'deformationJoint')
        endJoints.append(NameFactory.doNameObject(joint))
    mc.parent(endJoints[0], world=True)

    #>>> Influence chain
    """
    get the root joints from our main chain searching by "cgmName" tags...maybe not the best way
    Maybe should change to search to closest joints
    """
    influenceJointsBuffer = []
    for obj in surfaceJoints:
        if (search.returnTagInfo(obj, 'cgmName')) != False:
            influenceJointsBuffer.append(obj)
    """ make our influence joints """
    influenceJoints = []
    for joint in influenceJointsBuffer:
        buffer = mc.duplicate(joint, po=True)
        closestObject = distance.returnClosestObject(buffer[0], surfaceJoints)
        attributes.storeInfo(buffer[0], 'cgmName', closestObject)
        attributes.storeInfo(buffer[0], 'cgmType', 'influenceJoint')
        rigging.doParentToWorld(buffer[0])
        influenceJoints.append(NameFactory.doNameObject(buffer[0]))

    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    #>>> Put our deformation joints in the rig
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    ############### need better way of doing this for iterative
    mc.parent(endJoints[0], spineIKHandle)
    mc.parent(startJoints[0], hips)
    mc.parent(influenceJoints[0], hipsAnchor)
    mc.parent(influenceJoints[1], vectorHandles[0])
    mc.parent(influenceJoints[2], spineIKHandle)
    #mc.parent(influenceJoints[3],spineIKHandle)

    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    #>>> Control Surface
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    """ create """
    orientationBuffer = list(jointOrientation)
    outChannel = orientationBuffer[2]
    upChannel = (orientationBuffer[1] + 'up')
    print upChannel

    surfaceBuffer = joints.loftSurfaceFromJointList(surfaceJoints, outChannel)
    controlSurface = surfaceBuffer[0]
    attributes.copyUserAttrs(moduleNull,
                             controlSurface,
                             attrsToCopy=['cgmName'])
    attributes.storeInfo(controlSurface, 'cgmType', 'controlSurface', True)
    controlSurface = NameFactory.doNameObject(controlSurface)
    """ connect joints to surface"""
    surfaceConnectReturn = joints.attachJointChainToSurface(
        surfaceJoints, controlSurface, jointOrientation, upChannel, 'animCrv')
    print surfaceConnectReturn
    """ surface influence joints skinning"""
    surfaceSkinCluster = mc.skinCluster(influenceJoints,
                                        controlSurface,
                                        tsb=True,
                                        n=(controlSurface + '_skinCluster'),
                                        maximumInfluences=3,
                                        normalizeWeights=1,
                                        dropoffRate=1)
    #surfaceSkinCluster = mc.skinCluster (influenceJoints,controlSurface,tsb=True, n=(controlSurface+'_skinCluster'),maximumInfluences = 3, normalizeWeights = 1, dropoffRate=1,smoothWeights=.5,obeyMaxInfluences=True, weight = 1)
    controlSurfaceSkinCluster = surfaceSkinCluster[0]
    """ smooth skin weights """
    skinning.simpleControlSurfaceSmoothWeights(controlSurface)

    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    #>>> Connect skin joints to surface joints
    #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    deformationJoints = []
    deformationJoints.append(startJoints[0])
    deformationJoints = deformationJoints + surfaceJoints[1:-2]
    deformationJoints = deformationJoints + endJoints
    for joint in skinJoints:
        attachJoint = distance.returnClosestObject(joint, deformationJoints)
        pntConstBuffer = mc.pointConstraint(attachJoint,
                                            joint,
                                            maintainOffset=False,
                                            weight=1)
        orConstBuffer = mc.orientConstraint(attachJoint,
                                            joint,
                                            maintainOffset=False,
                                            weight=1)
        #mc.connectAttr((attachJoint+'.t'),(joint+'.t'))
        #mc.connectAttr((attachJoint+'.r'),(joint+'.r'))
        mc.connectAttr((attachJoint + '.s'), (joint + '.s'))
        pntConstBuffer = mc.pointConstraint(attachJoint,
                                            joint,
                                            maintainOffset=False,
                                            weight=1)
        orConstBuffer = mc.orientConstraint(attachJoint,
                                            joint,
                                            maintainOffset=False,
                                            weight=1)