Ejemplo n.º 1
0
    def acceptWindow(self, targetObject, enumIndex, *args):
        spaceName = cmds.textField(self.UIElements["spaceName"],
                                   q=True,
                                   text=True)
        maintainOffset = cmds.checkBox(
            self.UIElements["maintainOffset_checkBox"], q=True, value=True)
        setKeyframes = cmds.checkBox(self.UIElements["setKeyframes_checkBox"],
                                     q=True,
                                     value=True)

        cmds.deleteUI(self.UIElements["window"])

        animModuleNamespace = utils.stripAllNamespaces(self.controlObject)[0]
        blueprintModuleNamespace = utils.stripAllNamespaces(
            animModuleNamespace)[0]
        characterNamespace = utils.stripAllNamespaces(
            blueprintModuleNamespace)[0]

        containers = (characterNamespace + ":character_container",
                      blueprintModuleNamespace + ":module_container",
                      animModuleNamespace + ":module_container")

        for c in containers:
            cmds.lockNode(c, lock=False, lockUnpublished=False)

        self.switchSpace(targetObject,
                         spaceName,
                         index=enumIndex,
                         maintainOffset=maintainOffset,
                         setKeyframes=setKeyframes)

        for c in containers:
            cmds.lockNode(c, lock=True, lockUnpublished=True)

        cmds.select(self.controlObject, replace=True)
 def createDistanceCalculations(self, rootLocator, endLocator, containedNodes):
     rootLocatorName = utils.stripAllNamespaces(rootLocator)[1]
     endLocatorName = utils.stripAllNamespaces(endLocator)[1]
     distNode = cmds.shadingNode("distanceBetween", asUtility=True, n=self.blueprintNamespace+":"+self.moduleNamespace+":distanceBetween_" + rootLocatorName + "__" + endLocatorName)
     containedNodes.append(distNode)
     
     rootLocShape = rootLocator+"Shape"
     endLocShape = endLocator+"Shape"
     
     cmds.connectAttr(rootLocShape+".worldPosition[0]", distNode+".point1")
     cmds.connectAttr(endLocShape+".worldPosition[0]", distNode+".point2")
     
     totalOriginalLength = cmds.getAttr(distNode+".distance")
     totalOriginalLength /= cmds.getAttr(self.blueprintNamespace+":module_grp.hierarchicalScale")
     
     scaleFactor = cmds.shadingNode("multiplyDivide", asUtility=True, n=distNode+"_scaleFactor")
     containedNodes.append(scaleFactor)
     
     cmds.setAttr(scaleFactor+".operation", 2) # Divide
     cmds.connectAttr(distNode+".distance", scaleFactor+".input1X")
     cmds.setAttr(scaleFactor+".input2X", totalOriginalLength)
     
     scaleCorrection = cmds.shadingNode("multiplyDivide", asUtility=True, n=scaleFactor+"_correction")
     containedNodes.append(scaleCorrection)
     
     cmds.setAttr(scaleCorrection+".operation", 2) #Divide
     cmds.connectAttr(scaleFactor+".outputX", scaleCorrection+".input1X")
     cmds.connectAttr(self.blueprintNamespace+":module_grp.hierarchicalScale", scaleCorrection+".input2X")
     
     return scaleCorrection+".outputX"
	def createPreferredAngleRepresentation(self,joint,scaleTarget, childOfOrientationControl=False):
		paRepresentationFile = os.environ['RIGGING_TOOL_ROOT'] + '/ControlObjects/Blueprint/preferredAngle_representation.ma'
		cmds.file(paRepresentationFile, i=True)
		
		container = cmds.rename('preferredAngle_representation_container', joint + '_preferredAngle_representation_container')
		utils.addNodeToContainer(self.containerName, container)
		
		for node in cmds.container(container, q=True, nodeList=True):
			cmds.rename(node, joint + '_' + node, ignoreShape=True)
			
		control = joint + '_preferredAngle_representation'
		controlName = utils.stripAllNamespaces(control)[1]
		cmds.container(self.containerName,edit=True, publishAndBind=[container + '.axis' , controlName + '_axis'])
		
		controlGroup = cmds.group(control, n=joint + '_preferredAngle_parentConstraintGrp',absolute=True)
		containedNodes = [controlGroup]
		
		cmds.parent(controlGroup, self.preferredAngleRepresentationGrp, absolute=True)
		
		containedNodes.append(cmds.parentConstraint(joint, controlGroup, maintainOffset=False)[0])
		
		if childOfOrientationControl:
			rotateXGrp = cmds.group(control, n=control + '_rotateX_grp', absolute=True)
			orientationControl = self.getOrientationControl(joint)
			cmds.connectAttr(orientationControl + '.rotateX', rotateXGrp + '.rotateX')
			
			containedNodes.append(rotateXGrp)
			
		containedNodes.append(cmds.scaleConstraint(scaleTarget, controlGroup, maintainOffset=False)[0])
		
		utils.addNodeToContainer(container, containedNodes)
		
		return control
Ejemplo n.º 4
0
    def setupSpaceSwitching(self, blueprintModuleNamespace,
                            animationModuleNamespace, animationModuleInstance):
        cmds.select(self.controlObject, replace=True)
        # Do we have spaceswitching and is it orientation only
        cmds.addAttr(at="bool",
                     defaultValue=True,
                     keyable=False,
                     longName="spaceSwitching")
        cmds.addAttr(at="bool",
                     defaultValue=False,
                     keyable=False,
                     longName="switchOrientationOnly")

        spaceSwitcher = cmds.group(empty=True,
                                   name=self.controlObject + "_spaceSwitcher")

        if self.translation != [True, True, True]:
            cmds.setAttr(self.controlObject + ".switchOrientationOnly", True)

        cmds.parent(self.rootParent, spaceSwitcher, absolute=True)
        self.rootParent = spaceSwitcher

        utils.addNodeToContainer(
            animationModuleNamespace + ":module_container", spaceSwitcher)

        self.switchSpace(blueprintModuleNamespace + ":HOOK_IN", "Module Hook")

        controlObjectName = utils.stripAllNamespaces(self.controlObject)[1]
        animationModuleInstance.publishNameToModuleContainer(
            spaceSwitcher + ".currentSpace",
            controlObjectName + "_currentSpace",
            publishToOuterContainers=True)
Ejemplo n.º 5
0
    def initFKControl(self, joint, spaceSwitchable=False):
        translationControl = False
        jointName = utils.stripAllNamespaces(joint)[1]
        blueprintJoint = self.blueprintNamespace + ":blueprint_" + jointName

        if cmds.objExists(blueprintJoint + "_addTranslate"):
            translationControl = True

        name = jointName + "_fkControl"

        controlObjectInstance = controlObject.ControlObject()

        fkControlInfo = controlObjectInstance.create(
            name,
            "fourArrowControl.ma",
            self,
            lod=1,
            translation=translationControl,
            rotation=True,
            globalScale=False,
            spaceSwitching=spaceSwitchable)
        fkControl = fkControlInfo[0]

        cmds.connectAttr(joint + ".rotateOrder", fkControl + ".rotateOrder")

        return (fkControlInfo[0], fkControlInfo[1], translationControl)
Ejemplo n.º 6
0
	def createFKControl(self, joint, parent, moduleContainer):
		jointName = utils.stripAllNamespaces(joint)[1]
		containedNodes = []
		name = jointName + "_fkControl"
		
		fkControl = cmds.sphere(n=joint+ "_fkControl")[0]
		utils.addNodeToContainer(moduleContainer, fkControl, ihb=True)
		self.publishNameToModuleContainer(fkControl+".rotate", name+"_R", publishToOuterContainers=True)
		
		cmds.connectAttr(joint+".rotateOrder", fkControl+".roatateOrder")
		
		orientGrp = cmds.group(n=fkControl+"_orientGrp", empty=True, parent=parent)
		containedNodes.append(orientGrp)
		
		orientGrp_parentConstraint = cmds.parentConstraint(joint, orientGrp, maintainOffset=False)[0]
		cmds.delete(orientGrp_parentConstraint)
		
		jointParent = cmds.listRelatives(joint, parent=True)[0]
		
		orientGrp_parentConstraint = cmds.parentConstraint(jointParent, orientGrp, maintainOffset=True, n=orientGrp+"_parentConsraint")[0]
		orientGrp_scaleConstraint = cmds.scaleConstraint(jointParent, orientGrp, maintainOffset=True, n=orientGrp+"_scaleConsraint")[0]
		
		containedNodes.extend(orientGrp_parentConstraint, orientGrp_scaleConstraint)
		
		cmds.parent(fkControl, orientGrp, relative=True)
		
		orientContstraint = cmds.orientConstraint(fkControl, joint, maintainOffset=False, n=joint+"_orientConstraint")[0]
		containedNodes.append(orientConstraint)
		
		utils.addNodeToContainer(moduleContainer, containedNodes)
		
		return fkControl
Ejemplo n.º 7
0
    def lock_phase1(self): #109
        moduleInfo=hingeJoint.HingeJoint.lock_phase1(self)
        jointPositions=moduleInfo[0]
        jointOrientationValues=moduleInfo[1][0]
        jointRotationOrders=moduleInfo[2]

        joints=self.getJoints()
        for i in range(3, 5):
            joint=joints[i]
            jointPositions.append(cmds.xform(joint, q=True, worldSpace=True, translation=True))
            jointRotationOrders.append(cmds.getAttr(joint+".rotateOrder"))

        cmds.lockNode(self.containerName, lock=False, lockUnpublished=False)

        jointNameInfo=utils.stripAllNamespaces(joints[1])
        cleanParent=jointNameInfo[0]+":IK_"+jointNameInfo[1]
        deleteJoints=[]
        for i in range(2,4):
            orientationInfo=self.orientationControlledJoint_getOrientation(joints[i], cleanParent)
            jointOrientationValues.append(orientationInfo[0])
            cleanParent=orientationInfo[1]
            deleteJoints.append(cleanParent)
        cmds.delete(deleteJoints)
        cmds.lockNode(self.containerName, lock=True, lockUnpublished=True)

        return moduleInfo
Ejemplo n.º 8
0
 def refreshAnimationModuleList(self, index=1):
     cmds.textScrollList(self.UIElements["animationModule_textScroll"], edit=True, removeAll=True)
     
     cmds.symbolButton(self.UIElements["deleteModuleButton"], edit=True, enable=False)
     cmds.symbolButton(self.UIElements["duplicateModuleButton"], edit=True, enable=False)
     
     selectedBlprnModule = cmds.textScrollList(self.UIElements["blueprintModule_textScroll"], q=True, selectItem=True)
     self.selectedBlueprintModule = self.blueprintModules[selectedBlprnModule[0]]
     
     self.setupActiveModuleControls()
     
     cmds.namespace(setNamespace=self.selectedBlueprintModule)
     controlModuleNamespaces = cmds.namespaceInfo(listOnlyNamespaces=True)
     cmds.namespace(setNamespace=":")
     
     if controlModuleNamespaces != None:
         for module in controlModuleNamespaces:
             moduleName = utils.stripAllNamespaces(module)[1]
             cmds.textScrollList(self.UIElements["animationModule_textScroll"], edit=True, append=moduleName)
             
         cmds.textScrollList(self.UIElements["animationModule_textScroll"], edit=True, selectIndexedItem = index)
         
         cmds.symbolButton(self.UIElements["deleteModuleButton"], edit=True, enable=True)
         cmds.symbolButton(self.UIElements["duplicateModuleButton"], edit=True, enable=True)
         cmds.symbolButton(self.UIElements["zeroModulesButton"], edit=True, enable=True)
      
     self.setupModuleSpecificControls()    
     self.previousBlueprintListEntry = selectedBlprnModule
	def attachGeoToBlueprint_parenting(self,blueprintJoint,geometry):
		jointName = utils.stripAllNamespaces(blueprintJoint)[1]
		parentGroup = cmds.group(empty=True,n=jointName + '_geoAttach_parentGrp#')
		
		if len(geometry) == 1:
			geoParent = cmds.listRelatives(geometry,parent=True)
			if geoParent != None:
				cmds.parent(parentGroup, geoParent)
				
		cmds.parentConstraint(blueprintJoint,parentGroup, maintainOffset=False,n=parentGroup+'_parentConstraint')
		cmds.scaleConstraint(blueprintJoint,parentGroup, maintainOffset=False,n=parentGroup+'_scaleConstraint')
		
		geoParent = parentGroup
		
		children = cmds.listRelatives(blueprintJoint, children=True)
		children = cmds.ls(children,type='joint')
		
		if len(children) != 0:
			childJoint = children[0]
			
			scaleGroup = cmds.group(empty=True, n=jointName+'_geoAttach_scaleGrp#')
			cmds.parent(scaleGroup,parentGroup,relative=True)
			
			geoParent = scaleGroup
			
			originalTxValue = cmds.getAttr(childJoint + '.translateX')
			scaleFactor = cmds.shadingNode('multiplyDivide', asUtility=True, n=scaleGroup+'_scaleFactor')
			cmds.setAttr(scaleFactor+'.operation',2)#divide
			cmds.connectAttr(childJoint+'.translateX',scaleFactor+'.input1X')
			cmds.setAttr(scaleFactor+'.input2X', originalTxValue)
			
			cmds.connectAttr(scaleFactor+'.outputX',scaleGroup+'.scaleX')
			
		for geo in geometry:
			cmds.parent(geo,geoParent,absolute=True)
Ejemplo n.º 10
0
    def install_custom(self, joints):
        cmds.select(clear=True)
        ikJoints=[]

        if not self.mirrored:
            index=0
            for joint in self.jointInfo:
                ikJoints.append(cmds.joint(n=self.moduleNamespace+":IK_"+joint[0], p=joint[1], absolute=True))
                cmds.setAttr(ikJoints[index]+".visibility",0)
                if index!=0:
                    cmds.joint(ikJoints[index-1],edit=True, oj="xyz", sao="yup")
                index+=1
        else:
            rootJointName=self.jointInfo[0][0]
            tempDuplicateNodes=cmds.duplicate(self.originalModule+":IK_"+rootJointName, renameChildren=True)
            cmds.delete(tempDuplicateNodes.pop())
            mirrorXY=False
            mirrorYZ=False
            mirrorXZ=False

            if self.mirrorPlane=="XY":
                mirrorXY=True
            elif self.mirrorPlane=="YZ":
                mirrorYZ=True
            elif self.mirrorPlane=="XZ":
                mirrorXZ=True

            mirrorBehavior=False
            if self.rotationFunction=="behaviour":
                mirrorBehaviour=True
            mirrorJoints=cmds.mirrorJoint(tempDuplicateNodes[0], mirrorXY=mirrorXY, mirrorYZ=mirrorYZ, mirrorXZ=mirrorXZ, mirrorBehavior=mirrorBehavior)
            cmds.delete(tempDuplicateNodes)
            cmds.xform(mirrorJoints[0], worldSpace=True, absolute=True, translation=cmds.xform(self.moduleNamespace+":"+rootJointName, q=True, worldSpace=True, translation=True))

            for i in range(3):
                jointName=self.jointInfo[i][0]
                newName=cmds.rename(mirrorJoints[i], self.moduleNamespace+":IK_"+jointName)
                ikJoints.append(newName)

        utils.addNodeToContainer(self.containerName, ikJoints)

        for joint in ikJoints:
            jointName=utils.stripAllNamespaces(joint)[1]
            cmds.container(self.containerName, edit=True, publishAndBind=[joint+".rotate", jointName+"_R"])

        cmds.setAttr(ikJoints[0]+".preferredAngleY", -50.0)
        cmds.setAttr(ikJoints[1]+".preferredAngleY", 50.0)
        ikNodes=utils.RP_2segment_stretchy_IK(ikJoints[0], ikJoints[1], ikJoints[2], self.containerName)
        locators=(ikNodes[0], ikNodes[1], ikNodes[2])
        distanceNodes=ikNodes[3]
        constraints=[]
        for i in range(3):
            constraints.append(cmds.pointConstraint(self.getTranslationControl(joints[i]), locators[i], maintainOffset=False)[0])
            cmds.parent(locators[i],self.moduleNamespace+":module_grp", absolute=True)
            cmds.setAttr(locators[i]+".visibility",0)
        utils.addNodeToContainer(self.containerName, constraints)
        scaleTarget=self.getTranslationControl(joints[1])
        paRepresentation=self.createPreferredAngleRepresentation(ikJoints[1], scaleTarget)
        cmds.setAttr(paRepresentation+".axis",lock=True) #107
	def initialiseHook(self, rootTranslationControl):
		unhookedLocator = cmds.spaceLocator(name=self.moduleNamespace + ':unhookedTarget')[0]
		#i  have made some changes here on my own to rename to parent constraint. the original version 
		#is commented out.		
		#cmds.pointConstraint(rootTranslationControl, unhookedLocator, offset=[0,0.001,0])
		parentConstraint =cmds.pointConstraint(rootTranslationControl, unhookedLocator, offset=[0,0.001,0])[0]
		cmds.rename(parentConstraint, (self.moduleNamespace + ':' + parentConstraint))
		cmds.setAttr(unhookedLocator + '.visibility', 0)
		
		if self.hookObject == None:
			self.hookObject = unhookedLocator
			
		rootPos = cmds.xform(rootTranslationControl, q=True, worldSpace=True, translation=True)
		targetPos = cmds.xform(self.hookObject, q=True, worldSpace=True, translation=True)
		
		cmds.select(clear=True)
		
		rootJointWithoutNamespace = 'hook_root_joint'
		rootJoint = cmds.joint(n=self.moduleNamespace + ':' + rootJointWithoutNamespace, p=rootPos)
		cmds.setAttr((rootJoint + '.visibility'), 0)
		
		targetJointWithoutNamespace = 'hook_target_joint'
		targetJoint = cmds.joint(n=self.moduleNamespace + ':' + targetJointWithoutNamespace, p=targetPos)
		cmds.setAttr((targetJoint + '.visibility'), 0)
		
		cmds.joint(rootJoint, edit=True, orientJoint='xyz', sao='yup')
		
		hookGroup = cmds.group([rootJoint, unhookedLocator], name=self.moduleNamespace + ':hook_grp', parent=self.moduleGrp)
		
		hookContainer = cmds.container(name=self.moduleNamespace + ':hook_container')
		utils.addNodeToContainer(hookContainer, hookGroup, ihb=True)
		utils.addNodeToContainer(self.containerName, hookContainer)
		
		for joint in [rootJoint, targetJoint]:
			jointName = utils.stripAllNamespaces(joint)[1]
			cmds.container(hookContainer, edit=True, publishAndBind=[joint+'.rotate', jointName+'_R'])
			
		ikNodes = utils.basic_stretchy_IK(rootJoint, targetJoint, hookContainer, lockMinimumLength=False)
		ikHandle = ikNodes['ikHandle']
		rootLocator = ikNodes['rootLocator']
		endLocator = ikNodes['endLocator']
		poleVectorLocator = ikNodes['poleVectorObject']
		
		rootPointConstraint = cmds.pointConstraint(rootTranslationControl, rootJoint, maintainOffset=False, n=(rootJoint + '_pointConstraint'))[0]
		targetPointConstraint = cmds.pointConstraint(self.hookObject, endLocator, maintainOffset=False, n=(self.moduleNamespace + ':hook_pointConstraint'))[0]
		
		utils.addNodeToContainer(hookContainer, [rootPointConstraint, targetPointConstraint])
		
		for node in [ikHandle, rootLocator, endLocator, poleVectorLocator]:
			cmds.parent(node, hookGroup, absolute=True)
			cmds.setAttr((node + '.visibility'), 0)
			
		objectNodes = self.createStretchyObject('/ControlObjects/Blueprint/hook_representation.ma', 'hook_representation_container', 'hook_representation', rootJoint, targetJoint)
		constrainedGrp = objectNodes[2]
		cmds.parent(constrainedGrp, hookGroup, absolute=True)
		
		hookRepresentationContainer = objectNodes[0]
		cmds.container(self.containerName, edit=True, removeNode=hookRepresentationContainer)
		utils.addNodeToContainer(hookContainer, hookRepresentationContainer)
    def createDistanceCalculations(self, rootLocator, endLocator,
                                   containedNodes):
        rootLocatorName = utils.stripAllNamespaces(rootLocator)[1]
        endLocatorName = utils.stripAllNamespaces(endLocator)[1]
        distNode = cmds.shadingNode(
            "distanceBetween",
            asUtility=True,
            n=self.blueprintNamespace + ":" + self.moduleNamespace +
            ":distanceBetween_" + rootLocatorName + "__" + endLocatorName)
        containedNodes.append(distNode)

        rootLocShape = rootLocator + "Shape"
        endLocShape = endLocator + "Shape"

        cmds.connectAttr(rootLocShape + ".worldPosition[0]",
                         distNode + ".point1")
        cmds.connectAttr(endLocShape + ".worldPosition[0]",
                         distNode + ".point2")

        totalOriginalLength = cmds.getAttr(distNode + ".distance")
        totalOriginalLength /= cmds.getAttr(self.blueprintNamespace +
                                            ":module_grp.hierarchicalScale")

        scaleFactor = cmds.shadingNode("multiplyDivide",
                                       asUtility=True,
                                       n=distNode + "_scaleFactor")
        containedNodes.append(scaleFactor)

        cmds.setAttr(scaleFactor + ".operation", 2)  # Divide
        cmds.connectAttr(distNode + ".distance", scaleFactor + ".input1X")
        cmds.setAttr(scaleFactor + ".input2X", totalOriginalLength)

        scaleCorrection = cmds.shadingNode("multiplyDivide",
                                           asUtility=True,
                                           n=scaleFactor + "_correction")
        containedNodes.append(scaleCorrection)

        cmds.setAttr(scaleCorrection + ".operation", 2)  #Divide
        cmds.connectAttr(scaleFactor + ".outputX",
                         scaleCorrection + ".input1X")
        cmds.connectAttr(
            self.blueprintNamespace + ":module_grp.hierarchicalScale",
            scaleCorrection + ".input2X")

        return scaleCorrection + ".outputX"
Ejemplo n.º 13
0
 def install_init(self):
     cmds.namespace(setNamespace=self.blueprintNamespace)
     cmds.namespace(add=self.moduleNamespace)
     cmds.namespace(setNamespace=":")
     
     characterContainer = self.characterNamespaceOnly+":character_container"
     blueprintContainer = self.blueprintNamespace+":module_container"
     containers = [characterContainer, blueprintContainer]
     for c in containers:
         cmds.lockNode(c, lock=False, lockUnpublished=False)
         
     # Duplicate creation pose joints to create new instance. Stored in external method.   
     self.joints = self.duplicateAndRenameCreationPose()
     moduleJointsGrp = self.joints[0]
     
     # Group everything for animation module and parent to "Hook_IN_Grp"
     moduleGrp = cmds.group(empty=True, name=self.blueprintNamespace+":"+self.moduleNamespace+":module_grp")
     hookIn = self.blueprintNamespace+":HOOK_IN"
     cmds.parent(moduleGrp, hookIn, relative=True)
     cmds.parent(moduleJointsGrp, moduleGrp, absolute=True)
     
     # Attr to define icon size.
     cmds.select(moduleGrp)
     cmds.addAttr(at="float", ln="iconScale", min=0.001, softMaxValue=10.0, defaultValue=1, k=True)
     cmds.setAttr(moduleGrp+".overrideEnabled", 1)
     cmds.setAttr(moduleGrp+".overrideColor", 6)
     
     utilityNodes = self.setupBlueprintWeightBasedBlending()
     
     self.setupModuleVisibility(moduleGrp)
     
     containedNodes = list(self.joints)
     containedNodes.append(moduleGrp)
     containedNodes.extend(utilityNodes)
     
     self.moduleContainer = cmds.container(n=self.moduleContainer)
     utils.addNodeToContainer(self.moduleContainer, containedNodes, ihb=True)
     utils.addNodeToContainer(blueprintContainer, self.moduleContainer)
     #151
     index = 0
     publishToOuterContainers=False
     for joint in self.joints:
         if index > 0:
             niceJointName = utils.stripAllNamespaces(joint)[1]
             self.publishNameToModuleContainer(joint+".rotate", niceJointName+"_R", publishToOuterContainers=False)
             publishToOuterContainers=False
             
         index += 1
         
     self.publishNameToModuleContainer(moduleGrp+".lod", "Control_LOD")
     self.publishNameToModuleContainer(moduleGrp+".iconScale", "Icon_Scale")
     self.publishNameToModuleContainer(moduleGrp+".overrideColor", "Icon_Color")
     self.publishNameToModuleContainer(moduleGrp+".visibility", "Vis")
     self.publishNameToModuleContainer(moduleGrp+".visibility", "Vis", publishToOuterContainers=False)
     
     return (self.joints, moduleGrp, self.moduleContainer)
Ejemplo n.º 14
0
    def createFKControl(self, joint, parent, moduleContainer):
        fkControlInfo = self.initFKControl(joint, spaceSwitchable=True)
        
        fkControl = fkControlInfo[0]
        rootControlParent = fkControlInfo[1]
        translationControl = fkControlInfo[2]
  
        cmds.parent(rootControlParent, parent, relative=True)
        
        pointConstraint = ""

        if translationControl:
            cmds.xform(fkControl, worldSpace=True, a=True, translation=cmds.xform(joint, q=True, ws=True, translation=True))
            pointConstraint = cmds.pointConstraint(fkControl, joint, mo=False, n=joint+"_pointConstraint")[0]
        else:
            pointConstraint = cmds.pointConstraint(joint, rootControlParent, maintainOffset=False, n=rootControlParent+"_pointConstraint")[0]
            
        jointOrientation = cmds.xform(joint, q=True, ws=True, rotation=True)
        cmds.xform(fkControl, ws=True, a=True, rotation=jointOrientation)
        
        children = cmds.listRelatives(joint, children=True, type="joint")
        
        childJoint = None
        
        if children == None:
            childJoint = cmds.duplicate(joint, n=joint+"_child")[0]
            utils.addNodeToContainer(moduleContainer, childJoint)
            
            cmds.parent(childJoint, joint, a=True)
            cmds.setAttr(childJoint+".translateX", 1.0)
        else:
            childJoint = children[0]
            
        ikNodes = cmds.ikHandle(sj=joint, ee=childJoint, n=joint+"_ikHandle", sol="ikRPsolver")
        ikNodes[1] = cmds.rename(ikNodes[1], joint+"_effector")
        ikHandle = ikNodes[0]
        
        cmds.parent(ikHandle, fkControl, a=True)
        
        poleVectorLocator = cmds.spaceLocator(n=joint+"_poleVectorLoc")[0]
        
        cmds.parent(poleVectorLocator, joint, relative=True)
        cmds.setAttr(poleVectorLocator+".translateY", 3)
        cmds.parent(poleVectorLocator, fkControl, a=True)
        
        for node in [poleVectorLocator, ikHandle]:
            cmds.setAttr(node+".visibility", 0)
            
        jointName = utils.stripAllNamespaces(joint)[1]
        creationPoseJoint = self.blueprintNamespace + ":creationPose_" + jointName
        utils.matchTwistAngle(ikHandle+".twist", [joint,], [creationPoseJoint,])
        
        containedNodes = list(ikNodes)
        containedNodes.append(pointConstraint)
        containedNodes.append(poleVectorLocator)
        utils.addNodeToContainer(moduleContainer, containedNodes)
	def isModuleInstalled(self,moduleName):
		cmds.namespace(setNamespace=self.currentBlueprintModule)
		installedModules = cmds.namespaceInfo(listOnlyNamespaces=True)
		cmds.namespace(setNamespace=':')
		
		if installedModules != None:
			for module in installedModules:
				installedModuleNameWithSuffix = utils.stripAllNamespaces(module)[1]
				installedModuleName = installedModuleNameWithSuffix.rpartition('_')[0]
				if installedModuleName == moduleName:
					return True
				
		return False
	def acceptWindow(self,targetObject, enumIndex, *args):
		spaceName = cmds.textField(self.UIElements['spaceName'], q=True,text=True)
		maintainOffset = cmds.checkBox(self.UIElements['maintainOffset_checkBox'], q=True, value=True)
		setKeyframes = cmds.checkBox(self.UIElements['setKeyframes_checkBox'],q=True,value=True)
		
		cmds.deleteUI(self.UIElements['window'])
		
		animModuleNamespace = utils.stripAllNamespaces(self.controlObject)[0]
		blueprintModuleNamespace = utils.stripAllNamespaces(animModuleNamespace)[0]
		characterNamespace = utils.stripAllNamespaces(blueprintModuleNamespace)[0]
		
		containers = ( characterNamespace+':character_container',blueprintModuleNamespace+':module_container',animModuleNamespace+':module_container')
		
		for c in containers:
			cmds.lockNode(c,lock=False,lockUnpublished=False)
			
		self.switchSpace(targetObject,spaceName, index=enumIndex, maintainOffset=maintainOffset, setKeyframes=setKeyframes)
			
		for c in containers:
			cmds.lockNode(c,lock=True,lockUnpublished=True)
			
		cmds.select(self.controlObject, replace=True)
Ejemplo n.º 17
0
 def findBlueprintJoints(self, selection):
     selectedBlueprintJoints = []
     for object in selection:
         if cmds.objectType(object, isType="joint"):
             jointNameInfo = utils.stripAllNamespaces(object)
             if jointNameInfo != None:
                 jointName = jointNameInfo[1]
                 if jointName.find("blueprint_") == 0:
                     selectedBlueprintJoints.append(object)
     if len(selectedBlueprintJoints) > 0:
         return selectedBlueprintJoints
     else:
         return None
	def findBlueprintJoints(self,selection):
		selectedBlueprintJoints = []
		
		for object in selection:
			if cmds.objectType(object, isType='joint'):
				jointNameInfo = utils.stripAllNamespaces(object)
				if jointNameInfo != None:
					jointName = jointNameInfo[1]
					if jointName.find('blueprint_') == 0:
						selectedBlueprintJoints.append(object)
						
		if len(selectedBlueprintJoints) > 0:
			return selectedBlueprintJoints
Ejemplo n.º 19
0
	def install_init(self):
		cmds.namespace(setNamespace=self.blueprintNamespace)
		cmds.namespace(add=self.moduleNamespace)
		cmds.namespace(setNamespace=":")
		
		characterContainer = self.characterNamespaceOnly+":character_container"
		blueprintContainer = self.blueprintNamespace+":module_container"
		containers = [characterContainer, blueprintContainer]
		
		for c in containers:
			cmds.lockNode(c, lock=False, lockUnpublished=False)
			
		self.joints = self.duplicateAndRenameCreationPose()
		moduleJointsGrp = self.joints[0]
		
		moduleGrp = cmds.group(empty=True,name=self.blueprintNamespace+":"+self.moduleNamespace+":module_grp")
		hookIn = self.blueprintNamespace+":HOOK_IN"
		cmds.parent(moduleGrp, hookIn, relative=True)
		cmds.parent(moduleJointsGrp, moduleGrp, absolute=True)
		
		cmds.select(moduleGrp)
		cmds.addAttr(at="float", ln="iconScale", min=0.001, softMaxValue=10.0, defaultValue=1, k=True)
		cmds.setAttr(moduleGrp+".overrideEnabled", 1)
		cmds.setAttr(moduleGrp+".overrideColor", 6)
		
		utilityNodes = self.setupBlueprintWeightBasedBlending()
		
		self.setupModuleVisibility(moduleGrp)
		
		containedNodes = list(self.joints)
		containerNodes.append(moduleGrp)
		containedNodes.extend(utilityNodes)
		 
		self.moduleContainer = cmds.container(n=self.moduleContainer)
		utils.addNodeToContainer(self.moduleContainer, containedNodes, ihb=True)
		utils.addNodeToContainer(blueprintContainer, self.moduleContainer)
		 
		index = 0
		for joint in self.joints:
			if index > 0:
				niceJointName = utils.stripAllNamespaces(joint)[1]
				self.publisheNameToModuleContainer(joint+".rotate", niceJointName+"_R", publishToOuterContainers=False)
				
			index += 1
		
		self.publishNameToModuleContainer(moduleGrp+".lod", "Control_LOD")
		self.publishNameToModuleContainer(moduleGrp+".iconScale", "Icon_Scale")
		self.publishNameToModuleContainer(moduleGrp+".overrideColor", "Icon_Colour")
		self.publishNameToModuleContainer(moduleGrp+".visibility", "Vis", publishNameToModuleContainers=False)
		
		return (self.joints, moduleGrp, self.moduleContainer)
Ejemplo n.º 20
0
	def lock_phase1(self):
		#gather and return all the required information from this module's control objects
		
		#joint positions = list of joint positions from root down the hierarchy
		
		#jointOrientations = a list of orientations, or a list of axis information (orientJoint and secondaryAxisOrient for joint command)
		#                    #these are passed in the following tuple:(orientation,None) or (None, asixInfo)
		#jointRotationOrders = a list of joint rotation orders (integer values gathered with getAttr)
		#jointPreferredAngles = a list of joint preferred angles, optional(can pass None)
		#hookObject = self.findHookObjectForLock()
		#rootTransform = a bool, either True or False. True = R,T, and S on root joint. False = R only.
		#
		#moduleInfo = (jointPositions,jointOrientations,jointRotationOrders,jointPreferredAngles, hookObject,rootTransform)
		#return moduleInfo
		
		moduleInfo = hingeJoint.HingeJoint.lock_phase1(self)
		jointPositions = moduleInfo[0]
		jointOrientationValues = moduleInfo[1][0]
		jointRotationOrders = moduleInfo[2]
		
		joints = self.getJoints()
		for i in range(3,5):
			joint = joints[i]
			jointPositions.append(cmds.xform(joint, q=True, worldSpace=True, translation=True))
			jointRotationOrders.append(cmds.getAttr(joint+'.rotateOrder'))
			
		cmds.lockNode(self.containerName, lock=False, lockUnpublished=False)
		
		jointNameInfo = utils.stripAllNamespaces(joints[1])
		cleanParent = jointNameInfo[0] + ':IK_' + jointNameInfo[1] #ikKnee
		deleteJoints = []
		for i in range(2,4):
			orientationInfo = self.orientationControlledJoint_getOrientation(joints[i], cleanParent)
			jointOrientationValues.append(orientationInfo[0])
			cleanParent = orientationInfo[1]
			deleteJoints.append(cleanParent)
			
		cmds.delete(deleteJoints)
		
		cmds.lockNode(self.containerName, lock=True, lockUnpublished=True)
		
		return moduleInfo
			
		
		
			
	
			
		
				
Ejemplo n.º 21
0
    def isModuleInstalled(self, moduleName):
        cmds.namespace(setNamespace=self.currentBlueprintModule)
        installedModules = cmds.namespaceInfo(listOnlyNamespaces=True)
        cmds.namespace(setNamespace=":")

        if installedModules != None:
            for module in installedModules:
                installedModuleWithSuffix = utils.stripAllNamespaces(module)[1]
                installedModuleName = installedModuleWithSuffix.rpartition(
                    "_")[0]
                if installedModuleName == moduleName:
                    return True

        return False
	def install_init(self):
		cmds.namespace(setNamespace=self.blueprintNamespace)
		cmds.namespace(add=self.moduleNamespace)
		cmds.namespace(setNamespace=':')
		
		characterContainer = self.characterNamespaceOnly + ':character_container'
		blueprintContainer = self.blueprintNamespace + ':module_container'
		containers = [characterContainer,blueprintContainer]
		for c in containers:
			cmds.lockNode(c, lock=False, lockUnpublished=False)
			
		self.joints = self.duplicateAndRenameCreationPose()
		moduleJointsGrp = self.joints[0]
		
		moduleGrp = cmds.group(empty=True, name=self.blueprintNamespace + ':' + self.moduleNamespace + ':module_grp')
		hookIn = self.blueprintNamespace + ':HOOK_IN'
		cmds.parent(moduleGrp, hookIn, moduleGrp, relative=True)
		cmds.parent(moduleJointsGrp, moduleGrp, absolute=True)
		
		cmds.select(moduleGrp)
		cmds.addAttr(at='float',ln='iconScale', min=0.001, softMaxValue=10.0, defaultValue=1,k=True)
		cmds.setAttr(moduleGrp + '.overrideEnabled',1)
		cmds.setAttr(moduleGrp + '.overrideColor',6)
		
		utilityNodes = self.setupBlueprintWeightBasedBlending()
		
		self.setupModuleVisibility(moduleGrp)
		
		containedNodes = list(self.joints)
		containedNodes.append(moduleGrp)
		containedNodes.extend(utilityNodes)
		
		self.moduleContainer = cmds.container(n=self.moduleContainer)
		utils.addNodeToContainer(self.moduleContainer,containedNodes, ihb=True)
		utils.addNodeToContainer(blueprintContainer, self.moduleContainer)
		
		index = 0
		for joint in self.joints:
			if index > 0:
				niceJointName = utils.stripAllNamespaces(joint)[1]
				self.publishNameToModuleContainer(joint + '.rotate', niceJointName + '_R', publishToOuterContainers=False)
				
			index += 1
			
		self.publishNameToModuleContainer(moduleGrp + '.lod','Control_LOD')
		self.publishNameToModuleContainer(moduleGrp + '.iconScale', 'Icon_Scale')
		self.publishNameToModuleContainer(moduleGrp + '.overrideColor','Icon_Colour')
		self.publishNameToModuleContainer(moduleGrp + '.visibility', 'Vis', publishToOuterContainers=False)
		
		return (self.joints, moduleGrp, self.moduleContainer)
Ejemplo n.º 23
0
	def __init__(self, moduleNamespace):
		self.moduleContainer = None
		
		if moduleNamespace == None:
			return
			
		moduleNamespaceInfo = utils.stripAllNamespaces(moduleNamespace)
		
		self.blueprintNamespace = moduleNamespaceInfo[0]
		self.moduleNamespace = moduleNamespaceInfo[1]
		self.characterNamespaceOnly = utils.stripLeadingNamespace(self.blueprintNamespace)[0]
		
		self.moduleContainer = self.blueprintNamespace + ":" + self.moduleNamespace + ":module_container"
		
		self.publisheNames = []
Ejemplo n.º 24
0
 def spaceSwitching_deleteKey(self, spaceSwitcher, *args):
     animationNamespace = utils.stripAllNamespaces(spaceSwitcher)[0]
     
     characterContainer = self.selectedCharacter+":character_container"
     blueprintContainer = self.selectedBlueprintModule+":module_container"
     animationContainer = animationNamespace+":module_container"
     
     containers = [characterContainer, blueprintContainer, animationContainer]
     for c in containers:
         cmds.lockNode(c, lock=False, lockUnpublished=False)
         
     cmds.cutKey(spaceSwitcher, at="currentSpace", time=(cmds.currentTime(q=True),))
                    
     for c in containers:
         cmds.lockNode(c, lock=True, lockUnpublished=True)
	def __init__(self,moduleNamespace):
		self.moduleContainer = None
		
		if moduleNamespace == None:
			return
			
		moduleNamespaceInfo = utils.stripAllNamespaces(moduleNamespace)
		
		self.blueprintNamespace = moduleNamespaceInfo[0]
		self.moduleNamespace = moduleNamespaceInfo[1]
		self.characterNamespaceOnly = utils.stripLeadingNamespace(self.blueprintNamespace)[0]
		
		self.moduleContainer = self.blueprintNamespace + ':' + self.moduleNamespace + ':module_container'
		
		self.publishedNames = []
Ejemplo n.º 26
0
    def findSubModules(self, group):
        returnModules = []
        children = cmds.listRelatives(group)
        children = cmds.ls(children, transforms=True)

        for child in children:
            if child.find("Group__") == 0:
                returnModules.extend(self.findSubModules(child))
            else:
                namespaceInfo = utils.stripAllNamespaces(child)
                if namespaceInfo != None and namespaceInfo[
                        1] == "module_transform":
                    module = namespaceInfo[0]
                    returnModules.append(module)

        return returnModules
Ejemplo n.º 27
0
	def prepareForTemplate(self, *args):
		cmds.select(all=True)
		rootLevelNodes = cmds.ls(selection=True, transforms=True)
		
		filteredNodes = []
		for node in rootLevelNodes:
			if node.find("Group__") == 0:
				filteredNodes.append(node)
			else:
				nodeNamespaceInfo = utils.stripAllNamespaces(node)
				if nodeNamespaceInfo != None:
					if nodeNamespaceInfo[1] == "module_transform":
						filteredNodes.append(node)
		if len(filteredNodes) > 0:
			cmds.select(filteredNodes, replace=True)
			self.groupSelected()
Ejemplo n.º 28
0
    def attachGeoToBlueprint_parenting(self, blueprintJoint, geometry):
        jointName = utils.stripAllNamespaces(blueprintJoint)[1]
        parentGroup = cmds.group(empty=True,
                                 n=jointName + "_geoAttach_parentGrp#")

        if len(geometry) == 1:
            geoParent = cmds.listRelatives(geometry, parent=True)
            if geoParent != None:
                cmds.parent(parentGroup, geoParent)

        cmds.parentConstraint(blueprintJoint,
                              parentGroup,
                              maintainOffset=False,
                              n=parentGroup + "_parentConstraint")
        cmds.scaleConstraint(blueprintJoint,
                             parentGroup,
                             maintainOffset=False,
                             n=parentGroup + "_scaleConstraint")

        geoParent = parentGroup

        children = cmds.listRelatives(blueprintJoint, children=True)
        children = cmds.ls(children, type="joint")

        if len(children) != 0:
            childJoint = children[0]

            scaleGroup = cmds.group(empty=True,
                                    n=jointName + "_geoAttach_scaleGrp#")
            cmds.parent(scaleGroup, parentGroup, relative=True)

            geoParent = scaleGroup

            originalTxValue = cmds.getAttr(childJoint + ".translateX")
            scaleFactor = cmds.shadingNode("multiplyDivide",
                                           asUtility=True,
                                           n=scaleGroup + "_scaleFactor")
            cmds.setAttr(scaleFactor + ".operation", 2)  #divide
            cmds.connectAttr(childJoint + ".translateX",
                             scaleFactor + ".input1X")
            cmds.setAttr(scaleFactor + ".input2X", originalTxValue)

            cmds.connectAttr(scaleFactor + ".outputX", scaleGroup + ".scaleX")

        for geo in geometry:
            cmds.parent(geo, geoParent, absolute=True)
Ejemplo n.º 29
0
	def initFKControl(self,joint,spaceSwitchable=False):
		translationControl = False
		jointName = utils.stripAllNamespaces(joint)[1]
		blueprintJoint = self.blueprintNamespace + ':blueprint_' + jointName
		if cmds.objExists(blueprintJoint+'_addTranslate'):
			translationControl = True
		
		name = jointName + '_fkControl'
		
		controlObjectInstance = controlObject.ControlObject()
		
		fkControlInfo = controlObjectInstance.create(name, 'sphere.ma', self, lod=1, translation=translationControl, rotation=True, globalScale=False, spaceSwitching=spaceSwitchable)
		fkControl = fkControlInfo[0]

		cmds.connectAttr(joint + '.rotateOrder', fkControl + '.rotateOrder')
		
		return (fkControlInfo[0], fkControlInfo[1], translationControl)
	def createOrientationControl(self,parentJoint,childJoint):
	
		self.deleteHierarchyRepresentation(parentJoint)
		
		nodes = self.createStretchyObject('/ControlObjects/Blueprint/orientation_control.ma', 'orientation_control_container','orientation_control',parentJoint,childJoint)
		orientationContainer = nodes[0]
		orientationControl = nodes[1]
		constrainedGrp = nodes[2]
		
		cmds.parent(constrainedGrp,self.orientationControlsGrp, relative=True)
		
		parentJointWithoutNamespace = utils.stripAllNamespaces(parentJoint)[1]
		attrName = parentJointWithoutNamespace + '_orientation'
		cmds.container(orientationContainer, edit=True, publishAndBind=[orientationControl + '.rotateX', attrName])
		cmds.container(orientationContainer, edit=True, publishAndBind=[orientationContainer + '.' + attrName, attrName])
		
		return orientationControl
	def prepareForTemplate(self, *args):
		cmds.select(all=True)
		rootLevelNodes= cmds.ls(selection=True, transforms=True)
		
		filteredNodes = []
		for node in rootLevelNodes:
			if node.find('Group__') == 0:
				filteredNodes.append(node)
			else:
				nodeNamespaceInfo = utils.stripAllNamespaces(node)
				if nodeNamespaceInfo != None:
					if nodeNamespaceInfo[1] == 'module_transform':
						filteredNodes.append(node)
						
		if len(filteredNodes) > 0:
			cmds.select(filteredNodes, replace=True)
			self.groupSelected()
Ejemplo n.º 32
0
    def lock_phase1(self):
        #Gather and return all required information from this module's control object

        #jointPositions = list of joint positions, from root down the hierarchy

        #jointOrientations = a list of orientations, or a list of axis information (orientJoint and secondaryAxisOrient for the joint cmd)
        #					#These are passed in the followint tuple: (orientations, None) or (None, axisInfo)
        #jointRotationOrders = a list of joint rotation orders (integers values gathered with getAttr)
        #jointPreferredAngles = a list of joint preferred angles, optional (can pass None)
        #hookObject = self.findHookObjectForLock()
        #rootTransform = a bool, either True or False. True =R, T and S on root joint. False = R only.
        #
        #moduleInfo = (jointPositions, jointOrientations, jointRotationOrders, jointPreferredAngles, hookObject, rootTransform)
        #return moduleInfo

        moduleInfo = hingeJoint.HingeJoint.lock_phase1(self)
        jointPositions = moduleInfo[0]
        jointOrientationValues = moduleInfo[1][0]
        jointRotationOrders = moduleInfo[2]

        joints = self.getJoints()
        for i in range(3, 5):
            joint = joints[i]
            jointPositions.append(
                cmds.xform(joint, q=True, worldSpace=True, translation=True))
            jointRotationOrders.append(cmds.getAttr(joint + ".rotateOrder"))

        cmds.lockNode(self.containerName, lock=False, lockUnpublished=False)

        jointNameInfo = utils.stripAllNamespaces(joints[1])
        cleanParent = jointNameInfo[0] + ":IK_" + jointNameInfo[1]  #ikKnee
        deleteJoints = []
        for i in range(2, 4):
            orientationInfo = self.orientationControlledJoint_getOrientation(
                joints[i], cleanParent)
            jointOrientationValues.append(orientationInfo[0])
            cleanParent = orientationInfo[1]
            deleteJoints.append(cleanParent)

        cmds.delete(deleteJoints)
        cmds.lockNode(self.containerName, lock=True, lockUnpublished=True)

        return moduleInfo
Ejemplo n.º 33
0
    def initFKControl(self, joint, spaceSwitchable=False):
        translationControl = False
        jointName = utils.stripAllNamespaces(joint)[1]
        blueprintJoint = self.blueprintNamespace + ":blueprint_"+jointName
        
        if cmds.objExists(blueprintJoint+"_addTranslate"):
            translationControl = True

        name = jointName + "_fkControl"
        
        controlObjectInstance = controlObject.ControlObject()
        
        fkControlInfo = controlObjectInstance.create(name, "fourArrowControl.ma", self, lod=1, translation=translationControl, rotation=True, globalScale=False, spaceSwitching=spaceSwitchable)
        fkControl = fkControlInfo[0]
        
       
        cmds.connectAttr(joint+".rotateOrder", fkControl+".rotateOrder")
        
        return (fkControlInfo[0], fkControlInfo[1], translationControl )
	def setupSpaceSwitching(self,blueprintModuleNamespace,animationModuleNamespace,animationModuleInstance):
		cmds.select(self.controlObject,replace=True)
		cmds.addAttr(at='bool',defaultValue=True,keyable=False,longName='spaceSwitching')
		cmds.addAttr(at='bool',defaultValue=False,keyable=False,longName='switchOrientationOnly')
		
		spaceSwitcher = cmds.group(empty=True, name=self.controlObject+'_spaceSwitcher')
		
		if self.translation != [True,True,True]:
			cmds.setAttr(self.controlObject+'.switchOrientationOnly',True)
			
		cmds.parent(self.rootParent,spaceSwitcher, absolute=True)
		self.rootParent = spaceSwitcher
		
		utils.addNodeToContainer(animationModuleNamespace+':module_container',spaceSwitcher)
		
		self.switchSpace(blueprintModuleNamespace+':HOOK_IN','Module Hook')
		
		controlObjectName = utils.stripAllNamespaces(self.controlObject)[1]
		animationModuleInstance.publishNameToModuleContainer(spaceSwitcher+'.currentSpace', controlObjectName+'_currentSpace', publishToOuterContainers=True)
Ejemplo n.º 35
0
 def createFKControl(self, joint, parent, moduleContainer):
     fkControl = fk.FK.createFKControl(self, joint, parent, moduleContainer)
     
     children = cmds.listRelatives(joint, children=True, type="joint")
     childJoint = children[0]
     
     cmds.select(fkControl, replace=True)
     cmds.addAttr(at="float", defaultValue=1.0, minValue=0.001, softMaxValue=5.0, keyable=True, longName="stretch")
     cmds.addAttr(at="float", keyable=False, longName="originalLength")
     
     cmds.setAttr(fkControl+".originalLength", cmds.getAttr(childJoint+".translateX"))
     
     stretchFactorMultiply = cmds.shadingNode("multiplyDivide", asUtility=True, n=childJoint+"_stretchFactorMultiply")
     cmds.connectAttr(fkControl+".stretch", stretchFactorMultiply+".input1X", force=True)
     cmds.connectAttr(fkControl+".originalLength", stretchFactorMultiply+".input2X", force=True)
     cmds.connectAttr(stretchFactorMultiply+".outputX", childJoint+".translateX", force=True)
     
     utils.addNodeToContainer(moduleContainer, stretchFactorMultiply)
     
     attributeNiceName = utils.stripAllNamespaces(childJoint)[1]+"_stretch"
     self.publishNameToModuleContainer(fkControl+".stretch", attributeNiceName, publishToOuterContainers=True)
	def createFKControl(self,joint,parent,moduleContainer):
		fkControl = fk.FK.createFKControl(self,joint,parent,moduleContainer)
		
		children = cmds.listRelatives(joint, children=True, type='joint')
		childJoint = children[0]
		
		cmds.select(fkControl, replace=True)
		cmds.addAttr(at='float', defaultValue=1.0, minValue=0.001, softMaxValue=5.0, keyable=True, longName='stretch')
		cmds.addAttr(at='float', keyable=False, longName='originalLength')
		
		cmds.setAttr(fkControl+'.originalLength',cmds.getAttr(childJoint+'.translateX'))
		
		stretchFactorMultiply = cmds.shadingNode('multiplyDivide', asUtility=True, n=childJoint+'_stretchFactorMultiply')
		cmds.connectAttr(fkControl+'.stretch',stretchFactorMultiply+'.input1X',force=True)
		cmds.connectAttr(fkControl+'.originalLength',stretchFactorMultiply+'.input2X',force=True)
		cmds.connectAttr(stretchFactorMultiply+'.outputX',childJoint+'.translateX',force=True)
		
		utils.addNodeToContainer(moduleContainer,stretchFactorMultiply)
		
		attributeNiceName = utils.stripAllNamespaces(childJoint)[1]+'_stretch'
		self.publishNameToModuleContainer(fkControl+'.stretch', attributeNiceName,publishToOuterContainers=True)
Ejemplo n.º 37
0
    def createFKControl(self, joint, parent, moduleContainer):
        fkControl = fk.FK.createFKControl(self, joint, parent, moduleContainer)

        children = cmds.listRelatives(joint, children=True, type="joint")
        childJoint = children[0]

        cmds.select(fkControl, replace=True)
        cmds.addAttr(at="float",
                     defaultValue=1.0,
                     minValue=0.001,
                     softMaxValue=5.0,
                     keyable=True,
                     longName="stretch")
        cmds.addAttr(at="float", keyable=False, longName="originalLength")

        cmds.setAttr(fkControl + ".originalLength",
                     cmds.getAttr(childJoint + ".translateX"))

        stretchFactorMultiply = cmds.shadingNode("multiplyDivide",
                                                 asUtility=True,
                                                 n=childJoint +
                                                 "_stretchFactorMultiply")
        cmds.connectAttr(fkControl + ".stretch",
                         stretchFactorMultiply + ".input1X",
                         force=True)
        cmds.connectAttr(fkControl + ".originalLength",
                         stretchFactorMultiply + ".input2X",
                         force=True)
        cmds.connectAttr(stretchFactorMultiply + ".outputX",
                         childJoint + ".translateX",
                         force=True)

        utils.addNodeToContainer(moduleContainer, stretchFactorMultiply)

        attributeNiceName = utils.stripAllNamespaces(
            childJoint)[1] + "_stretch"
        self.publishNameToModuleContainer(fkControl + ".stretch",
                                          attributeNiceName,
                                          publishToOuterContainers=True)
	def UI(self,parentLayout):
		cmds.setParent(parentLayout)
		cmds.separator()
		
		niceName = utils.stripAllNamespaces(self.controlObject)[1]
		cmds.text(label=niceName)
		
		cmds.attrControlGrp(attribute=self.controlObject + '.display', label='Visibility: ')
		
		if self.translation == [True,True,True]:
			cmds.attrControlGrp(attribute=self.controlObject + '.translate', label='Translate')
		else:
			if self.translation[0] == True:
				cmds.attrControlGrp(attribute=self.controlObject + '.translateX', label='Translate X')
				
			if self.translation[1] == True:
				cmds.attrControlGrp(attribute=self.controlObject + '.translateY', label='Translate Y')
				
			if self.translation[2] == True:
				cmds.attrControlGrp(attribute=self.controlObject + '.translateZ', label='Translate Z')
			
			


		if self.rotation == [True,True,True]:
			cmds.attrControlGrp(attribute=self.controlObject + '.rotate', label='Rotate')
		else:
			if self.rotation[0] == True:
				cmds.attrControlGrp(attribute=self.controlObject + '.rotateX', label='Rotate X')
				
			if self.rotation[1] == True:
				cmds.attrControlGrp(attribute=self.controlObject + '.rotateY', label='Rotate Y')
				
			if self.rotation[2] == True:
				cmds.attrControlGrp(attribute=self.controlObject + '.rotateZ', label='Rotate Z')
				
		if self.globalScale == True:
			cmds.attrControlGrp(attribute=self.controlObject + '.globalScale', label='Scale')
Ejemplo n.º 39
0
    def install_custom(self, joints, moduleGrp, moduleContainer):
        ankleJoint = joints[3]
        ballJoint = joints[4]
        toeJoint = joints[5]
        
        tempLocator = cmds.spaceLocator()[0]
        cmds.parent(tempLocator, ballJoint, relative=True)
        cmds.parent(tempLocator, moduleGrp, absolute=True)
        
        ballJoint_modulePos = [cmds.getAttr(tempLocator+".translateX"), cmds.getAttr(tempLocator+".translateY"), cmds.getAttr(tempLocator+".translateZ")]
       
        cmds.parent(tempLocator, ankleJoint)
        for attr in [".translateX", ".translateY", ".translateZ"]:
            cmds.setAttr(tempLocator+attr, 0)
        cmds.parent(tempLocator, moduleGrp, absolute=True)
        
        ankleJoint_modulePos = [cmds.getAttr(tempLocator+".translateX"), cmds.getAttr(tempLocator+".translateY"), cmds.getAttr(tempLocator+".translateZ")]
        
        cmds.parent(tempLocator, toeJoint)
        for attr in [".translateX", ".translateY", ".translateZ"]:
            cmds.setAttr(tempLocator+attr, 0)
        cmds.parent(tempLocator, moduleGrp, absolute=True)
        
        toeJoint_modulePos = [cmds.getAttr(tempLocator+".translateX"), cmds.getAttr(tempLocator+".translateY"), cmds.getAttr(tempLocator+".translateZ")]
        
        cmds.delete(tempLocator)  
        
        containedNodes = []

        # Pass in functionality from basic IK        
        ikNodes = circleIK.CircleControlStretchyIK.install_custom(self, joints, moduleGrp, moduleContainer, createHandleControl=False, poleVectorAtRoot=False)
        ikEndPosLocator = ikNodes["endLocator"]
        ikPoleVectorLocator = ikNodes["poleVectorObject"]
        
        stretchinessAttribute = ikNodes["stretchinessAttribute"]
        
        name = "footControl"
        controlObjectInstance = controlObject.ControlObject()
        footControlInfo = controlObjectInstance.create(name, "footControl.ma", self, lod=1, translation=True, rotation=True, globalScale=False, spaceSwitching=True)
        footControl = footControlInfo[0]
        footControlRootParent = footControlInfo[1]
        
        # Parent foot control to root parent
        cmds.parent(footControlRootParent, moduleGrp, relative=True)
        
        # Position and orient foot control
        footControlPos = [ankleJoint_modulePos[0], ballJoint_modulePos[1], ankleJoint_modulePos[2]]
        cmds.xform(footControl, objectSpace=True, absolute=True, translation=footControlPos)
        
        cmds.setAttr(footControl+".rotateOrder", 3) #3 = xyz
        
        orientationVector = [toeJoint_modulePos[0] - ankleJoint_modulePos[0], toeJoint_modulePos[2] - ankleJoint_modulePos[2] ]
        
        footControlRotation = atan2(orientationVector[1], orientationVector[0])
        cmds.setAttr(footControl+".rotateY", -degrees(footControlRotation))
        
        # Hookup stretchiness attribute
        cmds.select(footControl)
        cmds.addAttr(at="float", minValue=0.0, maxValue=1.0, defaultValue=1.0, keyable=True, longName="stretchiness")
        self.publishNameToModuleContainer(footControl+".stretchiness", "stretchiness", publishToOuterContainers=True)
        
        cmds.connectAttr(footControl+".stretchiness", stretchinessAttribute, force=True)
        
        # Setup for ball and Toe controls
        ballToeControls = []
        ballToeControl_orientGrps = []
        for joint in [ballJoint, toeJoint]:
            controlObjectInstance = controlObject.ControlObject()
            jointName = utils.stripAllNamespaces(joint)[1]
            name = jointName + "_ryControl"
            
            ryControlInfo = controlObjectInstance.create(name, "yAxisCircle.ma", self, lod=2, translation=False, rotation=[True, True, True], globalScale=False, spaceSwitching=False)
            ryControl = ryControlInfo[0]
            
            ballToeControls.append(ryControl)
            
            orientGrp = cmds.group(empty=True, n=ryControl+"_orientGrp")
            containedNodes.append(orientGrp)
            ballToeControl_orientGrps.append(orientGrp)
            
            # Constrain to inherit orientations
            orientGrp_parentConstraint = cmds.parentConstraint(joint, orientGrp, maintainOffset=False)
            cmds.delete(orientGrp_parentConstraint)
            
            cmds.parent(ryControl, orientGrp, relative=True)
            
        for grp in ballToeControl_orientGrps:
            cmds.parent(grp, moduleGrp, absolute=True)
        # Constrain ball control    
        containedNodes.append(cmds.parentConstraint(footControl, ballToeControl_orientGrps[1], maintainOffset=True, n=ballToeControl_orientGrps[1] + "_parentConstraint")[0])
        # Constrain toe control 
        containedNodes.append(cmds.parentConstraint(ballToeControls[1], ballToeControl_orientGrps[0], maintainOffset=True, n=ballToeControl_orientGrps[0] + "_parentConstraint")[0])
        # Connect IK handles
        cmds.parent(ikEndPosLocator, ballToeControls[0], absolute=True)
        cmds.parent(ikPoleVectorLocator, ballToeControls[0], absolute=True)
       
        # Ankle IK
        ankleIKNodes = cmds.ikHandle(sj=ankleJoint, ee=ballJoint, solver="ikSCsolver", n=ankleJoint+"_ikHandle")
        ankleIKNodes[1] = cmds.rename(ankleIKNodes[1], ankleIKNodes[1]+"_ikEffector")
        containedNodes.extend(ankleIKNodes)
        
        cmds.parent(ankleIKNodes[0], ballToeControls[0])
        cmds.setAttr(ankleIKNodes[0]+".visibility", 0)
        
        #Ball IK 
        ballIKNodes = cmds.ikHandle(sj=ballJoint, ee=toeJoint, solver="ikSCsolver", n=ballJoint+"_ikHandle")
        ballIKNodes[1] = cmds.rename(ballIKNodes[1], ballIKNodes[1]+"_ikEffector")
        containedNodes.extend(ballIKNodes)
        
        cmds.parent(ballIKNodes[0], ballToeControls[1])
        cmds.setAttr(ballIKNodes[0]+".visibility", 0)
        
        utils.addNodeToContainer(moduleContainer, containedNodes, ihb=True)
Ejemplo n.º 40
0
    def progressGroup(self, group, parent):
        import System.groupSelected as groupSelected
        reload(groupSelected)

        tempGroup = cmds.duplicate(group,
                                   parentOnly=True,
                                   inputConnections=True)[0]
        emptyGroup = cmds.group(empty=True)
        cmds.parent(tempGroup, emptyGroup, absolute=True)

        scaleAxis = ".scaleX"
        if self.mirrorPlane == "XZ":
            scaleAxis = ".scaleY"
        elif self.mirrorPlane == "XY":
            scaleAxis = ".scaleZ"

        cmds.setAttr(emptyGroup + scaleAxis, -1)

        instance = groupSelected.GroupSelected()
        groupSuffix = group.partition("__")[2]
        newGroup = instance.createGroupAtSpecified(groupSuffix + "_mirror",
                                                   tempGroup, parent)

        cmds.lockNode("Group_container", lock=False, lockUnpublished=False)
        cmds.delete(emptyGroup)

        for moduleLink in ((group, newGroup), (newGroup, group)):
            attributeValue = moduleLink[1] + "__"

            if self.mirrorPlane == "YZ":
                attributeValue += "X"
            elif self.mirrorPlane == "XZ":
                attributeValue += "Y"
            elif self.mirrorPlane == "XY":
                attributeValue += "Z"

            cmds.select(moduleLink[0])
            cmds.addAttr(dt="string", longName="mirrorLinks", k=False)
            cmds.setAttr(moduleLink[0] + ".mirrorLinks",
                         attributeValue,
                         type="string")

        cmds.select(clear=True)

        children = cmds.listRelatives(group, children=True)
        children = cmds.ls(children, transforms=True)

        for child in children:
            if child.find("Group__") == 0:
                self.progressGroup(child, newGroup)
            else:
                childNamespaces = utils.stripAllNamespaces(child)
                if childNamespaces != None and childNamespaces[
                        1] == "module_transform":
                    for module in self.moduleInfo:
                        if childNamespaces[0] == module[0]:
                            moduleContainer = module[1] + ":module_container"
                            cmds.lockNode(moduleContainer,
                                          lock=False,
                                          lockUnpublished=False)

                            moduleTransform = module[1] + ":module_transform"
                            cmds.parent(moduleTransform,
                                        newGroup,
                                        absolute=True)

                            cmds.lockNode(moduleContainer,
                                          lock=True,
                                          lockUnpublished=True)
Ejemplo n.º 41
0
    def objectSelected(self):
        print "objectSelected 58"
        objects = cmds.ls(selection = True)
        
        cmds.select(clear=True)
        
        """ Find the installed characters """
        characters = utils.findInstalledCharacters()
        
        """ Unlock the containers """
        for character in characters:
            characterContainer = character + ":character_container"
            cmds.lockNode(characterContainer, lock=False, lockUnpublished=False)
            # Find every module installed on that character.
            blueprintInstances = utils.findInstalledBlueprintInstances(character)
            
            for blueprintInstance in blueprintInstances:
                moduleContainer = character+":"+blueprintInstance+":module_container"
                cmds.lockNode(moduleContainer, lock=False, lockUnpublished=False)
                
                """ Do we have modules installed?  If so, set the joint color to blue. """
                blueprintJointsGrp = character+":"+blueprintInstance+":blueprint_joints_grp"
                
                if cmds.getAttr(blueprintJointsGrp+".controlModulesInstalled"):
                    #Blue
                    cmds.setAttr(blueprintJointsGrp+".overrideColor", 6)
                else:
                    cmds.setAttr(blueprintJointsGrp+".overrideColor", 2)
                
                cmds.lockNode(moduleContainer, lock=True, lockUnpublished=True)
                       
            cmds.lockNode(characterContainer, lock=True, lockUnpublished=True)
        
        if len(objects) > 0:
            lastSelected = objects[len(objects)-1]
            
            lastSelected_stripNamespaces = utils.stripAllNamespaces(lastSelected)
                    
            if lastSelected_stripNamespaces != None:
                lastSelected_withoutNamespaces = lastSelected_stripNamespaces[1]
                
                if lastSelected_withoutNamespaces.find("blueprint_") == 0:
                    blueprintModuleNamespace_incCharNamespace = lastSelected_stripNamespaces[0]
                    moduleContainer = blueprintModuleNamespace_incCharNamespace + ":module_container"

                    cmds.select(moduleContainer, replace=True)
                    
                    # set color of the joints
                    characterNamespace = utils.stripLeadingNamespace(lastSelected)[0]
                    
                    characterContainer = characterNamespace + ":character_container"
                    
                    containers = [characterContainer, moduleContainer]
                    for container in containers:
                        cmds.lockNode(container, lock=False, lockUnpublished=False)
                        
                    blueprintJointsGrp = blueprintModuleNamespace_incCharNamespace+":blueprint_joints_grp"
                    #  This was not in the video.  I needed to add this to allow overrides.
                    cmds.setAttr(blueprintJointsGrp+".overrideEnabled", 1)

                    cmds.setAttr(blueprintJointsGrp+".overrideColor", 13)
                                              
                    for container in containers:
                        cmds.lockNode(container, lock=True, lockUnpublished=True)

        self.currentBlueprintModule['currentMod'] = (blueprintModuleNamespace_incCharNamespace)
        print "ModMaintEX cureent bp mod name "
        print self.currentBlueprintModule['currentMod']
    def install_custom(self, joints, moduleGrp, moduleContainer):
        result = cmds.confirmDialog(
            title="Interpolation-based Stretchy Spline",
            message="please specify the root control type:",
            button=["Translation and Rotation", "Rotation Only", "None"],
            defaultButton="Translation and Rotation",
            cancelButton="None",
            dismissString="None")

        rootControlTranslation = (result == "Translation and Rotation")
        createRootControl = not (result == "None")

        containedNodes = []

        creationPoseJoints = []
        for joint in joints:
            jointName = utils.stripAllNamespaces(joint)[1]
            creationPoseJoint = self.blueprintNamespace + ":creationPose_" + jointName
            creationPoseJoints.append(creationPoseJoint)

        # Create root and end controls
        rootControlObject = moduleGrp
        if createRootControl:
            rootControlObjectInfo = self.createRootEndControl(
                "rootControl", creationPoseJoints[1], creationPoseJoints[1],
                rootControlTranslation, containedNodes, moduleGrp)

            #"Return Tuple.  [0] is object, [1] parent"
            rootControlObject = rootControlObjectInfo[0]
            rootControlParent = rootControlObjectInfo[1]

            if not rootControlTranslation:
                containedNodes.append(
                    cmds.pointConstraint(moduleGrp,
                                         rootControlParent,
                                         maintainOffset=True)[0])
        # Orient end joint based off second to last joint
        endControlObjectInfo = self.createRootEndControl(
            "endControl", creationPoseJoints[len(creationPoseJoints) - 2],
            creationPoseJoints[len(creationPoseJoints) - 1], True,
            containedNodes, moduleGrp)
        endControlObject = endControlObjectInfo[0]

        # Setup splineIK
        # Duplicate stretchyIKJoints and rename
        stretchyIKJoints = cmds.duplicate(joints, renameChildren=True)
        index = 0
        for joint in stretchyIKJoints:
            stretchyIKJoints[index] = cmds.rename(
                joint, joints[index] + "_stretchyIKJoint")
            index += 1

        containedNodes.extend(stretchyIKJoints)

        # Get the ws position of the root and end joints
        rootJoint = stretchyIKJoints[1]
        endJoint = stretchyIKJoints[len(stretchyIKJoints) - 1]
        secondJoint = stretchyIKJoints[2]
        secondToLastJoint = stretchyIKJoints[len(stretchyIKJoints) - 2]

        rootPos = cmds.xform(rootJoint, q=True, ws=True, translation=True)
        endPos = cmds.xform(endJoint, q=True, ws=True, translation=True)

        rootLocator = cmds.spaceLocator(n=stretchyIKJoints[0] +
                                        "_systemStretch_rootLocator")[0]
        cmds.xform(rootLocator, ws=True, absolute=True, translation=rootPos)
        #containedNodes.append(rootLocator)

        endLocator = cmds.spaceLocator(n=stretchyIKJoints[0] +
                                       "_systemStretch_endLocator")[0]
        cmds.xform(endLocator, ws=True, absolute=True, translation=endPos)
        #containedNodes.append(endLocator)

        # Hide locators
        for loc in [rootLocator, endLocator]:
            cmds.setAttr(loc + ".visibility", 0)

        #parent locators to controls
        cmds.parent(rootLocator, rootControlObject, absolute=True)
        cmds.parent(endLocator, endControlObject, absolute=True)

        index = 0
        for joint in stretchyIKJoints:
            if index > 2 and index < len(stretchyIKJoints) - 1:
                cmds.select(stretchyIKJoints[index], replace=True)
                cmds.addAttr(at="float", longName="originalLength")
                originalLength = cmds.getAttr(stretchyIKJoints[index] +
                                              ".translateX")
                cmds.setAttr(stretchyIKJoints[index] + ".originalLength",
                             originalLength)

            index += 1

        # Setup the scale factor
        scaleFactorAttr = self.createDistanceCalculations(
            rootLocator, endLocator, containedNodes)

        rootScaler = self.createScalar(rootLocator, scaleFactorAttr,
                                       containedNodes)
        endScaler = self.createScalar(endLocator, scaleFactorAttr,
                                      containedNodes)

        rootIKLocators = self.setupBasicStretchyIK(rootJoint, secondJoint,
                                                   creationPoseJoints[1],
                                                   rootControlObject,
                                                   moduleContainer, moduleGrp)
        rootIK_rootLocator = rootIKLocators[0]
        rootIK_endLocator = rootIKLocators[1]

        cmds.parent(rootIK_endLocator, rootScaler, absolute=True)

        endIKLocators = self.setupBasicStretchyIK(
            secondToLastJoint, endJoint,
            creationPoseJoints[len(creationPoseJoints) - 2], endControlObject,
            moduleContainer, moduleGrp)
        endIK_rootLocator = endIKLocators[0]
        endIK_endLocator = endIKLocators[1]

        cmds.parent(endIK_endLocator, endControlObject, absolute=True)

        ikNodes = cmds.ikHandle(sj=secondJoint,
                                ee=secondToLastJoint,
                                n=secondJoint + "_splineIKHandle",
                                sol="ikSplineSolver",
                                rootOnCurve=False,
                                createCurve=True)

        ikNodes[1] = cmds.rename(ikNodes[1], secondJoint + "_splineIKEffector")
        ikNodes[2] = cmds.rename(ikNodes[2], secondJoint + "_splineIKCurve")

        splineIKhandle = ikNodes[0]
        splineIKCurve = ikNodes[2]

        containedNodes.extend(ikNodes)

        cmds.parent(splineIKhandle, moduleGrp, absolute=True)
        cmds.setAttr(splineIKhandle + ".visibility", 0)
        cmds.setAttr(splineIKCurve + ".visibility", 0)

        cmds.parent(splineIKCurve, world=True, absolute=True)
        cmds.setAttr(splineIKCurve + ".inheritsTransform", 0)
        cmds.parent(splineIKCurve, moduleGrp, relative=True)

        # Create a cluster for the CV's on the curve.
        cmds.select(splineIKCurve + ".cv[0:1]", replace=True)
        clusterNodes = cmds.cluster(n=splineIKCurve + "_rootCluster")
        cmds.container(moduleContainer,
                       edit=True,
                       addNode=clusterNodes,
                       ihb=True,
                       includeNetwork=True)
        rootClusterHandle = clusterNodes[1]

        cmds.select(splineIKCurve + ".cv[2:3]", replace=True)
        clusterNodes = cmds.cluster(n=splineIKCurve + "_endCluster")
        cmds.container(moduleContainer,
                       edit=True,
                       addNode=clusterNodes,
                       ihb=True,
                       includeNetwork=True)
        endClusterHandle = clusterNodes[1]

        for handle in [rootClusterHandle, endClusterHandle]:
            cmds.setAttr(handle + ".visibility", 0)

        cmds.parent(rootClusterHandle, rootScaler, absolute=True)
        cmds.parent(endClusterHandle, endScaler, absolute=True)

        containedNodes.append(
            cmds.parentConstraint(rootControlObject,
                                  rootJoint,
                                  maintainOffset=True)[0])

        targetLocatorNodes = cmds.duplicate(endIK_rootLocator,
                                            name=endIK_rootLocator +
                                            "_duplicateTarget")
        targetLocator = targetLocatorNodes[0]
        cmds.delete(targetLocatorNodes[1])
        cmds.parent(targetLocator, endScaler, absolute=True)

        splineScaleFactorAttr = self.createDistanceCalculations(
            rootIK_endLocator, targetLocator, containedNodes)

        # Use scaleFactor on each of the joints
        index = 0
        for joint in stretchyIKJoints:
            if index > 2 and index < len(stretchyIKJoints) - 1:
                multNode = cmds.shadingNode("multiplyDivide",
                                            asUtility=True,
                                            n=joint + "_jointScale")
                containedNodes.append(multNode)
                cmds.connectAttr(scaleFactorAttr, multNode + ".input1X")
                cmds.setAttr(multNode + ".input2X",
                             cmds.getAttr(joint + ".originalLength"))

                cmds.connectAttr(multNode + ".outputX", joint + ".translateX")
            index += 1

        cmds.setAttr(splineIKhandle + ".dTwistControlEnable", 1)
        cmds.setAttr(splineIKhandle + ".dWorldUpType", 4)
        cmds.setAttr(splineIKhandle + ".dWorldUpAxis", 5)

        cmds.setAttr(splineIKhandle + ".dWorldUpVector",
                     0.0,
                     0.0,
                     1.0,
                     type="double3")
        cmds.setAttr(splineIKhandle + ".dWorldUpVectorEnd",
                     0.0,
                     0.0,
                     1.0,
                     type="double3")

        if createRootControl:
            cmds.connectAttr(rootControlObject + ".worldMatrix[0]",
                             splineIKhandle + ".dWorldUpMatrix")
        else:
            dummyNode = cmds.duplicate(rootJoint,
                                       parentOnly=True,
                                       n=rootJoint + "_dummyDuplicate")[0]
            containedNodes.append(dummyNode)
            cmds.parent(dummyNode, moduleGrp, absolute=True)
            cmds.connectAttr(dummyNode + ".worldMatrix[0]",
                             splineIKhandle + ".dWorldUpMatrix")

        cmds.connectAttr(endControlObject + ".worldMatrix[0]",
                         splineIKhandle + ".dWorldUpMatrixEnd")
        # Create 2 attributes for "offsetY and offsetZ".
        cmds.select(moduleGrp)
        cmds.addAttr(at="float",
                     defaultValue=0.0,
                     softMinValue=-10.0,
                     softMaxValue=10.0,
                     keyable=True,
                     longName="offsetY")
        cmds.addAttr(at="float",
                     defaultValue=0.0,
                     softMinValue=-10.0,
                     softMaxValue=10.0,
                     keyable=True,
                     longName="offsetZ")
        # Publish new attrs to container
        self.publishNameToModuleContainer(moduleGrp + ".offsetY",
                                          "interpolator_offsetY",
                                          publishToOuterContainers=True)
        self.publishNameToModuleContainer(moduleGrp + ".offsetZ",
                                          "interpolator_offsetZ",
                                          publishToOuterContainers=True)
        # Create a node to inverse offset
        inverseNode = cmds.shadingNode("multiplyDivide",
                                       asUtility=True,
                                       n=moduleGrp + "_offsetInverse")
        containedNodes.append(inverseNode)

        cmds.connectAttr(moduleGrp + ".offsetY", inverseNode + ".input1Y")
        cmds.connectAttr(moduleGrp + ".offsetZ", inverseNode + ".input1Z")
        cmds.setAttr(inverseNode + ".input2Y", -1)
        cmds.setAttr(inverseNode + ".input2Z", -1)
        # Setup interpolators
        numStretchyIKJoints = len(stretchyIKJoints) - 1

        interpolators_ikParents = []
        aimChildren = []

        for i in range(1, numStretchyIKJoints):
            if i > 1:
                # Create a group to follow each joint
                jointFollower = cmds.group(empty=True,
                                           n=stretchyIKJoints[i] + "_follower")
                containedNodes.append(jointFollower)
                # Parent the group to the joint we are following
                cmds.parent(jointFollower, moduleGrp, relative=True)
                containedNodes.append(
                    cmds.parentConstraint(stretchyIKJoints[i],
                                          jointFollower,
                                          maintainOffset=False,
                                          n=jointFollower +
                                          "_parentConstraint")[0])

                offset = cmds.group(empty=True,
                                    n=stretchyIKJoints[i] +
                                    "_interpolatorOffset")
                containedNodes.append(offset)
                # parent the offset group to the follower group
                cmds.parent(offset, jointFollower, relative=True)

                cmds.connectAttr(moduleGrp + ".offsetY",
                                 offset + ".translateY")
                cmds.connectAttr(moduleGrp + ".offsetZ",
                                 offset + ".translateZ")

                name = utils.stripAllNamespaces(
                    joints[i])[1] + "_offsetControl"
                controlObjectInstance = controlObject.ControlObject()
                offsetControlObject = controlObjectInstance.create(
                    name,
                    "cubeLocator.ma",
                    self,
                    lod=2,
                    translation=True,
                    rotation=False,
                    globalScale=False,
                    spaceSwitching=False)[0]
                # parent control object under offset group
                cmds.parent(offsetControlObject, offset, relative=True)

                offsetCancelation = cmds.group(empty=True,
                                               n=stretchyIKJoints[i] +
                                               "interpolatorOffsetCancelation")
                containedNodes.append(offsetCancelation)
                cmds.parent(offsetCancelation,
                            offsetControlObject,
                            relative=True)

                cmds.connectAttr(inverseNode + ".outputY",
                                 offsetCancelation + ".translateY")
                cmds.connectAttr(inverseNode + ".outputZ",
                                 offsetCancelation + ".translateZ")

                interpolators_ikParents.append(offsetCancelation)

            aimChild = cmds.group(empty=True,
                                  n=stretchyIKJoints[i] + "_aimChild")
            containedNodes.append(aimChild)
            aimChildren.append(aimChild)

            if i > 1:
                cmds.parent(aimChild, offsetCancelation, relative=True)
                print "parent offset cancel"
            else:
                cmds.parent(aimChild, stretchyIKJoints[i], relative=True)

            cmds.setAttr(aimChild + ".translateY", -1)
        # Make use of interpolation nodes
        for i in range(1, numStretchyIKJoints):
            ikNodes = utils.basic_stretchy_IK(
                joints[i],
                joints[i + 1],
                container=moduleContainer,
                scaleCorrectionAttribute=self.blueprintNamespace +
                ":module_grp.hierarchicalScale",
                lockMinimumLength=False,
                poleVectorObject=aimChildren[i - 1])
            ikHandle = ikNodes["ikHandle"]
            rootLocator = ikNodes["rootLocator"]
            endLocator = ikNodes["endLocator"]

            for loc in (ikHandle, rootLocator):
                cmds.parent(loc, moduleGrp, absolute=True)

            utils.matchTwistAngle(ikHandle + ".twist", [
                joints[i],
            ], [
                stretchyIKJoints[i],
            ])

            if i == 1:
                if createRootControl:
                    containedNodes.append(
                        cmds.pointConstraint(rootControlObject,
                                             joints[i],
                                             maintainOffset=False,
                                             n=joints[i] +
                                             "_pointConstraint")[0])

            cmds.setAttr(endLocator + ".translate",
                         0.0,
                         0.0,
                         0.0,
                         type="double3")
            if i < numStretchyIKJoints - 1:
                cmds.parent(endLocator,
                            interpolators_ikParents[i - 1],
                            relative=True)
            else:
                cmds.parent(endLocator, endControlObject, relative=True)

        cmds.setAttr(moduleGrp + ".lod", 2)

        utils.addNodeToContainer(moduleContainer, containedNodes, ihb=True)
        # Publish joints to module container.
        for joint in stretchyIKJoints:
            jointName = utils.stripAllNamespaces(joint)[1]
            self.publishNameToModuleContainer(joint + ".rotate",
                                              jointName + "_R",
                                              publishToOuterContainers=False)
            self.publishNameToModuleContainer(joint + ".translate",
                                              jointName + "_T",
                                              publishToOuterContainers=False)
Ejemplo n.º 43
0
    def switchSpace(self,
                    targetObject,
                    spaceName,
                    index=-1,
                    maintainOffset=False,
                    setKeyframes=False):
        if cmds.objExists(targetObject + "_spaceSwitchTarget"):
            targetObject = targetObject + "_spaceSwitchTarget"

        setKeyframes = setKeyframes and maintainOffset

        currentPosition = cmds.xform(self.controlObject,
                                     q=True,
                                     worldSpace=True,
                                     translation=True)
        currentOrientation = cmds.xform(self.controlObject,
                                        q=True,
                                        worldSpace=True,
                                        rotation=True)
        currentScale = self.getCurrentScale()

        spaceSwitcher = self.controlObject + "_spaceSwitcher"
        animModuleNamespace = utils.stripAllNamespaces(self.controlObject)[0]

        if index == -1:
            cmds.select(spaceSwitcher)
            enumIndex = 0

            if cmds.attributeQuery("currentSpace",
                                   n=spaceSwitcher,
                                   exists=True):
                currentEntries = cmds.attributeQuery("currentSpace",
                                                     n=spaceSwitcher,
                                                     listEnum=True)[0]
                newEntry = currentEntries + ":" + spaceName
                cmds.addAttr(spaceSwitcher + ".currentSpace",
                             edit=True,
                             enumName=newEntry)

                enumIndex = len(currentEntries.split(":"))

            else:
                cmds.addAttr(at="enum",
                             enumName=spaceName,
                             keyable=True,
                             longName="currentSpace")

            if self.globalScale:
                scaleConstraint = cmds.scaleConstraint(targetObject,
                                                       spaceSwitcher,
                                                       n=spaceSwitcher +
                                                       "_scaleConstraint",
                                                       maintainOffset=False)[0]

            skipTranslate = "none"
            if cmds.getAttr(self.controlObject + ".switchOrientationOnly"):
                skipTranslate = ["x", "y", "z"]

            parentConstraint = cmds.parentConstraint(
                targetObject,
                spaceSwitcher,
                n=spaceSwitcher + "_parentConstraint",
                maintainOffset=False,
                skipTranslate=skipTranslate)[0]

            parentWeightList = cmds.parentConstraint(parentConstraint,
                                                     q=True,
                                                     weightAliasList=True)
            parentWeight = parentConstraint + "." + parentWeightList[
                len(parentWeightList) - 1]

            attrs = [(parentWeight, "parent")]
            containedNodes = [parentConstraint]

            if self.globalScale:
                scaleWeightList = cmds.scaleConstraint(scaleConstraint,
                                                       q=True,
                                                       weightAliasList=True)
                scaleWeight = scaleConstraint + "." + scaleWeightList[
                    len(scaleWeightList) - 1]

                attrs.append((scaleWeight, "scale"))
                containedNodes.append(scaleConstraint)

            for attr in attrs:
                expressionString = attr[
                    0] + " = (" + spaceSwitcher + ".currentSpace == " + str(
                        enumIndex) + ");\n"
                expressionName = spaceSwitcher + "_" + attr[
                    1] + "WeightExpression_" + str(enumIndex)
                containedNodes.append(
                    cmds.expression(name=expressionName,
                                    string=expressionString))

            utils.addNodeToContainer(animModuleNamespace + ":module_container",
                                     containedNodes)

            index = enumIndex

        transformAttributes = ([self.translation[0], "translateX"], [
            self.translation[1], "translateY"
        ], [self.translation[2],
            "translateZ"], [self.rotation[0],
                            "rotateX"], [self.rotation[1], "rotateY"],
                               [self.rotation[2],
                                "rotateZ"], [self.globalScale, "globalScale"])
        currentTime = cmds.currentTime(q=True)
        if setKeyframes:
            for attribute in transformAttributes:
                if attribute[0]:
                    if not cmds.selectKey(self.controlObject,
                                          attribute=attribute[1],
                                          time=(currentTime - 1, )) > 0:
                        value = cmds.getAttr(self.controlObject + "." +
                                             attribute[1],
                                             time=currentTime - 1)
                        cmds.setKeyframe(self.controlObject,
                                         attribute=attribute[1],
                                         time=currentTime - 1,
                                         value=value,
                                         outTangentType="step")

        cmds.setAttr(spaceSwitcher + ".currentSpace", index)
        cmds.setKeyframe(spaceSwitcher, at="currentSpace", ott="step")
        utils.addNodeToContainer(animModuleNamespace + ":module_container",
                                 spaceSwitcher + "_currentSpace")

        if maintainOffset:
            if self.globalScale == True:
                newScale = self.getCurrentScale()
                scaleRatio = newScale / currentScale
                newScaleAttributeValue = cmds.getAttr(self.controlObject +
                                                      ".scaleY") / scaleRatio
                cmds.setAttr(self.controlObject + ".scaleY",
                             newScaleAttributeValue)

            if self.rotation == [True, True, True]:
                cmds.xform(self.controlObject,
                           ws=True,
                           a=True,
                           rotation=currentOrientation)

            if self.translation == [True, True, True]:
                cmds.xform(self.controlObject,
                           ws=True,
                           a=True,
                           translation=currentPosition)

        if setKeyframes:
            for attribute in transformAttributes:
                if attribute[0]:
                    cmds.setKeyframe(self.controlObject,
                                     attribute=attribute[1])
	def setupBlueprintWeightBasedBlending(self):
		settingsLocator = self.blueprintNamespace + ':SETTINGS'
		
		attributes = cmds.listAttr(settingsLocator, keyable=False)
		weightAttributes = []
		for attr in attributes:
			if attr.find('_weight') != -1:
				weightAttributes.append(attr)
				
		value = 0
		if len(weightAttributes) == 0:
			value = 1
			cmds.setAttr(settingsLocator + '.creationPoseWeight',0)
			
		cmds.select(settingsLocator)
		weightAttributeName = self.moduleNamespace + '_weight'
		cmds.addAttr(ln=weightAttributeName, at='double', min=0, max=1, defaultValue=value, keyable=False)
		
		cmds.container(self.blueprintNamespace + ':module_container', edit=True, publishAndBind=[settingsLocator + '.' + weightAttributeName, weightAttributeName])
		
		currentEntries = cmds.attributeQuery('activeModule', n=settingsLocator, listEnum=True)
		
		newEntry = self.moduleNamespace
		
		if currentEntries[0] == 'None':
			cmds.addAttr(settingsLocator + '.activeModule', edit=True, enumName=newEntry)
			cmds.setAttr(settingsLocator + '.activeModule', 0)
		else:
			cmds.addAttr(settingsLocator + '.activeModule', edit=True, enumName=currentEntries[0] + ':' + newEntry)
			
		utilityNodes = []
		for i in range(1,len(self.joints)):
			joint = self.joints[i]
			
			nameSuffix = utils.stripAllNamespaces(joint)[1]
			blueprintJoint = self.blueprintNamespace + ':blueprint_' + nameSuffix
			
			weightNodeAttr = settingsLocator + '.' + weightAttributeName
			
			if i < len(self.joints) - 1 or len(self.joints) == 2:
				multiplyRotations = cmds.shadingNode('multiplyDivide', n=joint + '_multiplyRotationsWeight', asUtility=True)
				utilityNodes.append(multiplyRotations)
				cmds.connectAttr(joint + '.rotate',multiplyRotations + '.input1',force=True)
				
				
				for attr in ['input2X','input2Y','input2Z']:
					cmds.connectAttr(weightNodeAttr,multiplyRotations + '.' + attr, force=True)
					
				index = utils.findFirstFreeConnection(blueprintJoint + '_addRotations.input3D')
				cmds.connectAttr(multiplyRotations + '.output', blueprintJoint+'_addRotations.input3D[' + str(index) + ']')
				
			if i == 1:
				addNode = blueprintJoint + '_addTranslate'
				if cmds.objExists(addNode):
					multiplyTranslation = cmds.shadingNode('multiplyDivide',n=joint + '_multiplyTranslationWeight',asUtility=True)
					utilityNodes.append(multiplyTranslation)
					
					cmds.connectAttr(joint + '.translate', multiplyTranslation+'.input1', force=True)
					for attr in ['input2X','input2Y','input2Z']:
						cmds.connectAttr(weightNodeAttr,multiplyTranslation + '.' + attr,force=True)
						
					index = utils.findFirstFreeConnection(addNode + '.input3D')
					cmds.connectAttr(multiplyTranslation + '.output', addNode + '.input3D[' + str(index) + ']', force=True)
					
				addNode = blueprintJoint + '_addScale'
				if cmds.objExists(addNode):
					multiplyScale = cmds.shadingNode('multiplyDivide', n=joint + '_multiplyScaleWeight', asUtility=True)
					utilityNodes.append(multiplyScale)
					
					cmds.connectAttr(joint + '.scale', multiplyScale + '.input1', force=True)
					for attr in ['input2X','input2Y','input2Z']:
						cmds.connectAttr(weightNodeAttr,multiplyScale+'.' + attr, force=True)
						
					index = utils.findFirstFreeConnection(addNode + '.input3D')
					cmds.connectAttr(multiplyScale + '.output',addNode + '.input3D[' + str(index) + ']' , force=True)
			else:
				multiplyTranslation = cmds.shadingNode('multiplyDivide', n=joint + '_multiplyTranslationWeight', asUtility=True)
				utilityNodes.append(multiplyTranslation)
				
				cmds.connectAttr(joint + '.translateX', multiplyTranslation + '.input1X', force=True)
				cmds.connectAttr(weightNodeAttr,multiplyTranslation + '.input2X', force=True)
				
				addNode = blueprintJoint + '_addTx'
				index = utils.findFirstFreeConnection(addNode + '.input1D')
				cmds.connectAttr(multiplyTranslation + '.outputX', addNode + '.input1D[' + str(index) + ']', force=True)
				
		return utilityNodes
	def duplicateControlModule(self,withAnimation=True):
		characterContainer = self.characterNamespaceOnly + ':character_container'
		blueprintContainer = self.blueprintNamespace + ':module_container'
		moduleContainer = self.moduleContainer
		
		containers = [characterContainer, blueprintContainer,moduleContainer]
		for c in containers:
			cmds.lockNode(c, lock=False, lockUnpublished=False)
			
		cmds.namespace(setNamespace=self.blueprintNamespace + ':' + self.moduleNamespace)
		allAnimationNodes = cmds.namespaceInfo(listOnlyDependencyNodes=True)
		allAnimationNodes = cmds.ls(allAnimationNodes, type='animCurve')
		
		containedAnimationNodes = cmds.container(moduleContainer, q=True, nodeList=True)
		containedAnimationNodes = cmds.ls(containedAnimationNodes, type='animCurve')
		
		animationNodes = []
		spaceSwitchAnimationNodes = []
		
		for node in allAnimationNodes:
			if not node in containedAnimationNodes:
				animationNodes.append(node)
			else:
				if node.rpartition('_')[2] == 'currentSpace':
					spaceSwitchAnimationNodes.append(node)
					
		cmds.namespace(setNamespace=':')
		
		utils.addNodeToContainer(moduleContainer, animationNodes)
		
		cmds.namespace(addNamespace='TEMP')
		cmds.namespace(setNamespace='TEMP')
		
		cmds.duplicate(moduleContainer, inputConnections=True)
		
		cmds.namespace(setNamespace=':'+self.blueprintNamespace)
		moduleNamespaces = cmds.namespaceInfo(listOnlyNamespaces=True)
		
		baseModuleNamespace = self.moduleNamespace.rpartition('_')[0] + '_'
		baseNamespace = self.blueprintNamespace + ':' + baseModuleNamespace
		
		highestSuffix = utils.findHighestTrailingNumber(moduleNamespaces, baseNamespace)
		highestSuffix += 1
		
		newModuleNamespace = baseModuleNamespace + str(highestSuffix)
		
		cmds.namespace(addNamespace=newModuleNamespace)
		cmds.namespace(setNamespace=':')
		
		cmds.namespace(moveNamespace=['TEMP',self.blueprintNamespace+':'+newModuleNamespace])
		cmds.namespace(removeNamespace='TEMP')
		
		oldModuleNamespace = self.moduleNamespace
		self.moduleNamespace = newModuleNamespace
		
		newModuleContainer = self.blueprintNamespace + ':' + self.moduleNamespace + ':module_container'
		utils.addNodeToContainer(blueprintContainer, newModuleContainer)
		
		publishedNameList = []
		
		publishedNames = cmds.container(newModuleContainer, q=True, publishName=True)
		for name in publishedNames:
			drivenAttribute = cmds.connectionInfo(newModuleContainer + '.' + name, getExactSource=True)
			publishedNameList.append((name,drivenAttribute))
			
			
		for name in publishedNameList:
			cmds.container(newModuleContainer,edit=True, unbindAndUnpublish=name[1])
			
			nameInfo = name[0].partition(oldModuleNamespace)
			newName = nameInfo[0] + self.moduleNamespace + nameInfo[2]
			
			cmds.container(newModuleContainer,edit=True,publishAndBind=[name[1],newName])
			
		self.moduleContainer = moduleContainer
		oldPublishedNames = self.findAllNamesPublishedToOuterContainers()
		newPublishedNames = []
		
		for name in oldPublishedNames:
			nameInfo = name.partition(oldModuleNamespace)
			newPublishedNames.append((nameInfo[0] + self.moduleNamespace + nameInfo[2]))
			
		self.publishedNames = list(newPublishedNames)
		self.moduleContainer = newModuleContainer
		self.publishModuleContainerNamesToOuterContainers()
		
		deleteNodes = []
		
		moduleJointsGrp = self.blueprintNamespace + ':' + self.moduleNamespace + ':joints_grp'
		self.joints = utils.findJointChain(moduleJointsGrp)
		
		for joint in self.joints:
			if cmds.objExists(joint + '_multiplyRotationsWeight'):
				deleteNodes.append(joint + '_multiplyRotationsWeight')
				
			if cmds.objExists(joint + '_multiplyTranslationWeight'):
				deleteNodes.append(joint + '_multiplyTranslationWeight')
				
			if cmds.objExists(joint + '_multiplyScaleWeight'):
				deleteNodes.append(joint + '_multiplyScaleWeight')
				
		cmds.delete(deleteNodes, inputConnectionsAndNodes=False)
		
		utilityNodes = self.setupBlueprintWeightBasedBlending()
		utils.addNodeToContainer(newModuleContainer, utilityNodes)
		
		cmds.container(moduleContainer,edit=True, removeNode=animationNodes)
		cmds.container(blueprintContainer,edit=True, removeNode=animationNodes)
		cmds.container(characterContainer,edit=True, removeNode=animationNodes)
		
		newAnimationNodes = []
		for node in animationNodes:
			nodeName = utils.stripAllNamespaces(node)[1]
			newAnimationNodes.append(self.blueprintNamespace+':'+self.moduleNamespace+':'+nodeName)
			
		newSpaceSwitchAnimationNodes = []
		for node in newSpaceSwitchAnimationNodes:
			nodeName = utils.stripAllNamespaces(node)[1]
			newSpaceSwitchAnimationNodes.append(self.blueprintNamespace+':'+self.moduleNamespace+':'+nodeName)
			
		if withAnimation:
			cmds.container(newModuleContainer,edit=True, removeNode=newAnimationNodes)
			cmds.container(blueprintContainer,edit=True, removeNode=newAnimationNodes)
			cmds.container(characterContainer,edit=True, removeNode=newAnimationNodes)
		else:
			if len(newAnimationNodes) >0:
				cmds.delete(newAnimationNodes)
				
			if len(newSpaceSwitchAnimationNodes) > 0:
				cmds.delete(newSpaceSwitchAnimationNodes)
				
		containers.append(newModuleContainer)
		for c in containers:
			cmds.lockNode(c,lock=True,lockUnpublished=True)
Ejemplo n.º 46
0
    def processGroup(self, group, parent):
        import System.groupSelected as groupSelected

        tempGroup = cmds.duplicate(group,
                                   parentOnly=True,
                                   inputConnections=True)[0]
        emptyGroup = cmds.group(empty=True)
        cmds.parent(tempGroup, emptyGroup, absolute=True)
        #scale based on mirrorPlane plane
        scaleAxis = ".scaleX"
        if self.mirrorPlane == "XZ":
            scaleAxis = ".scaleY"
        elif self.mirrorPlane == "XY":
            scaleAxis = ".scaleZ"

        cmds.setAttr(emptyGroup + scaleAxis, -1)

        # Instance of groupSelected class
        instance = groupSelected.GroupSelected()
        groupSuffix = group.partition("__")[2]
        # Take group suffix, target, and parent.  Create a new group that matches orientation and scale.
        newGroup = instance.createGroupAtSpecified(groupSuffix + "_mirror",
                                                   tempGroup, parent)

        # Lock container and delete empty group
        cmds.lockNode("Group_container", lock=False, lockUnpublished=False)
        cmds.delete(emptyGroup)

        #085
        for moduleLink in ((group, newGroup), (newGroup, group)):
            attributeValue = moduleLink[1] + "__"

            if self.mirrorPlane == "YZ":
                attributeValue += "X"
            elif self.mirrorPlane == "XZ":
                attributeValue += "Y"
            elif self.mirrorPlane == "XY":
                attributeValue += "Z"

            cmds.select(moduleLink[0])
            cmds.addAttr(dt="string", longName="mirrorLinks", k=False)
            cmds.setAttr(moduleLink[0] + ".mirrorLinks",
                         attributeValue,
                         type="string")

        cmds.select(clear=True)

        # Search for children of the groups.  Is child a group or module transform?
        children = cmds.listRelatives(group, children=True)
        children = cmds.ls(children, transforms=True)

        for child in children:
            if child.find("Group__") == 0:
                self.processGroup(child, newGroup)
            else:
                childNamespaces = utils.stripAllNamespaces(child)
                if childNamespaces != None and childNamespaces[
                        1] == "module_transform":
                    for module in self.moduleInfo:
                        if childNamespaces[0] == module[0]:
                            moduleContainer = module[1] + ":module_container"
                            cmds.lockNode(moduleContainer,
                                          lock=False,
                                          lockUnpublished=False)

                            moduleTransform = module[1] + ":module_transform"
                            cmds.parent(moduleTransform,
                                        newGroup,
                                        absolute=True)

                            cmds.lockNode(moduleContainer,
                                          lock=True,
                                          lockUnpublished=True)
Ejemplo n.º 47
0
	def install_custom(self,joints,moduleGrp,moduleContainer):
		containedNodes = []
		rootJoint = joints[1]
		endJoint = joints[len(joints) -1]
		
		ikNodes = utils.basic_stretchy_IK(rootJoint, endJoint, container=moduleContainer, scaleCorrectionAttribute=self.blueprintNamespace+':module_grp.hierarchicalScale')
		ikHandle = ikNodes['ikHandle']
		rootLocator = ikNodes['rootLocator']
		endLocator = ikNodes['endLocator']
		poleVectorLocator = ikNodes['poleVectorObject']
		stretchinessAttribute = ikNodes['stretchinessAttribute']
		
		for node in [rootLocator, ikHandle, poleVectorLocator]:
			cmds.parent(node, moduleGrp, absolute=True)
			
		name = 'ikHandleControl'
		
		controlObjectInstance = controlObject.ControlObject()
		handleControlInfo = controlObjectInstance.create(name, 'cubeLocator.ma', self , lod=1, translation=True, rotation=True, globalScale=False, spaceSwitching=True)
		handleControl = handleControlInfo[0]
		handleRootParent = handleControlInfo[1]
		
		cmds.parent(handleRootParent, moduleGrp, relative=True)
		
		cmds.xform(handleControl, worldSpace=True, absolute=True, translation=cmds.xform(endLocator, q=True, worldSpace=True, translation=True))
		
		cmds.parent(endLocator, handleControl, absolute=True)
		
		handleControlParent = cmds.listRelatives(handleControl, parent=True)[0]
		preTransform = cmds.group(empty=True, n=handleControl+'_preTransform')
		containedNodes.append(preTransform)
		
		cmds.parent(preTransform, handleControl, relative=True)
		cmds.parent(preTransform, handleControlParent, absolute=True)
		cmds.parent(handleControl, preTransform, absolute=True)
		
		cmds.select(handleControl)
		cmds.addAttr(at='float', minValue=0.0, maxValue=1.0, defaultValue=1.0, keyable=True, longName='stretchiness')
		cmds.addAttr(at='float', softMinValue=360.0, softMaxValue=360.0, defaultValue=0.0, keyable=True, longName='twist')
		
		cmds.connectAttr(handleControl+'.twist', ikHandle+'.twist')
		cmds.connectAttr(handleControl+'.stretchiness', stretchinessAttribute)
		
		self.publishNameToModuleContainer(handleControl+'.twist', 'twist', publishToOuterContainers=True)
		self.publishNameToModuleContainer(handleControl+'.stretchiness', 'stretchiness', publishToOuterContainers=True)
		
		
		jointName = utils.stripAllNamespaces(rootJoint)[1]
		ikJoints = utils.findJointChain(rootJoint)
		targetJoints = utils.findJointChain(self.blueprintNamespace+':creationPose_'+jointName)
		
		utils.matchTwistAngle(handleControl+'.twist',ikJoints,targetJoints)
		
		offsetNode = cmds.shadingNode('plusMinusAverage', asUtility=True, n=handleControl+'_twistOffset')
		containedNodes.append(offsetNode)
		
		cmds.setAttr(offsetNode+'.input1D[0]',cmds.getAttr(handleControl+'.twist'))
		cmds.connectAttr(handleControl+'.twist', offsetNode+'.input1D[1]')
		cmds.connectAttr(offsetNode+'.output1D', ikHandle+'.twist', force=True)
		
		cmds.setAttr(handleControl+'.twist',0.0)
		

		
		utils.addNodeToContainer(moduleContainer,containedNodes)
Ejemplo n.º 48
0
    def install_custom(self, joints, moduleGrp, moduleContainer):
        moduleNamespace = self.blueprintNamespace + ":" + self.moduleNamespace
        
        """ Assign the joint indices to a variable """
        ankleJoint = joints[3]
        ballJoint = joints[4]
        toeJoint = joints[5]
        """ Create a list of objects that need to be added to a namespace """
        namespaceObjects = []
        
        """ Get the module positions by creating a temp locator which is parented to each module in turn.
        Use xform on the locator and save it's position to a new variable.
        """
        
        """ Temp locator used to get the module positions """
        tempLocator = cmds.spaceLocator()[0]
        
        """ Ball Joint """   
        cmds.parent(tempLocator, ballJoint, relative=True)
        cmds.parent(tempLocator, moduleGrp, absolute=True)  
        ballJoint_modulePos = [cmds.getAttr(tempLocator+".translateX"), cmds.getAttr(tempLocator+".translateY"), cmds.getAttr(tempLocator+".translateZ")]
       
        """ Ankle Joint """
        cmds.parent(tempLocator, ankleJoint)
        for attr in [".translateX", ".translateY", ".translateZ"]:
            cmds.setAttr(tempLocator+attr, 0)
        cmds.parent(tempLocator, moduleGrp, absolute=True)
        ankleJoint_modulePos = [cmds.getAttr(tempLocator+".translateX"), cmds.getAttr(tempLocator+".translateY"), cmds.getAttr(tempLocator+".translateZ")]
 
        """ Toe Joint """
        cmds.parent(tempLocator, toeJoint)
        for attr in [".translateX", ".translateY", ".translateZ"]:
            cmds.setAttr(tempLocator+attr, 0)
        cmds.parent(tempLocator, moduleGrp, absolute=True) 
        toeJoint_modulePos = [cmds.getAttr(tempLocator+".translateX"), cmds.getAttr(tempLocator+".translateY"), cmds.getAttr(tempLocator+".translateZ")]
        
        """ Delete the temp locator """
        cmds.delete(tempLocator)  
        
        """ containedNodes is an empty list that will store all the nodes that should be added to the animation module container """
        containedNodes = []

        """ Pass in functionality from basic IK """    
        ikNodes = circleIK.CircleControlStretchyIK.install_custom(self, joints, moduleGrp, moduleContainer, createHandleControl=False, poleVectorAtRoot=False)
        ikEndPosLocator = ikNodes["endLocator"]
        ikPoleVectorLocator = ikNodes["poleVectorObject"]
        #namespaceObjects.append(ikEndPosLocator)
        #namespaceObjects.append(ikPoleVectorLocator)
        
        stretchinessAttribute = ikNodes["stretchinessAttribute"]
        
        """ Import the foot control """
        name = "footControl"
        controlObjectInstance = controlObject.ControlObject()
        footControlInfo = controlObjectInstance.create(name, "footControl.ma", self, lod=1, translation=True, rotation=True, globalScale=False, spaceSwitching=True)
        footControl = footControlInfo[0]
        footControlRootParent = footControlInfo[1]

        """ Create control attributes on the foot control """
        footControlAttributes = ('roll', 'roll_break', 'toe_twist', 'ball_twist', 'heel_twist', 'bank', 'toe_flap')
        cmds.select(footControl)
        for attr in footControlAttributes:
            cmds.addAttr(shortName=attr, defaultValue=0.0, k=True)
            self.publishNameToModuleContainer(footControl + '.' + attr, attr, publishToOuterContainers=True)

        #footControlAttributes = ('pv_follow')
        #cmds.select(footControl) 

        #cmds.addAttr(shortName=footControlAttributes[0], at='enum', en='off:on', k=True)
        """ Publish attributes to the top level character container """
        #self.publishNameToModuleContainer(footControl + '.' + attr, attr, publishToOuterContainers=True)
            
   

        """ Parent foot control to root parent"""
        cmds.parent(footControlRootParent, moduleGrp, relative=True)
        
        """ Position and orient foot control"""
        footControlPos = [ankleJoint_modulePos[0], ballJoint_modulePos[1], ankleJoint_modulePos[2]]
        cmds.xform(footControl, objectSpace=True, absolute=True, translation=footControlPos)
        
        """ Position the foot control pivot at the ankle """
        cmds.xform(footControl, ws=True, p=True, piv=[ankleJoint_modulePos[0], ankleJoint_modulePos[1], ankleJoint_modulePos[2]])  
 
        cmds.setAttr(footControl+".rotateOrder", 3) #3 = xyz
        
        orientationVector = [toeJoint_modulePos[0] - ankleJoint_modulePos[0], toeJoint_modulePos[2] - ankleJoint_modulePos[2] ]
        
        footControlRotation = atan2(orientationVector[1], orientationVector[0])
        cmds.setAttr(footControl+".rotateY", -degrees(footControlRotation))
        
        # Hookup stretchiness attribute
        cmds.select(footControl)
        cmds.addAttr(at="float", minValue=0.0, maxValue=1.0, defaultValue=1.0, keyable=True, longName="stretchiness")
        self.publishNameToModuleContainer(footControl+".stretchiness", "stretchiness", publishToOuterContainers=True)
        
        cmds.connectAttr(footControl+".stretchiness", stretchinessAttribute, force=True)
  
        """ Setup for ball and Toe controls"""
        ballToeControls = []
        ballToeControl_orientGrps = []
        rootParents =  []
        for joint in [ankleJoint, ballJoint]:
            controlObjectInstance = controlObject.ControlObject()
            jointName = utils.stripAllNamespaces(joint)[1]
            name = jointName + "_pivotControl"
            
            ryControlInfo = controlObjectInstance.create(name, "needleControl.ma", self, lod=2, translation=True, rotation=False, globalScale=False, spaceSwitching=False)
            ryControl = ryControlInfo[0]
            ryControlRootParent = ryControlInfo[0]
            
            ballToeControls.append(ryControl)
            rootParents.append(ryControlInfo[0])
            
            orientGrp = cmds.group(empty=True, n=ryControl+"_orientGrp")
            containedNodes.append(orientGrp)
            ballToeControl_orientGrps.append(orientGrp)
 
            cmds.parent(ryControl, orientGrp, relative=True)
    
            
        cmds.xform(ballToeControl_orientGrps[0], objectSpace=True, absolute=True, translation=ankleJoint_modulePos)
        cmds.xform(ballToeControl_orientGrps[1], objectSpace=True, absolute=True, translation=ballJoint_modulePos)

        heelControlRootParent = rootParents[0]
        bankControlRootParent = rootParents[1]
     
        for grp in ballToeControl_orientGrps:
            cmds.parent(grp, moduleGrp, absolute=True)
            
        """ This aligns the leg """
        #cmds.parent(ikEndPosLocator, ballToeControls[0], absolute=True)
        
        """ Ankle IK """
        ankleIKNodes = cmds.ikHandle(sj=ankleJoint, ee=ballJoint, solver="ikSCsolver", n=ankleJoint+"_ikHandle")
        ankleIKNodes[1] = cmds.rename(ankleIKNodes[1], ankleIKNodes[1]+"_ikEffector")
        containedNodes.extend(ankleIKNodes)
        namespaceObjects.append(ankleIKNodes[0])
        namespaceObjects.append(ankleIKNodes[1])
        
        
        cmds.setAttr(ankleIKNodes[0]+".visibility", 0)
        
        """ Ball IK  """
        ballIKNodes = cmds.ikHandle(sj=ballJoint, ee=toeJoint, solver="ikSCsolver", n=ballJoint+"_ikHandle")
        ballIKNodes[1] = cmds.rename(ballIKNodes[1], ballIKNodes[1]+"_ikEffector")
        containedNodes.extend(ballIKNodes)
        namespaceObjects.append(ballIKNodes[0])
        namespaceObjects.append(ballIKNodes[1])
        
        cmds.setAttr(ballIKNodes[0]+".visibility", 0)
                 
        utils.addNodeToContainer(moduleContainer, containedNodes, ihb=True)
        
        
        """ Empty the contained nodes list """
        containedNodes = []

   
        """ Create the IK_Groups """
        ikGroups = []
        
        """ These groups go at the ankle """
        ikGrp = cmds.group(em=True, name='footIK_grp')
        cmds.xform(ikGrp, a=True, t=ankleJoint_modulePos)
        ikGroups.append(ikGrp)
        containedNodes.append(ikGrp)
        
        """ These go at the ball """
        groupNames = ('bank_grp', 'ballTwist_grp', 'ballRoll_grp', 'toeFlap_grp')
        for group in groupNames:
            cmds.group(em=True, name=group)
            cmds.xform(group, a=True, t=ballJoint_modulePos)
            ikGroups.append(group)
            containedNodes.append(group)
  
        """ These go at the toe """
        ikGrp = cmds.group(em=True, name='toeRoll_grp')
        cmds.xform(ikGrp, a=True, t=toeJoint_modulePos)
        ikGroups.append(ikGrp)
        containedNodes.append(ikGrp)
        
        """ Create a heel roll group """
        """ TODO:  How do I get this to sit at the heel without adding a joint for it? """
        ikGrp = cmds.group(em=True, name='heelRoll_grp')
        cmds.xform(ikGrp, a=True, t=(ankleJoint_modulePos[0], 0, ankleJoint_modulePos[2]) )
        ikGroups.append(ikGrp)
        containedNodes.append(ikGrp)
     
        """ Create 3 locators to be used for roll attribute """
        rollLctrs = []
        dynRollLctr = cmds.spaceLocator(name='dynRoll_lctr')[0]
        cmds.xform(dynRollLctr, a=True, t=ballJoint_modulePos)
        rollLctrs.append(dynRollLctr)
        containedNodes.append(dynRollLctr)
        
        statRollLctr = cmds.spaceLocator(name='statRoll_lctr')[0]
        cmds.xform(statRollLctr, a=True, t=ballJoint_modulePos)
        rollLctrs.append(statRollLctr)
        containedNodes.append(statRollLctr)
        
        """ heelRoll_lctr """
        heelRollLctr = cmds.spaceLocator(name='heelRoll_lctr')[0]
        cmds.xform(heelRollLctr, a=True, t=ballJoint_modulePos)
        rollLctrs.append(heelRollLctr)
        containedNodes.append(heelRollLctr)
        
        for locator in rollLctrs:
            cmds.setAttr(locator + '.visibility', 0) 
            
        """ Parent the adjustment controls to the foot control """
        cmds.parent(heelControlRootParent , ikGroups[3], absolute=True)
        cmds.makeIdentity(heelControlRootParent, apply=True, translate=True )        
        cmds.parent(bankControlRootParent , ikGroups[3], absolute=True)
        
        """ Parent the ikHandles under the appropriate group """
        cmds.parent(ankleIKNodes[0], ikGroups[3])
        cmds.parent(ikEndPosLocator, ikGroups[3])
        
        cmds.parent(ballIKNodes[0], ikGroups[4])
        
        cmds.parent(ikGroups[3], ikGroups[5]) #ballRoll  toeRoll  
        cmds.parent(ikGroups[4], ikGroups[5]) #toeFlap toeRoll   
        cmds.parent(ikGroups[5], ikGroups[2]) #toeRoll  ballTwist  
        cmds.parent(ikGroups[2], ikGroups[1]) #ballTwist  bank  
        cmds.parent(ikGroups[1], ikGroups[6]) #bank  heelRoll
        cmds.parent(ikGroups[6], ikGroups[0]) #heelRoll  footIK
        
        cmds.parent(dynRollLctr, ikGroups[0])
        cmds.parent(heelRollLctr, ikGroups[0])
        cmds.parent(statRollLctr, ikGroups[6])
        
        """ Parent constrain ball and toe groups to roll_lctrs """
        parentConstraints = []
        rollParentConstraint = cmds.parentConstraint(dynRollLctr, ikGroups[3], mo=True, st=('x', 'y', 'z'), sr=('y', 'z'))
        parentConstraints.append(rollParentConstraint[0])
        rollParentConstraint = cmds.parentConstraint(statRollLctr, ikGroups[3], mo=True, st=('x', 'y', 'z'), sr=('y', 'z'))
        parentConstraints.append(rollParentConstraint[0])
        rollParentConstraint = cmds.parentConstraint(statRollLctr, ikGroups[5], mo=True, st=('x', 'y', 'z'), sr=('y', 'z'))
        parentConstraints.append(rollParentConstraint[0])
        rollParentConstraint = cmds.parentConstraint(dynRollLctr, ikGroups[5], mo=True, st=('x', 'y', 'z'), sr=('y', 'z'))
        parentConstraints.append(rollParentConstraint[0])
        
        for constraint in parentConstraints:
            print constraint
            newName = moduleNamespace+':'+constraint
            cmds.rename(constraint, newName)
        
        
        """ Create a remap value node to control foot roll """
        cmds.createNode('remapValue', name ='roll_rv')
        cmds.setAttr('roll_rv.inputMax', 180.0)
        """ Connect to the remap value node """
        """" Connect the output of dynRollLctr to roll_rv input value """
        cmds.connectAttr(dynRollLctr + '.rx', 'roll_rv.inputValue' )
        """ roll_break to input min """
        cmds.setAttr(footControl + '.roll_break', 45.0)
        cmds.connectAttr(footControl + '.roll_break', 'roll_rv.inputMin')
        """ roll_break to parent constraint switches """
        cmds.connectAttr('roll_rv.outColorG', ikGroups[3] + '.blendParent2')
        cmds.connectAttr('roll_rv.outColorR', ikGroups[5] + '.blendParent2')
        namespaceObjects.append('roll_rv')
    
        """ constrain the heelRoll_grp to heelRoll_lctr.  Switch off the constraint when greater than 0 """
        cmds.createNode('condition', name='roll_cond')
        heelOrientConstraint = cmds.orientConstraint(heelRollLctr, ikGroups[6], skip=('y', 'z'), mo=True)
        heelOrientAttr = (heelOrientConstraint[0] + '.' + heelRollLctr +'W0')
        cmds.connectAttr('roll_cond.outColorR', heelOrientAttr)
        cmds.connectAttr(heelRollLctr + '.rx', 'roll_cond.firstTerm')
        cmds.setAttr('roll_cond.operation', 3)
        newName = moduleNamespace+':'+heelOrientConstraint[0]
        cmds.rename(heelOrientConstraint[0], newName)
        namespaceObjects.append('roll_cond')
        
        """ Connect the foot attributes to respective groups and locators """
        cmds.connectAttr(footControl + ".roll", heelRollLctr + '.rx')
        cmds.connectAttr(footControl + ".roll", 'dynRoll_lctr.rx')
        cmds.connectAttr(footControl + ".toe_twist", 'toeRoll_grp.ry')
        cmds.connectAttr(footControl + ".ball_twist", 'ballTwist_grp.ry')
        cmds.connectAttr(footControl + ".heel_twist", 'heelRoll_grp.ry')
        cmds.connectAttr(footControl + ".bank", 'bank_grp.rz')
        cmds.connectAttr(footControl + ".toe_flap", 'toeFlap_grp.rx')
        
        """ Connect pivot controls to the rotatePivot of appropriate group """
        cmds.connectAttr(rootParents[1]+'.translate', 'bank_grp.rotatePivot')
        cmds.connectAttr(rootParents[0]+'.translate', 'heelRoll_grp.rotatePivot')
        
        """ Parent the footIK_grp to the foot control """
        cmds.parent('footIK_grp', footControl, absolute=True)

        utils.addNodeToContainer(moduleContainer, containedNodes, ihb=True)
        
        for node in containedNodes:
            newName = moduleNamespace+':'+node
            cmds.rename(node, newName)
            
            
        """ Add the namespaceObjects to the moduleNamespace """
        
        for node in namespaceObjects:
            print node
            newName = moduleNamespace+':'+node
            cmds.rename(node, newName)
Ejemplo n.º 49
0
    def objectSelected(self):
        print "objectSelected 58"
        objects = cmds.ls(selection=True)

        cmds.select(clear=True)
        """ Find the installed characters """
        characters = utils.findInstalledCharacters()
        """ Unlock the containers """
        for character in characters:
            characterContainer = character + ":character_container"
            cmds.lockNode(characterContainer,
                          lock=False,
                          lockUnpublished=False)
            # Find every module installed on that character.
            blueprintInstances = utils.findInstalledBlueprintInstances(
                character)

            for blueprintInstance in blueprintInstances:
                moduleContainer = character + ":" + blueprintInstance + ":module_container"
                cmds.lockNode(moduleContainer,
                              lock=False,
                              lockUnpublished=False)
                """ Do we have modules installed?  If so, set the joint color to blue. """
                blueprintJointsGrp = character + ":" + blueprintInstance + ":blueprint_joints_grp"

                if cmds.getAttr(blueprintJointsGrp +
                                ".controlModulesInstalled"):
                    #Blue
                    cmds.setAttr(blueprintJointsGrp + ".overrideColor", 6)
                else:
                    cmds.setAttr(blueprintJointsGrp + ".overrideColor", 2)

                cmds.lockNode(moduleContainer, lock=True, lockUnpublished=True)

            cmds.lockNode(characterContainer, lock=True, lockUnpublished=True)

        if len(objects) > 0:
            lastSelected = objects[len(objects) - 1]

            lastSelected_stripNamespaces = utils.stripAllNamespaces(
                lastSelected)

            if lastSelected_stripNamespaces != None:
                lastSelected_withoutNamespaces = lastSelected_stripNamespaces[
                    1]

                if lastSelected_withoutNamespaces.find("blueprint_") == 0:
                    blueprintModuleNamespace_incCharNamespace = lastSelected_stripNamespaces[
                        0]
                    moduleContainer = blueprintModuleNamespace_incCharNamespace + ":module_container"

                    cmds.select(moduleContainer, replace=True)

                    # set color of the joints
                    characterNamespace = utils.stripLeadingNamespace(
                        lastSelected)[0]

                    characterContainer = characterNamespace + ":character_container"

                    containers = [characterContainer, moduleContainer]
                    for container in containers:
                        cmds.lockNode(container,
                                      lock=False,
                                      lockUnpublished=False)

                    blueprintJointsGrp = blueprintModuleNamespace_incCharNamespace + ":blueprint_joints_grp"
                    #  This was not in the video.  I needed to add this to allow overrides.
                    cmds.setAttr(blueprintJointsGrp + ".overrideEnabled", 1)

                    cmds.setAttr(blueprintJointsGrp + ".overrideColor", 13)

                    for container in containers:
                        cmds.lockNode(container,
                                      lock=True,
                                      lockUnpublished=True)

        self.currentBlueprintModule['currentMod'] = (
            blueprintModuleNamespace_incCharNamespace)
        print "ModMaintEX cureent bp mod name "
        print self.currentBlueprintModule['currentMod']
Ejemplo n.º 50
0
    def objectSelected(self):
        objects = cmds.ls(selection=True)

        cmds.select(clear=True)

        if cmds.window("modMaintain_UI_window", exists=True):
            cmds.deleteUI("modMaintain_UI_window")

        characters = utils.findInstalledCharacters()

        for character in characters:
            characterContainer = character + ":character_container"
            cmds.lockNode(characterContainer,
                          lock=False,
                          lockUnpublished=False)
            # Find every module installed on that character.
            blueprintInstances = utils.findInstalledBlueprintInstances(
                character)

            for blueprintInstance in blueprintInstances:
                moduleContainer = character + ":" + blueprintInstance + ":module_container"
                cmds.lockNode(moduleContainer,
                              lock=False,
                              lockUnpublished=False)

                # Do we have modules installed?  If so, set the joint color to blue.
                blueprintJointsGrp = character + ":" + blueprintInstance + ":blueprint_joints_grp"

                if cmds.getAttr(blueprintJointsGrp +
                                ".controlModulesInstalled"):
                    #Blue
                    cmds.setAttr(blueprintJointsGrp + ".overrideColor", 6)
                else:
                    cmds.setAttr(blueprintJointsGrp + ".overrideColor", 2)

                cmds.lockNode(moduleContainer, lock=True, lockUnpublished=True)

            cmds.lockNode(characterContainer, lock=True, lockUnpublished=True)

        if len(objects) > 0:
            lastSelected = objects[len(objects) - 1]

            lastSelected_stripNamespaces = utils.stripAllNamespaces(
                lastSelected)

            if lastSelected_stripNamespaces != None:
                lastSelected_withoutNamespaces = lastSelected_stripNamespaces[
                    1]

                if lastSelected_withoutNamespaces.find("blueprint_") == 0:
                    blueprintModuleNamespace_incCharNamespace = lastSelected_stripNamespaces[
                        0]
                    moduleContainer = blueprintModuleNamespace_incCharNamespace + ":module_container"

                    cmds.select(moduleContainer, replace=True)

                    # set color of the joints
                    characterNamespace = utils.stripLeadingNamespace(
                        lastSelected)[0]

                    characterContainer = characterNamespace + ":character_container"

                    containers = [characterContainer, moduleContainer]
                    for container in containers:
                        cmds.lockNode(container,
                                      lock=False,
                                      lockUnpublished=False)

                    blueprintJointsGrp = blueprintModuleNamespace_incCharNamespace + ":blueprint_joints_grp"
                    #  This was not in the video.  I needed to add this to allow overrides.
                    cmds.setAttr(blueprintJointsGrp + ".overrideEnabled", 1)

                    cmds.setAttr(blueprintJointsGrp + ".overrideColor", 13)

                    # Bring up UI
                    self.createUserInterface(
                        blueprintModuleNamespace_incCharNamespace)

                    for container in containers:
                        cmds.lockNode(container,
                                      lock=True,
                                      lockUnpublished=True)

        self.setupSelectionScriptJob()
Ejemplo n.º 51
0
	def setupBlueprintWeightBasedBlending(self):
		settingsLocator = self.blueprintNamespace+":SETTINGS"
		
		attributes = cmds.listAttr(settingsLocator, keyable=False)
		weightAttributes = []
		for attr in attributes:
			if attr.find("_weight") != -1:
				weightAttributes.append(attr)
		
		value = 0
		if len(weightAttributes) == 0:
			value = 1
			cmds.setAttr(settingsLocator+".creationPoseWeight", 0)
			
		cmds.select(settingsLocator)
		weightAttributeName = self.moduleNamespace+"_weight"
		cmds.addAttr(ln=weightAttributeName, at="double", min=0, max=1, defaultValue=value, keyable=False)
		
		cmds.container(self.blueprintNamespace+":module_container", edit=True, publishAndBind=[settingsLocator+"."+weightAttributeName, weightAttributeName])
		
		currentEntries = cmds.attributeQuery("activeModule", n=settingsLocator, listEnum=True)
		
		newEntry = self.moduleNamespace
		
		if currentEntries[0] == "None":
			cmds.addAttr(settingsLocator+".activeModule", edit=True, enumName=newEntry)
			cmds.setAttr(settingsLocator+".activeModule", 0)
			
		else:
			cmds.addAttr(settingsLocator+".activeModule", edit=True, enumName=currentEntries[0]+":"+newEntry)
			
		
		weightAttributeName = self.moduleNamespace + "_weight"
		cmds.addAttr(ln=weightAttributeName, at="double", min=0, max=1, defaultValue=value, keyable=False)
		
		cmds.container(self.blueprintNamespace+":module_container", edit=True, publishAndBind=[settingsLocator+"."+weightAttributeName])
		
		currentEntries = cmds.attributeQuery("activeModule", n=settingsLocator, listEnum=True)
		
		newEntry = self.moduleNamespace
		
		if currentEntries[0] == "None":
			cmds.addAttr(settingsLocator+".activeModule", edit=True, enumName=newEntry)
			cmds.setAttr(settingsLocator+".activeModule", 0)
		else:
			cmds.addAttr(settingsLocator+".activeModule", edit=True, enumNum=currentEntries[0]+":"+newEntry)
			
		utilityNodes =[]
		for i in range(1, len(self.joints)):
			joint = self.joints[i]
			
			nameSuffix = utils.stripAllNamespaces(joint)[1]
			blueprintJoint = self.blueprintNamespace+":blueprint_"+nameSuffix
		
		
			weightNodeAttr = settingsLocator + "." + weightAttributeName
			
			if i < len(self.joints) - 1 or len(self.joints) == 2:
				multiplyRotations = cmds.shadingNode("multiplyDivide", n=joint+"_multiplyRotationsWeight", asUtility=True)
				utilityNodes.append(multiplyRotations)
				cmds.connectAttr(joint+".rotate", multiplyRotations+".input1", force=True)
				
				for attr in ["input2X", "input2Y", "input2Z"]:
					cmds.connectAttr(weightNodeAttr, multiplyRotations+"."+attr, force=True)
					
				index = utils.findFirstFreeConnection (blueprintJoint+"_addRotations.input3D")
				index = 1
				cmds.connectAttr(multiplyRotations+".output", blueprintJoint+"_addRotations.input3D["+str(index)+"]")
			
			if i == 1:
				addNode = blueprintJoint + "_addTranslate"
				if cmds.objExists(addNode):
					multiplyTranslation = cmds.shadingNode("multiplyDivide", n=joint+"_multiplyTranslationWeight", asUtility=True)
					utilityNodes.append(multiplyTranslation)
					
					cmds.connectAttr(joint+".translate", multiplyTranslation+".input1", force=True)
					for attr in ["input2X", "input2Y", "input2Z"]:
						cmds.connectAttr(weightNodeAttr, multiplyTranslation+"."+attr, force=True)
						
					index = utils.findFirstFreeConnection(addNode+".input3D")
					cmds.connectAttr(multiplyTranslation+".output", addNode+".input3D["+str(index)+"]", force=True)
				
				addNode = blueprintJoint+"_addScale"
				if cmds.objExists(addNode):
					multiplyScale = cmds.shadingNode("multiplyDivide", n=joint+"_multiplyScaleWeight", asUtility=True)
					utilityNodes.append(multiplyScale)
					
					cmds.connectAttr(joint+".scale", multiplyScale+".input1", force=True)
					for attr in ["input2X", "input2Y", "input2Z"]:
						cmds.connectAttr(weightNodeAttr, multiplyScale+"."+attr, force=True)
					
					index = utils.findFirstFreeConnection(addNode+".input3D")
					cmds.connectAttr(multiplyScale+".output", addNode+".input3D["+str(index)+"]", force=True)
				
			else:
				multiplyTranslation = cmds.shadingNode("multiplyDivide", n=joint+"_multiplyTranslationWeight", asUtility=True)
				utilityNodes.append(multiplyTranslation)
				
				cmds.connectAttr(joint+".translateX", multiplyTranslation+".input1X", force=True)
				cmds.connectAttr(weightNodeAttr, multiplyTranslation+".input2X", force=True)
				
				addNode = blueprintJoint+"_addTx"
				index = utils.findFirstFreeConnection (addNode+".input1D")
				index = 1
				cmds.connectAttr(multiplyTranslation+".outputX", addNode+".input1D["+str(index)+"]", force=True)
		
		return utilityNodes
Ejemplo n.º 52
0
 def setupBlueprintWeightBasedBlending(self):
     settingsLocator = self.blueprintNamespace+":SETTINGS"
     
     attributes = cmds.listAttr(settingsLocator, keyable=False)
     weightAttributes = []
     for attr in attributes:
         if attr.find("_weight") != -1:
             weightAttributes.append(attr)
             
     value = 0
     if len(weightAttributes) == 0:
         value = 1
         cmds.setAttr(settingsLocator+".creationPoseWeight", 0)
         
     cmds.select(settingsLocator)
     weightAttributeName = self.moduleNamespace + "_weight"
     cmds.addAttr(ln=weightAttributeName, at="double", min=0, max=1, defaultValue=value, keyable=False)
     
     cmds.container(self.blueprintNamespace+":module_container", edit=True, publishAndBind=[settingsLocator+"."+weightAttributeName, weightAttributeName])
     
     currentEntries = cmds.attributeQuery("activeModule", n=settingsLocator, listEnum=True)
     
     newEntry = self.moduleNamespace
     
     if currentEntries[0] == "None":
         cmds.addAttr(settingsLocator+".activeModule", edit=True, enumName=newEntry)
         cmds.setAttr(settingsLocator+".activeModule", 0)
     else:
         cmds.addAttr(settingsLocator+".activeModule", edit=True, enumName=currentEntries[0]+":"+newEntry)
         
     utilityNodes = []
     for i in range(1, len(self.joints)):
         joint = self.joints[i]
         
         nameSuffix = utils.stripAllNamespaces(joint)[1]
         blueprintJoint = self.blueprintNamespace+":blueprint_"+nameSuffix
         weightNodeAttr = settingsLocator+"."+weightAttributeName
         
         if i < len(self.joints) -1 or len(self.joints) == 2:
             multiplyRotations = cmds.shadingNode("multiplyDivide", n=joint+"_multiplyRotationsWeight", asUtility=True)
             utilityNodes.append(multiplyRotations)
             cmds.connectAttr(joint+".rotate", multiplyRotations+".input1", force=True)
             
             
             for attr in ["input2X", "input2Y", "input2Z"]:
                 cmds.connectAttr(weightNodeAttr, multiplyRotations+"."+attr, force=True)
                 
             index = utils.findFirstFreeConnection(blueprintJoint+"_addRotations.input3D")
             cmds.connectAttr(multiplyRotations+".output", blueprintJoint+"_addRotations.input3D[" + str(index) + "]")
             
         if i == 1:
             addNode = blueprintJoint+"_addTranslate"
             if cmds.objExists(addNode):
                 multiplyTranslation = cmds.shadingNode("multiplyDivide", n=joint+"_multiplyTranslationWeight", asUtility=True)
                 utilityNodes.append(multiplyTranslation)
                 
                 cmds.connectAttr(joint+".translate", multiplyTranslation+".input1", force=True)
                 for attr in ["input2X", "input2Y", "input2Z"]:
                     cmds.connectAttr(weightNodeAttr, multiplyTranslation+"."+attr, force=True)
                     
                 index = utils.findFirstFreeConnection(addNode+".input3D")
                 cmds.connectAttr(multiplyTranslation+".output", addNode+".input3D["+str(index)+"]", force=True)
                 
             addNode = blueprintJoint+"_addScale"
             #I am removing the following lines to eliminate scale for now.
             if cmds.objExists(addNode):
                 multiplyScale = cmds.shadingNode("multiplyDivide", n=joint+"_multiplyScaleWeight", asUtility=True)
                 utilityNodes.append(multiplyScale)
                 
                 cmds.connectAttr(joint+".scale", multiplyScale+".input1", force=True)
                 for attr in ["input2X", "input2Y", "input2Z"]:
                     cmds.connectAttr(weightNodeAttr, multiplyScale+"."+attr, force=True)
                     
                 index = utils.findFirstFreeConnection(addNode+".input3D")
                 cmds.connectAttr(multiplyScale+".output", addNode+".input3D["+str(index)+"]", force=True)
                 
                    
         else:
             multiplyTranslation = cmds.shadingNode("multiplyDivide", n=joint+"_multiplyTranslationWeight", asUtility=True)
             utilityNodes.append  (multiplyTranslation)
             
             cmds.connectAttr(joint+".translateX", multiplyTranslation+".input1X", force=True)
             cmds.connectAttr(weightNodeAttr, multiplyTranslation+".input2X", force=True)
             
             addNode = blueprintJoint+"_addTx"
             index = utils.findFirstFreeConnection(addNode+".input1D")
             cmds.connectAttr(multiplyTranslation+".outputX", addNode+".input1D[" + str(index) + "]", force=True)
             
     return utilityNodes
	def objectSelected(self):
		objects = cmds.ls(selection = True)
		
		cmds.select(clear=True)
		
		if cmds.window('modMaintain_UI_window',exists=True):
			cmds.deleteUI('modMaintain_UI_window')
		
		characters = utils.findInstalledCharacters()
		
		for character in characters:
			characterContainer = character + ':character_container'
			cmds.lockNode(characterContainer,lock=False,lockUnpublished=False)
			
			blueprintInstances = utils.findInstalledBlueprintInstances(character)
			
			for blueprintInstance in blueprintInstances:
				moduleContainer = character + ':' + blueprintInstance + ':module_container'
				cmds.lockNode(moduleContainer,lock=False,lockUnpublished=False)
				
				blueprintJointsGrp = character + ':' + blueprintInstance + ':blueprint_joints_grp'
				
				if cmds.getAttr(blueprintJointsGrp + '.controlModulesInstalled'):
					#blue
					cmds.setAttr(blueprintJointsGrp + '.overrideColor', 6)
				else:
					#Grey
					cmds.setAttr(blueprintJointsGrp + '.overrideColor', 2)
				
				
				cmds.lockNode(moduleContainer,lock=True,lockUnpublished=True)			
			
			cmds.lockNode(characterContainer,lock=True,lockUnpublished=True)
		
		if len(objects) > 0:
			lastSelected = objects[len(objects)-1]
			
			lastSelected_stripNamespaces = utils.stripAllNamespaces(lastSelected)
			
			if lastSelected_stripNamespaces != None:
				lastSelected_withoutNamespaces = lastSelected_stripNamespaces[1]
				
				if lastSelected_withoutNamespaces.find('blueprint_') == 0:
					blueprintModuleNamespace_incCharNamespace = lastSelected_stripNamespaces[0]
					moduleContainer = blueprintModuleNamespace_incCharNamespace + ':module_container'
					cmds.select(moduleContainer,replace=True)
					
					characterNamespace = utils.stripLeadingNamespace(lastSelected)[0]
					
					characterContainer = characterNamespace + ':character_container'
					
					containers = [characterContainer, moduleContainer]
					for container in containers:
						cmds.lockNode(container, lock=False, lockUnpublished=False)
						
					blueprintJointsGrp = blueprintModuleNamespace_incCharNamespace + ':blueprint_joints_grp'
					cmds.setAttr(blueprintJointsGrp + '.overrideColor', 13)
					
					self.createUserInterface(blueprintModuleNamespace_incCharNamespace)
					
					for container in containers:
						cmds.lockNode(container, lock=True, lockUnpublished=True)
						
		self.setupSelectionScriptJob()
Ejemplo n.º 54
0
    def install_custom(self, joints, moduleGrp, moduleContainer):
        moduleNamespace = self.blueprintNamespace + ":" + self.moduleNamespace
        """ Assign the joint indices to a variable """
        ankleJoint = joints[3]
        ballJoint = joints[4]
        toeJoint = joints[5]
        """ Create a list of objects that need to be added to a namespace """
        namespaceObjects = []
        """ Get the module positions by creating a temp locator which is parented to each module in turn.
        Use xform on the locator and save it's position to a new variable.
        """
        """ Temp locator used to get the module positions """
        tempLocator = cmds.spaceLocator()[0]
        """ Ball Joint """
        cmds.parent(tempLocator, ballJoint, relative=True)
        cmds.parent(tempLocator, moduleGrp, absolute=True)
        ballJoint_modulePos = [
            cmds.getAttr(tempLocator + ".translateX"),
            cmds.getAttr(tempLocator + ".translateY"),
            cmds.getAttr(tempLocator + ".translateZ")
        ]
        """ Ankle Joint """
        cmds.parent(tempLocator, ankleJoint)
        for attr in [".translateX", ".translateY", ".translateZ"]:
            cmds.setAttr(tempLocator + attr, 0)
        cmds.parent(tempLocator, moduleGrp, absolute=True)
        ankleJoint_modulePos = [
            cmds.getAttr(tempLocator + ".translateX"),
            cmds.getAttr(tempLocator + ".translateY"),
            cmds.getAttr(tempLocator + ".translateZ")
        ]
        """ Toe Joint """
        cmds.parent(tempLocator, toeJoint)
        for attr in [".translateX", ".translateY", ".translateZ"]:
            cmds.setAttr(tempLocator + attr, 0)
        cmds.parent(tempLocator, moduleGrp, absolute=True)
        toeJoint_modulePos = [
            cmds.getAttr(tempLocator + ".translateX"),
            cmds.getAttr(tempLocator + ".translateY"),
            cmds.getAttr(tempLocator + ".translateZ")
        ]
        """ Delete the temp locator """
        cmds.delete(tempLocator)
        """ containedNodes is an empty list that will store all the nodes that should be added to the animation module container """
        containedNodes = []
        """ Pass in functionality from basic IK """
        ikNodes = circleIK.CircleControlStretchyIK.install_custom(
            self,
            joints,
            moduleGrp,
            moduleContainer,
            createHandleControl=False,
            poleVectorAtRoot=False)
        ikEndPosLocator = ikNodes["endLocator"]
        ikPoleVectorLocator = ikNodes["poleVectorObject"]
        #namespaceObjects.append(ikEndPosLocator)
        #namespaceObjects.append(ikPoleVectorLocator)

        stretchinessAttribute = ikNodes["stretchinessAttribute"]
        """ Import the foot control """
        name = "footControl"
        controlObjectInstance = controlObject.ControlObject()
        footControlInfo = controlObjectInstance.create(name,
                                                       "footControl.ma",
                                                       self,
                                                       lod=1,
                                                       translation=True,
                                                       rotation=True,
                                                       globalScale=False,
                                                       spaceSwitching=True)
        footControl = footControlInfo[0]
        footControlRootParent = footControlInfo[1]
        """ Create control attributes on the foot control """
        footControlAttributes = ('roll', 'roll_break', 'toe_twist',
                                 'ball_twist', 'heel_twist', 'bank',
                                 'toe_flap')
        cmds.select(footControl)
        for attr in footControlAttributes:
            cmds.addAttr(shortName=attr, defaultValue=0.0, k=True)
            self.publishNameToModuleContainer(footControl + '.' + attr,
                                              attr,
                                              publishToOuterContainers=True)

        #footControlAttributes = ('pv_follow')
        #cmds.select(footControl)

        #cmds.addAttr(shortName=footControlAttributes[0], at='enum', en='off:on', k=True)
        """ Publish attributes to the top level character container """
        #self.publishNameToModuleContainer(footControl + '.' + attr, attr, publishToOuterContainers=True)
        """ Parent foot control to root parent"""
        cmds.parent(footControlRootParent, moduleGrp, relative=True)
        """ Position and orient foot control"""
        footControlPos = [
            ankleJoint_modulePos[0], ballJoint_modulePos[1],
            ankleJoint_modulePos[2]
        ]
        cmds.xform(footControl,
                   objectSpace=True,
                   absolute=True,
                   translation=footControlPos)
        """ Position the foot control pivot at the ankle """
        cmds.xform(footControl,
                   ws=True,
                   p=True,
                   piv=[
                       ankleJoint_modulePos[0], ankleJoint_modulePos[1],
                       ankleJoint_modulePos[2]
                   ])

        cmds.setAttr(footControl + ".rotateOrder", 3)  #3 = xyz

        orientationVector = [
            toeJoint_modulePos[0] - ankleJoint_modulePos[0],
            toeJoint_modulePos[2] - ankleJoint_modulePos[2]
        ]

        footControlRotation = atan2(orientationVector[1], orientationVector[0])
        cmds.setAttr(footControl + ".rotateY", -degrees(footControlRotation))

        # Hookup stretchiness attribute
        cmds.select(footControl)
        cmds.addAttr(at="float",
                     minValue=0.0,
                     maxValue=1.0,
                     defaultValue=1.0,
                     keyable=True,
                     longName="stretchiness")
        self.publishNameToModuleContainer(footControl + ".stretchiness",
                                          "stretchiness",
                                          publishToOuterContainers=True)

        cmds.connectAttr(footControl + ".stretchiness",
                         stretchinessAttribute,
                         force=True)
        """ Setup for ball and Toe controls"""
        ballToeControls = []
        ballToeControl_orientGrps = []
        rootParents = []
        for joint in [ankleJoint, ballJoint]:
            controlObjectInstance = controlObject.ControlObject()
            jointName = utils.stripAllNamespaces(joint)[1]
            name = jointName + "_pivotControl"

            ryControlInfo = controlObjectInstance.create(name,
                                                         "needleControl.ma",
                                                         self,
                                                         lod=2,
                                                         translation=True,
                                                         rotation=False,
                                                         globalScale=False,
                                                         spaceSwitching=False)
            ryControl = ryControlInfo[0]
            ryControlRootParent = ryControlInfo[0]

            ballToeControls.append(ryControl)
            rootParents.append(ryControlInfo[0])

            orientGrp = cmds.group(empty=True, n=ryControl + "_orientGrp")
            containedNodes.append(orientGrp)
            ballToeControl_orientGrps.append(orientGrp)

            cmds.parent(ryControl, orientGrp, relative=True)

        cmds.xform(ballToeControl_orientGrps[0],
                   objectSpace=True,
                   absolute=True,
                   translation=ankleJoint_modulePos)
        cmds.xform(ballToeControl_orientGrps[1],
                   objectSpace=True,
                   absolute=True,
                   translation=ballJoint_modulePos)

        heelControlRootParent = rootParents[0]
        bankControlRootParent = rootParents[1]

        for grp in ballToeControl_orientGrps:
            cmds.parent(grp, moduleGrp, absolute=True)
        """ This aligns the leg """
        #cmds.parent(ikEndPosLocator, ballToeControls[0], absolute=True)
        """ Ankle IK """
        ankleIKNodes = cmds.ikHandle(sj=ankleJoint,
                                     ee=ballJoint,
                                     solver="ikSCsolver",
                                     n=ankleJoint + "_ikHandle")
        ankleIKNodes[1] = cmds.rename(ankleIKNodes[1],
                                      ankleIKNodes[1] + "_ikEffector")
        containedNodes.extend(ankleIKNodes)
        namespaceObjects.append(ankleIKNodes[0])
        namespaceObjects.append(ankleIKNodes[1])

        cmds.setAttr(ankleIKNodes[0] + ".visibility", 0)
        """ Ball IK  """
        ballIKNodes = cmds.ikHandle(sj=ballJoint,
                                    ee=toeJoint,
                                    solver="ikSCsolver",
                                    n=ballJoint + "_ikHandle")
        ballIKNodes[1] = cmds.rename(ballIKNodes[1],
                                     ballIKNodes[1] + "_ikEffector")
        containedNodes.extend(ballIKNodes)
        namespaceObjects.append(ballIKNodes[0])
        namespaceObjects.append(ballIKNodes[1])

        cmds.setAttr(ballIKNodes[0] + ".visibility", 0)

        utils.addNodeToContainer(moduleContainer, containedNodes, ihb=True)
        """ Empty the contained nodes list """
        containedNodes = []
        """ Create the IK_Groups """
        ikGroups = []
        """ These groups go at the ankle """
        ikGrp = cmds.group(em=True, name='footIK_grp')
        cmds.xform(ikGrp, a=True, t=ankleJoint_modulePos)
        ikGroups.append(ikGrp)
        containedNodes.append(ikGrp)
        """ These go at the ball """
        groupNames = ('bank_grp', 'ballTwist_grp', 'ballRoll_grp',
                      'toeFlap_grp')
        for group in groupNames:
            cmds.group(em=True, name=group)
            cmds.xform(group, a=True, t=ballJoint_modulePos)
            ikGroups.append(group)
            containedNodes.append(group)
        """ These go at the toe """
        ikGrp = cmds.group(em=True, name='toeRoll_grp')
        cmds.xform(ikGrp, a=True, t=toeJoint_modulePos)
        ikGroups.append(ikGrp)
        containedNodes.append(ikGrp)
        """ Create a heel roll group """
        """ TODO:  How do I get this to sit at the heel without adding a joint for it? """
        ikGrp = cmds.group(em=True, name='heelRoll_grp')
        cmds.xform(ikGrp,
                   a=True,
                   t=(ankleJoint_modulePos[0], 0, ankleJoint_modulePos[2]))
        ikGroups.append(ikGrp)
        containedNodes.append(ikGrp)
        """ Create 3 locators to be used for roll attribute """
        rollLctrs = []
        dynRollLctr = cmds.spaceLocator(name='dynRoll_lctr')[0]
        cmds.xform(dynRollLctr, a=True, t=ballJoint_modulePos)
        rollLctrs.append(dynRollLctr)
        containedNodes.append(dynRollLctr)

        statRollLctr = cmds.spaceLocator(name='statRoll_lctr')[0]
        cmds.xform(statRollLctr, a=True, t=ballJoint_modulePos)
        rollLctrs.append(statRollLctr)
        containedNodes.append(statRollLctr)
        """ heelRoll_lctr """
        heelRollLctr = cmds.spaceLocator(name='heelRoll_lctr')[0]
        cmds.xform(heelRollLctr, a=True, t=ballJoint_modulePos)
        rollLctrs.append(heelRollLctr)
        containedNodes.append(heelRollLctr)

        for locator in rollLctrs:
            cmds.setAttr(locator + '.visibility', 0)
        """ Parent the adjustment controls to the foot control """
        cmds.parent(heelControlRootParent, ikGroups[3], absolute=True)
        cmds.makeIdentity(heelControlRootParent, apply=True, translate=True)
        cmds.parent(bankControlRootParent, ikGroups[3], absolute=True)
        """ Parent the ikHandles under the appropriate group """
        cmds.parent(ankleIKNodes[0], ikGroups[3])
        cmds.parent(ikEndPosLocator, ikGroups[3])

        cmds.parent(ballIKNodes[0], ikGroups[4])

        cmds.parent(ikGroups[3], ikGroups[5])  #ballRoll  toeRoll
        cmds.parent(ikGroups[4], ikGroups[5])  #toeFlap toeRoll
        cmds.parent(ikGroups[5], ikGroups[2])  #toeRoll  ballTwist
        cmds.parent(ikGroups[2], ikGroups[1])  #ballTwist  bank
        cmds.parent(ikGroups[1], ikGroups[6])  #bank  heelRoll
        cmds.parent(ikGroups[6], ikGroups[0])  #heelRoll  footIK

        cmds.parent(dynRollLctr, ikGroups[0])
        cmds.parent(heelRollLctr, ikGroups[0])
        cmds.parent(statRollLctr, ikGroups[6])
        """ Parent constrain ball and toe groups to roll_lctrs """
        parentConstraints = []
        rollParentConstraint = cmds.parentConstraint(dynRollLctr,
                                                     ikGroups[3],
                                                     mo=True,
                                                     st=('x', 'y', 'z'),
                                                     sr=('y', 'z'))
        parentConstraints.append(rollParentConstraint[0])
        rollParentConstraint = cmds.parentConstraint(statRollLctr,
                                                     ikGroups[3],
                                                     mo=True,
                                                     st=('x', 'y', 'z'),
                                                     sr=('y', 'z'))
        parentConstraints.append(rollParentConstraint[0])
        rollParentConstraint = cmds.parentConstraint(statRollLctr,
                                                     ikGroups[5],
                                                     mo=True,
                                                     st=('x', 'y', 'z'),
                                                     sr=('y', 'z'))
        parentConstraints.append(rollParentConstraint[0])
        rollParentConstraint = cmds.parentConstraint(dynRollLctr,
                                                     ikGroups[5],
                                                     mo=True,
                                                     st=('x', 'y', 'z'),
                                                     sr=('y', 'z'))
        parentConstraints.append(rollParentConstraint[0])

        for constraint in parentConstraints:
            print constraint
            newName = moduleNamespace + ':' + constraint
            cmds.rename(constraint, newName)
        """ Create a remap value node to control foot roll """
        cmds.createNode('remapValue', name='roll_rv')
        cmds.setAttr('roll_rv.inputMax', 180.0)
        """ Connect to the remap value node """
        """" Connect the output of dynRollLctr to roll_rv input value """
        cmds.connectAttr(dynRollLctr + '.rx', 'roll_rv.inputValue')
        """ roll_break to input min """
        cmds.setAttr(footControl + '.roll_break', 45.0)
        cmds.connectAttr(footControl + '.roll_break', 'roll_rv.inputMin')
        """ roll_break to parent constraint switches """
        cmds.connectAttr('roll_rv.outColorG', ikGroups[3] + '.blendParent2')
        cmds.connectAttr('roll_rv.outColorR', ikGroups[5] + '.blendParent2')
        namespaceObjects.append('roll_rv')
        """ constrain the heelRoll_grp to heelRoll_lctr.  Switch off the constraint when greater than 0 """
        cmds.createNode('condition', name='roll_cond')
        heelOrientConstraint = cmds.orientConstraint(heelRollLctr,
                                                     ikGroups[6],
                                                     skip=('y', 'z'),
                                                     mo=True)
        heelOrientAttr = (heelOrientConstraint[0] + '.' + heelRollLctr + 'W0')
        cmds.connectAttr('roll_cond.outColorR', heelOrientAttr)
        cmds.connectAttr(heelRollLctr + '.rx', 'roll_cond.firstTerm')
        cmds.setAttr('roll_cond.operation', 3)
        newName = moduleNamespace + ':' + heelOrientConstraint[0]
        cmds.rename(heelOrientConstraint[0], newName)
        namespaceObjects.append('roll_cond')
        """ Connect the foot attributes to respective groups and locators """
        cmds.connectAttr(footControl + ".roll", heelRollLctr + '.rx')
        cmds.connectAttr(footControl + ".roll", 'dynRoll_lctr.rx')
        cmds.connectAttr(footControl + ".toe_twist", 'toeRoll_grp.ry')
        cmds.connectAttr(footControl + ".ball_twist", 'ballTwist_grp.ry')
        cmds.connectAttr(footControl + ".heel_twist", 'heelRoll_grp.ry')
        cmds.connectAttr(footControl + ".bank", 'bank_grp.rz')
        cmds.connectAttr(footControl + ".toe_flap", 'toeFlap_grp.rx')
        """ Connect pivot controls to the rotatePivot of appropriate group """
        cmds.connectAttr(rootParents[1] + '.translate', 'bank_grp.rotatePivot')
        cmds.connectAttr(rootParents[0] + '.translate',
                         'heelRoll_grp.rotatePivot')
        """ Parent the footIK_grp to the foot control """
        cmds.parent('footIK_grp', footControl, absolute=True)

        utils.addNodeToContainer(moduleContainer, containedNodes, ihb=True)

        for node in containedNodes:
            newName = moduleNamespace + ':' + node
            cmds.rename(node, newName)
        """ Add the namespaceObjects to the moduleNamespace """

        for node in namespaceObjects:
            print node
            newName = moduleNamespace + ':' + node
            cmds.rename(node, newName)
Ejemplo n.º 55
0
 def install_custom(self, joints, moduleGrp, moduleContainer, createHandleControl=True, poleVectorAtRoot=True):
     rootJoint = joints[1]
     hingeJoint = joints[2]
     endJoint = joints[3]
     
     containedNodes = []
     
     twistRotationAimer = cmds.group(empty=True, n=rootJoint+"_twistRotationAimer")
     containedNodes.append(twistRotationAimer)
     
     containedNodes.append(cmds.pointConstraint(rootJoint, twistRotationAimer, maintainOffset=False, n=twistRotationAimer+"_pointConstraint")[0])
     cmds.pointConstraint(endJoint, twistRotationAimer, maintainOffset=False)
     
     upVectorTarget = cmds.group(empty=True, n=rootJoint+"_twistRotationAimer_upVectorTarget")
     containedNodes.append(upVectorTarget)
     
     cmds.parent(upVectorTarget, hingeJoint, relative=True)
     cmds.setAttr(upVectorTarget+".translateZ", cmds.getAttr(hingeJoint+".translateX"))
     
     containedNodes.append(cmds.aimConstraint(endJoint, twistRotationAimer, maintainOffset=False, n=twistRotationAimer+"_aimConstraint", aimVector=[0.0, 0.0, 1.0], upVector=[1.0, 0.0, 0.0], worldUpType="object", worldUpObject=upVectorTarget)[0])
     
     tempLocator = cmds.spaceLocator()[0]
     cmds.parent(tempLocator, twistRotationAimer, relative=True)
     cmds.setAttr(tempLocator+".translateY", 10)
     
     twistRotationAimerPos = cmds.xform(twistRotationAimer, q=True, worldSpace=True, translation=True)
     tempLocatorPos = cmds.xform(tempLocator, q=True, worldSpace=True, translation=True)
     
     offsetVector = [tempLocatorPos[0] - twistRotationAimerPos[0], tempLocatorPos[1] - twistRotationAimerPos[1], tempLocatorPos[2] - twistRotationAimerPos[2]]
     
     cmds.delete(tempLocator)
     
     ikNodes = utils.basic_stretchy_IK(rootJoint, endJoint, container=moduleContainer, scaleCorrectionAttribute=self.blueprintNamespace+":module_grp.hierarchicalScale")
     ikHandle = ikNodes["ikHandle"]
     rootPosLocator = ikNodes["rootLocator"]
     endPosLocator = ikNodes["endLocator"]
     poleVectorLocator = ikNodes["poleVectorObject"]
     stretchinessAttribute = ikNodes["stretchinessAttribute"]
     
     for node in [ikHandle, rootPosLocator, endPosLocator, poleVectorLocator]:
         cmds.parent(node, moduleGrp, absolute=True)
         
     if poleVectorAtRoot:
         poleVectorPos = cmds.xform(rootJoint, q=True, worldSpace=True, translation=True)
     else:
         poleVectorPos = cmds.xform(endJoint, q=True, worldSpace=True, translation=True)
         
     poleVectorPos[0] += offsetVector[0]
     poleVectorPos[1] += offsetVector[1]
     poleVectorPos[2] += offsetVector[2]
     cmds.xform(poleVectorLocator, worldSpace=True, absolute=True, translation=poleVectorPos)
     
     if createHandleControl:
         name = "ikHandleControl"
         
         controlObjectInstance = controlObject.ControlObject()
         handleControlInfo = controlObjectInstance.create(name, "cubeLocator.ma", self, lod=1, translation=True, rotation=True, globalScale=False, spaceSwitching=True)
         handleControl = handleControlInfo[0]
         handleRootParent = handleControlInfo[1]
         
         cmds.parent(handleRootParent, moduleGrp, relative=True)
         cmds.xform(handleControl, worldSpace=True, absolute=True, translation=cmds.xform(endPosLocator, q=True, worldSpace=True, translation=True))
         
         pointConstraint = cmds.pointConstraint(handleControl, endPosLocator, maintainOffset=False, n=endPosLocator+"_pointConstraint")[0]
         containedNodes.append(pointConstraint)
         
         cmds.select(handleControl)
         cmds.addAttr(at="float", minValue=0.0, maxValue=1.0, defaultValue=1.0, keyable=True, longName="stretchiness")
         cmds.connectAttr(handleControl+".stretchiness", stretchinessAttribute)
         
         self.publishNameToModuleContainer(handleControl+".stretchiness", "stretchiness", publishToOuterContainers=True)
         
     rotationCancellation = cmds.group(empty=True, n=self.blueprintNamespace+":"+self.moduleNamespace+":twistRotationCancellation")
     containedNodes.append(rotationCancellation)
     
     cmds.parent(rotationCancellation, twistRotationAimer, relative=True)
     
     twistControlOffset = cmds.group(empty=True, n=self.blueprintNamespace + ":" + self.moduleNamespace + ":twistControlOffset")
     containedNodes.append(twistControlOffset)
     
     cmds.parent(twistControlOffset, rotationCancellation, relative=True)
     
     twistControlObjectInstance = controlObject.ControlObject()
     twistControlInfo = twistControlObjectInstance.create("twistControl", "zAxisCircle.ma", self, lod=2, translation=False, rotation=[False, False, True], globalScale=False, spaceSwitching=True)
     twistControl = twistControlInfo[0]
     
     cmds.parent(twistControl, twistControlOffset, relative=True)
     cmds.connectAttr(twistControl+".rotateZ", ikHandle+".twist")
     
     pivotMultNode = cmds.shadingNode("multiplyDivide", asUtility=True, n=twistControl+"_invertOffset")
     containedNodes.append(pivotMultNode)
     
     cmds.connectAttr(twistControlOffset+".translateX", pivotMultNode+".input1X")
     cmds.setAttr(pivotMultNode+".input2X", -1)
     cmds.connectAttr(pivotMultNode+".output", twistControl+".rotatePivot")
     
     multNode = cmds.shadingNode("multiplyDivide", asUtility=True, n=rotationCancellation+"_invertRotateZ")
     containedNodes.append(multNode)
     
     cmds.connectAttr(twistControl+".rotateZ", multNode+".input1X")
     cmds.setAttr(multNode+".input2X", -1)
     cmds.connectAttr(multNode+".outputX", rotationCancellation+".rotateZ")
     
     cmds.parent(twistRotationAimer, moduleGrp, absolute=True)
     
     ikJoints = [joints[1], joints[2], joints[3]]
     
     jointName = utils.stripAllNamespaces(joints[1])[1]
     creationPoseRoot = self.blueprintNamespace+":creationPose_"+jointName
     creationPoseJoints = utils.findJointChain(creationPoseRoot)
     
     targetJoints = [creationPoseJoints[0], creationPoseJoints[1], creationPoseJoints[2]]
     
     utils.matchTwistAngle(twistControl+".rotateZ", ikJoints, targetJoints)
     
     offsetNode = cmds.shadingNode("plusMinusAverage", asUtility=True, n=twistControl+"_twistOffset")
     containedNodes.append(offsetNode)
     
     cmds.setAttr(offsetNode+".input1D[0]", cmds.getAttr(twistControl+".rotateZ"))
     cmds.connectAttr(twistControl+".rotateZ", offsetNode+".input1D[1]")
     cmds.connectAttr(offsetNode+".output1D", ikHandle+".twist", force=True)
     
     utils.forceSceneUpdate()
     cmds.setAttr(twistControl+".rotateZ", 0)
     
     utils.addNodeToContainer(moduleContainer, containedNodes)
     
     self.publishNameToModuleContainer(twistControlOffset+".translateX", "twistControlOffset", publishToOuterContainers=True)
     
     cmds.setAttr(moduleGrp+".lod", 2)
     
     return(ikNodes)
Ejemplo n.º 56
0
    def install_custom(self,
                       joints,
                       moduleGrp,
                       moduleContainer,
                       createHandleControl=True,
                       poleVectorAtRoot=True):
        rootJoint = joints[1]
        hingeJoint = joints[2]
        endJoint = joints[3]

        containedNodes = []

        twistRotationAimer = cmds.group(empty=True,
                                        n=rootJoint + "_twistRotationAimer")
        containedNodes.append(twistRotationAimer)

        containedNodes.append(
            cmds.pointConstraint(rootJoint,
                                 twistRotationAimer,
                                 maintainOffset=False,
                                 n=twistRotationAimer + "_pointConstraint")[0])
        cmds.pointConstraint(endJoint,
                             twistRotationAimer,
                             maintainOffset=False)

        upVectorTarget = cmds.group(empty=True,
                                    n=rootJoint +
                                    "_twistRotationAimer_upVectorTarget")
        containedNodes.append(upVectorTarget)

        cmds.parent(upVectorTarget, hingeJoint, relative=True)
        cmds.setAttr(upVectorTarget + ".translateZ",
                     cmds.getAttr(hingeJoint + ".translateX"))

        containedNodes.append(
            cmds.aimConstraint(endJoint,
                               twistRotationAimer,
                               maintainOffset=False,
                               n=twistRotationAimer + "_aimConstraint",
                               aimVector=[0.0, 0.0, 1.0],
                               upVector=[1.0, 0.0, 0.0],
                               worldUpType="object",
                               worldUpObject=upVectorTarget)[0])

        tempLocator = cmds.spaceLocator()[0]
        cmds.parent(tempLocator, twistRotationAimer, relative=True)
        cmds.setAttr(tempLocator + ".translateY", 10)

        twistRotationAimerPos = cmds.xform(twistRotationAimer,
                                           q=True,
                                           worldSpace=True,
                                           translation=True)
        tempLocatorPos = cmds.xform(tempLocator,
                                    q=True,
                                    worldSpace=True,
                                    translation=True)

        offsetVector = [
            tempLocatorPos[0] - twistRotationAimerPos[0],
            tempLocatorPos[1] - twistRotationAimerPos[1],
            tempLocatorPos[2] - twistRotationAimerPos[2]
        ]

        cmds.delete(tempLocator)

        ikNodes = utils.basic_stretchy_IK(
            rootJoint,
            endJoint,
            container=moduleContainer,
            scaleCorrectionAttribute=self.blueprintNamespace +
            ":module_grp.hierarchicalScale")
        ikHandle = ikNodes["ikHandle"]
        rootPosLocator = ikNodes["rootLocator"]
        endPosLocator = ikNodes["endLocator"]
        poleVectorLocator = ikNodes["poleVectorObject"]
        stretchinessAttribute = ikNodes["stretchinessAttribute"]

        for node in [
                ikHandle, rootPosLocator, endPosLocator, poleVectorLocator
        ]:
            cmds.parent(node, moduleGrp, absolute=True)

        if poleVectorAtRoot:
            poleVectorPos = cmds.xform(rootJoint,
                                       q=True,
                                       worldSpace=True,
                                       translation=True)
        else:
            poleVectorPos = cmds.xform(endJoint,
                                       q=True,
                                       worldSpace=True,
                                       translation=True)

        poleVectorPos[0] += offsetVector[0]
        poleVectorPos[1] += offsetVector[1]
        poleVectorPos[2] += offsetVector[2]
        cmds.xform(poleVectorLocator,
                   worldSpace=True,
                   absolute=True,
                   translation=poleVectorPos)

        if createHandleControl:
            name = "ikHandleControl"

            controlObjectInstance = controlObject.ControlObject()
            handleControlInfo = controlObjectInstance.create(
                name,
                "cubeLocator.ma",
                self,
                lod=1,
                translation=True,
                rotation=True,
                globalScale=False,
                spaceSwitching=True)
            handleControl = handleControlInfo[0]
            handleRootParent = handleControlInfo[1]

            cmds.parent(handleRootParent, moduleGrp, relative=True)
            cmds.xform(handleControl,
                       worldSpace=True,
                       absolute=True,
                       translation=cmds.xform(endPosLocator,
                                              q=True,
                                              worldSpace=True,
                                              translation=True))

            pointConstraint = cmds.pointConstraint(handleControl,
                                                   endPosLocator,
                                                   maintainOffset=False,
                                                   n=endPosLocator +
                                                   "_pointConstraint")[0]
            containedNodes.append(pointConstraint)

            cmds.select(handleControl)
            cmds.addAttr(at="float",
                         minValue=0.0,
                         maxValue=1.0,
                         defaultValue=1.0,
                         keyable=True,
                         longName="stretchiness")
            cmds.connectAttr(handleControl + ".stretchiness",
                             stretchinessAttribute)

            self.publishNameToModuleContainer(handleControl + ".stretchiness",
                                              "stretchiness",
                                              publishToOuterContainers=True)

        rotationCancellation = cmds.group(empty=True,
                                          n=self.blueprintNamespace + ":" +
                                          self.moduleNamespace +
                                          ":twistRotationCancellation")
        containedNodes.append(rotationCancellation)

        cmds.parent(rotationCancellation, twistRotationAimer, relative=True)

        twistControlOffset = cmds.group(empty=True,
                                        n=self.blueprintNamespace + ":" +
                                        self.moduleNamespace +
                                        ":twistControlOffset")
        containedNodes.append(twistControlOffset)

        cmds.parent(twistControlOffset, rotationCancellation, relative=True)

        twistControlObjectInstance = controlObject.ControlObject()
        twistControlInfo = twistControlObjectInstance.create(
            "twistControl",
            "zAxisCircle.ma",
            self,
            lod=2,
            translation=False,
            rotation=[False, False, True],
            globalScale=False,
            spaceSwitching=True)
        twistControl = twistControlInfo[0]

        cmds.parent(twistControl, twistControlOffset, relative=True)
        cmds.connectAttr(twistControl + ".rotateZ", ikHandle + ".twist")

        pivotMultNode = cmds.shadingNode("multiplyDivide",
                                         asUtility=True,
                                         n=twistControl + "_invertOffset")
        containedNodes.append(pivotMultNode)

        cmds.connectAttr(twistControlOffset + ".translateX",
                         pivotMultNode + ".input1X")
        cmds.setAttr(pivotMultNode + ".input2X", -1)
        cmds.connectAttr(pivotMultNode + ".output",
                         twistControl + ".rotatePivot")

        multNode = cmds.shadingNode("multiplyDivide",
                                    asUtility=True,
                                    n=rotationCancellation + "_invertRotateZ")
        containedNodes.append(multNode)

        cmds.connectAttr(twistControl + ".rotateZ", multNode + ".input1X")
        cmds.setAttr(multNode + ".input2X", -1)
        cmds.connectAttr(multNode + ".outputX",
                         rotationCancellation + ".rotateZ")

        cmds.parent(twistRotationAimer, moduleGrp, absolute=True)

        ikJoints = [joints[1], joints[2], joints[3]]

        jointName = utils.stripAllNamespaces(joints[1])[1]
        creationPoseRoot = self.blueprintNamespace + ":creationPose_" + jointName
        creationPoseJoints = utils.findJointChain(creationPoseRoot)

        targetJoints = [
            creationPoseJoints[0], creationPoseJoints[1], creationPoseJoints[2]
        ]

        utils.matchTwistAngle(twistControl + ".rotateZ", ikJoints,
                              targetJoints)

        offsetNode = cmds.shadingNode("plusMinusAverage",
                                      asUtility=True,
                                      n=twistControl + "_twistOffset")
        containedNodes.append(offsetNode)

        cmds.setAttr(offsetNode + ".input1D[0]",
                     cmds.getAttr(twistControl + ".rotateZ"))
        cmds.connectAttr(twistControl + ".rotateZ", offsetNode + ".input1D[1]")
        cmds.connectAttr(offsetNode + ".output1D",
                         ikHandle + ".twist",
                         force=True)

        utils.forceSceneUpdate()
        cmds.setAttr(twistControl + ".rotateZ", 0)

        utils.addNodeToContainer(moduleContainer, containedNodes)

        self.publishNameToModuleContainer(twistControlOffset + ".translateX",
                                          "twistControlOffset",
                                          publishToOuterContainers=True)

        cmds.setAttr(moduleGrp + ".lod", 2)

        return (ikNodes)
Ejemplo n.º 57
0
    def create(self,
               name,
               controlFile,
               animationModuleInstance,
               lod=1,
               translation=True,
               rotation=True,
               globalScale=True,
               spaceSwitching=False):
        if translation == True or translation == False:
            translation = [translation, translation, translation]

        if rotation == True or rotation == False:
            rotation = [rotation, rotation, rotation]

        self.translation = translation
        self.rotation = rotation
        self.globalScale = globalScale

        animationModuleName = animationModuleInstance.moduleNamespace
        blueprintModuleNamespace = animationModuleInstance.blueprintNamespace
        blueprintModuleUserSpecifiedName = utils.stripAllNamespaces(
            blueprintModuleNamespace)[1].partition("__")[2]

        animationModuleNamespace = blueprintModuleNamespace + ":" + animationModuleName
        # This system currently pulls in control objects from a maya file.  I would like to change this so control objects are built on the fly.
        # I may also want to use the lo rez geo as a control.
        controlObjectFile = os.environ[
            "GEPPETTO"] + "/ControlObjects/Animation/" + controlFile
        cmds.file(controlObjectFile, i=True)

        self.controlObject = cmds.rename("control",
                                         animationModuleNamespace + ":" + name)
        self.rootParent = self.controlObject

        self.setupIconScale(animationModuleNamespace)

        # Set control object drawing overrides.
        cmds.setAttr(self.controlObject + ".overrideEnabled", 1)
        cmds.setAttr(self.controlObject + ".overrideShading", 0)
        cmds.connectAttr(
            animationModuleNamespace + ":module_grp.overrideColor",
            self.controlObject + ".overrideColor")

        # Add objects to container and setup attrs for global scale.
        cmds.container(animationModuleNamespace + ":module_container",
                       edit=True,
                       addNode=self.controlObject,
                       ihb=True,
                       includeNetwork=True)

        if globalScale:
            cmds.connectAttr(self.controlObject + ".scaleY",
                             self.controlObject + ".scaleX")
            cmds.connectAttr(self.controlObject + ".scaleY",
                             self.controlObject + ".scaleZ")
            cmds.aliasAttr("globalScale", self.controlObject + ".scaleY")

        # Promote attrs to top level container.
        attributes = []

        if self.translation == [True, True, True]:
            attributes.append([True, ".translate", "T"])
        else:
            attributes.extend([[translation[0], ".translateX", "TX"],
                               [translation[1], ".translateY", "TY"],
                               [translation[2], ".translateZ", "TZ"]])

        if self.rotation == [True, True, True]:
            attributes.append([True, ".rotate", "R"])
        else:
            attributes.extend([[rotation[0], ".rotateX", "RX"],
                               [rotation[1], ".rotateY", "RY"],
                               [rotation[2], ".rotateZ", "RZ"]])

        attributes.append([globalScale, ".globalScale", "scale"])

        for attrInfo in attributes:
            if attrInfo[0]:
                attributeNiceName = name + "_" + attrInfo[2]
                animationModuleInstance.publishNameToModuleContainer(
                    self.controlObject + attrInfo[1],
                    attributeNiceName,
                    publishToOuterContainers=True)

        cmds.select(self.controlObject, replace=True)
        cmds.addAttr(at="bool", defaultValue=1, k=True, ln="display")
        animationModuleInstance.publishNameToModuleContainer(
            self.controlObject + ".display",
            "display",
            publishToOuterContainers=False)

        # Create an expression to tie together module grp vis and lod.
        moduleGrp = animationModuleNamespace + ":module_grp"
        visibilityExpression = self.controlObject + ".visibility = " + self.controlObject + ".display * (" + moduleGrp + ".lod >= " + str(
            lod) + ");"
        expression = cmds.expression(n=self.controlObject +
                                     "_visibility_expression",
                                     string=visibilityExpression)
        utils.addNodeToContainer(
            animationModuleNamespace + ":module_container", expression)

        # 173 >
        axisInverse = cmds.spaceLocator(name=self.controlObject +
                                        "_axisInverse")[0]
        cmds.parent(axisInverse, self.controlObject, relative=True)
        cmds.setAttr(axisInverse + ".visibility", 0)
        utils.addNodeToContainer(animationModuleNamespace +
                                 ":module_container",
                                 axisInverse,
                                 ihb=True)

        spaceSwitchTarget = cmds.spaceLocator(name=self.controlObject +
                                              "_spaceSwitchTarget")[0]
        cmds.setAttr(spaceSwitchTarget + ".visibility", 0)
        cmds.parent(spaceSwitchTarget, self.controlObject, relative=True)
        cmds.setAttr(axisInverse + ".visibility", 0)
        utils.addNodeToContainer(animationModuleNamespace +
                                 ":module_container",
                                 axisInverse,
                                 ihb=True)

        if self.rotation == [False, False, False]:
            self.setupMirroring(blueprintModuleNamespace,
                                animationModuleNamespace, axisInverse)

        if spaceSwitching:
            self.setupSpaceSwitching(blueprintModuleNamespace,
                                     animationModuleNamespace,
                                     animationModuleInstance)

        # < 173
        return (self.controlObject, self.rootParent)