Exemplo n.º 1
0
 def changeJointNumber(self, enteredNJoints, *args):
     """ Edit the number of joints in the guide.
     """
     utils.useDefaultRenderLayer()
     # get the number of joints entered by user:
     if enteredNJoints == 0:
         try:
             self.enteredNJoints = cmds.intField(self.nJointsIF, query=True, value=True)
         except:
             return
     else:
         self.enteredNJoints = enteredNJoints
     # get the number of joints existing:
     self.currentNJoints = cmds.getAttr(self.moduleGrp + ".nJoints")
     # start analisys the difference between values:
     if self.enteredNJoints != self.currentNJoints:
         self.cvEndJoint = self.guideName + "_JointEnd"
         if self.currentNJoints > 1:
             # delete current point constraints:
             for n in range(2, self.currentNJoints):
                 cmds.delete(self.guideName + "_ParentConstraint" + str(n))
         # verify if the nJoints is greather or less than the current
         if self.enteredNJoints > self.currentNJoints:
             # add the new cvLocators:
             for n in range(self.currentNJoints + 1, self.enteredNJoints + 1):
                 # create another N cvLocator:
                 self.cvLocator, shapeSizeCH = ctrls.cvLocator(ctrlName=self.guideName + "_JointLoc" + str(n), r=0.3)
                 self.connectShapeSize(shapeSizeCH)
                 # set its nJoint value as n:
                 cmds.setAttr(self.cvLocator + ".nJoint", n)
                 # parent its group to the first cvJointLocator:
                 self.cvLocGrp = cmds.group(self.cvLocator, name=self.cvLocator + "_Grp")
                 cmds.parent(self.cvLocGrp, self.guideName + "_JointLoc" + str(n - 1), relative=True)
                 cmds.setAttr(self.cvLocGrp + ".translateZ", 2)
                 if n > 2:
                     cmds.parent(self.cvLocGrp, self.guideName + "_JointLoc1", absolute=True)
         elif self.enteredNJoints < self.currentNJoints:
             # re-parent cvEndJoint:
             self.cvLocator = self.guideName + "_JointLoc" + str(self.enteredNJoints)
             cmds.parent(self.cvEndJoint, world=True)
             # delete difference of nJoints:
             for n in range(self.enteredNJoints, self.currentNJoints):
                 # re-parent the children guides:
                 childrenGuideBellowList = utils.getGuideChildrenList(
                     self.guideName + "_JointLoc" + str(n + 1) + "_Grp"
                 )
                 if childrenGuideBellowList:
                     for childGuide in childrenGuideBellowList:
                         cmds.parent(childGuide, self.cvLocator)
                 cmds.delete(self.guideName + "_JointLoc" + str(n + 1) + "_Grp")
         # re-parent cvEndJoint:
         cmds.parent(self.cvEndJoint, self.cvLocator)
         cmds.setAttr(self.cvEndJoint + ".tz", 1.3)
         cmds.setAttr(self.cvEndJoint + ".visibility", 0)
         # re-create parentConstraints:
         if self.enteredNJoints > 1:
             for n in range(2, self.enteredNJoints):
                 self.parentConst = cmds.parentConstraint(
                     self.guideName + "_JointLoc1",
                     self.cvEndJoint,
                     self.guideName + "_JointLoc" + str(n) + "_Grp",
                     name=self.guideName + "_ParentConstraint" + str(n),
                     maintainOffset=True,
                 )[0]
                 nParentValue = (n - 1) / float(self.enteredNJoints - 1)
                 cmds.setAttr(self.parentConst + ".Guide_JointLoc1W0", 1 - nParentValue)
                 cmds.setAttr(self.parentConst + ".Guide_JointEndW1", nParentValue)
                 ctrls.setLockHide([self.guideName + "_JointLoc" + str(n)], ["rx", "ry", "rz", "sx", "sy", "sz"])
         # actualise the nJoints in the moduleGrp:
         cmds.setAttr(self.moduleGrp + ".nJoints", self.enteredNJoints)
         self.currentNJoints = self.enteredNJoints
         # re-build the preview mirror:
         Layout.LayoutClass.createPreviewMirror(self)
     cmds.select(self.moduleGrp)
Exemplo n.º 2
0
 def createPreviewMirror(self, *args):
     # re-declaring guideMirror and previewMirror groups:
     self.previewMirrorGrpName = self.moduleGrp[:self.moduleGrp.find(":")]+'_MirrorGrp'
     if cmds.objExists(self.previewMirrorGrpName):
         cmds.delete(self.previewMirrorGrpName)
     
     # verify if there is not any guide module in the guideMirrorGrp and then delete it:
     self.guideMirrorGrp = 'dpAR_GuideMirror_Grp'
     utils.clearNodeGrp(nodeGrpName=self.guideMirrorGrp, attrFind='guideBaseMirror', unparent=False)
     
     # get children, verifying if there are children guides:
     guideChildrenList = utils.getGuideChildrenList(self.moduleGrp)
     
     self.mirrorAxis = cmds.getAttr(self.moduleGrp+".mirrorAxis")
     if self.mirrorAxis != 'off':
         if not cmds.objExists(self.guideMirrorGrp):
             self.guideMirrorGrp = cmds.group(name=self.guideMirrorGrp, empty=True)
             cmds.setAttr(self.guideMirrorGrp+".template", 1)
             cmds.addAttr(self.guideMirrorGrp, longName="selectionChanges", defaultValue=0, attributeType="byte")
         if not cmds.objExists(self.previewMirrorGrpName):
             if guideChildrenList:
                 guideFatherNameList = []
                 for guideChild in guideChildrenList:
                     # get guide father name:
                     guideFatherName = cmds.listRelatives(guideChild, parent=True)
                     guideFatherNameList.append(guideFatherName)
                     # unparent this child guide in order to make the mirror and after return it to the parent:
                     cmds.parent(guideChild, world=True)
                     # set child guide as not mirrorable:
                     cmds.setAttr(guideChild+".mirrorEnable", 0)
                     # get initial values from father guide base:
                     fatherMirrorName = cmds.getAttr(self.moduleGrp+".mirrorName")
                     # set values to guide base:
                     cmds.setAttr(guideChild+".mirrorAxis", self.mirrorAxis, type='string')
                     cmds.setAttr(guideChild+".mirrorName", fatherMirrorName, type='string')
             
             # duplicating the moduleGuide
             duplicated = cmds.duplicate(self.moduleGrp, returnRootsOnly=True)[0]
             duplicatedList = cmds.listRelatives(duplicated, allDescendents=True, fullPath=True)
             # renaming  and reShaping all its children nodes:
             if duplicatedList:
                 for dup in duplicatedList:
                     if cmds.objExists(dup):
                         if "_RadiusCtrl" in dup or "_Ant" in dup:
                             cmds.delete(dup)
                         else:
                             if cmds.objectType(dup) == 'transform' or cmds.objectType(dup) == 'joint':
                                 # rename duplicated node:
                                 dupRenamed = cmds.rename(dup, self.moduleGrp[:self.moduleGrp.find(":")]+'_'+dup[dup.rfind("|")+1:]+'_Mirror')
                                 originalGuide = self.moduleGrp[:self.moduleGrp.find(":")+1]+dup[dup.rfind("|")+1:]
                                 # unlock and unhide all attributes and connect original guide node transformations to the mirror guide node:
                                 attrList = ['translateX', 'translateY', 'translateZ', 'rotateX', 'rotateY', 'rotateZ', 'scaleX', 'scaleY', 'scaleZ']
                                 for attr in attrList:
                                     cmds.setAttr(dupRenamed+"."+attr, lock=False, keyable=True)
                                     cmds.connectAttr(originalGuide+'.'+attr, dupRenamed+'.'+attr, force=True)
                                 
                                 # rebuild the shape as a nurbsSphere:
                                 if cmds.objectType(dupRenamed) == 'transform':
                                     childrenShapeList = cmds.listRelatives(dupRenamed, shapes=True, children=True)
                                     if childrenShapeList:
                                         cmds.delete(childrenShapeList)
                                         newSphere = cmds.sphere(name=dupRenamed+"Sphere", radius=0.1, constructionHistory=False)
                                         newSphereShape = cmds.listRelatives(newSphere, shapes=True, children=True)[0]
                                         cmds.parent(newSphereShape, dupRenamed, shape=True, relative=True)
                                         cmds.delete(newSphere)
                             elif cmds.objectType(dup) != 'nurbsCurve':
                                 cmds.delete(dup)
             
             # renaming the previewMirrorGuide:
             self.previewMirrorGuide = cmds.rename(duplicated, self.moduleGrp.replace(":", "_")+'_Mirror')
             cmds.delete(self.previewMirrorGuide+'Shape')
             
             # create a decomposeMatrix node in order to get the worldSpace transformations (like using xform):
             decomposeMatrix = cmds.createNode('decomposeMatrix', name=self.previewMirrorGuide+"_dm")
             cmds.connectAttr(self.moduleGrp+'.worldMatrix', decomposeMatrix+'.inputMatrix', force=True)
             
             # connect original guide base decomposeMatrix node output transformations to the mirror guide base node:
             axisList = ['X', 'Y', 'Z']
             for axis in axisList:
                 cmds.connectAttr(decomposeMatrix+'.outputTranslate'+axis, self.previewMirrorGuide+'.translate'+axis, force=True)
                 cmds.connectAttr(decomposeMatrix+'.outputRotate'+axis, self.previewMirrorGuide+'.rotate'+axis, force=True)
                 cmds.connectAttr(decomposeMatrix+'.outputScale'+axis, self.previewMirrorGuide+'.scale'+axis, force=True)
             
             # analysis if there were children guides for this guide in order to re-parent them:
             if guideChildrenList:
                 for p, guideChild in enumerate(guideChildrenList):
                     # re-parent this child guide to the correct guideFatherName:
                     cmds.parent(guideChild, guideFatherNameList[p])
             
             # create previewMirror group:
             self.previewMirrorGrp = cmds.group(name=self.previewMirrorGrpName, empty=True)
             cmds.parent( self.previewMirrorGuide, self.previewMirrorGrpName, absolute=True )
             # parent the previewMirror group to the guideMirror group:
             cmds.parent(self.previewMirrorGrp, self.guideMirrorGrp, relative=True)
             
             # add attributes to be read as mirror guide when re-creating this module:
             cmds.addAttr(self.previewMirrorGrp, longName='guideBaseMirror', attributeType='bool')
             cmds.setAttr(self.previewMirrorGrp+".guideBaseMirror", 1)
         
         # reset all scale values to 1:
         cmds.setAttr(self.previewMirrorGrp+'.scaleX', 1)
         cmds.setAttr(self.previewMirrorGrp+'.scaleY', 1)
         cmds.setAttr(self.previewMirrorGrp+'.scaleZ', 1)
         # set a negative value to the scale mirror axis:
         for axis in self.mirrorAxis:
             cmds.setAttr(self.previewMirrorGrp+'.scale'+axis, -1)
     
     else:
         if guideChildrenList:
             for guideChild in guideChildrenList:
                 # get initial values from father guide base:
                 fatherMirrorName = cmds.getAttr(self.moduleGrp+".mirrorName")
                 # set values to guide base:
                 cmds.setAttr(guideChild+".mirrorAxis", "off", type='string')
                 cmds.setAttr(guideChild+".mirrorName", fatherMirrorName, type='string')
     
     cmds.select(self.moduleGrp)
Exemplo n.º 3
0
 def changeJointNumber(self, enteredNJoints, *args):
     """ Edit the number of joints in the guide.
     """
     utils.useDefaultRenderLayer()
     # get the number of joints entered by user:
     if enteredNJoints == 0:
         try:
             self.enteredNJoints = cmds.intField(self.nJointsIF, query=True, value=True)
         except:
             return
     else:
         self.enteredNJoints = enteredNJoints
     # get the number of joints existing:
     self.currentNJoints = cmds.getAttr(self.moduleGrp+".nJoints")
     # start analisys the difference between values:
     if self.enteredNJoints != self.currentNJoints:
         # check if the controls have scale changed values in order to avoid the transform groups created from maya without namespace:
         scaledCtrl = False
         scaledCtrlDic = {}
         for j in range(1, self.currentNJoints+1):
             if cmds.getAttr(self.guideName+"_JointLoc"+str(j)+".scaleX") != 1 or cmds.getAttr(self.guideName+"_JointLoc"+str(j)+".scaleY") != 1 or cmds.getAttr(self.guideName+"_JointLoc"+str(j)+".scaleZ") != 1:
                 scaledCtrl = True
                 # get scale values:
                 scaledX = cmds.getAttr(self.guideName+"_JointLoc"+str(j)+".scaleX")
                 scaledY = cmds.getAttr(self.guideName+"_JointLoc"+str(j)+".scaleY")
                 scaledZ = cmds.getAttr(self.guideName+"_JointLoc"+str(j)+".scaleZ")
                 # store scale values in the dictionary:
                 scaledCtrlDic[j] = [scaledX, scaledY, scaledZ]
                 # reset scales values to 1,1,1:
                 cmds.setAttr(self.guideName+"_JointLoc"+str(j)+".scaleX", 1)
                 cmds.setAttr(self.guideName+"_JointLoc"+str(j)+".scaleY", 1)
                 cmds.setAttr(self.guideName+"_JointLoc"+str(j)+".scaleZ", 1)
         # unparent temporarely the Ends:
         self.cvEndJoint = self.guideName+"_JointEnd"
         cmds.parent(self.cvEndJoint, world=True)
         self.jGuideEnd = (self.guideName+"_JGuideEnd")
         cmds.parent(self.jGuideEnd, world=True)
         # verify if the nJoints is greather or less than the current
         if self.enteredNJoints > self.currentNJoints:
             for n in range(self.currentNJoints+1, self.enteredNJoints+1):
                 # create another N cvJointLoc:
                 self.cvJointLoc, shapeSizeCH = ctrls.cvJointLoc( ctrlName=self.guideName+"_JointLoc"+str(n), r=0.3 )
                 self.connectShapeSize(shapeSizeCH)
                 # set its nJoint value as n:
                 cmds.setAttr(self.cvJointLoc+".nJoint", n)
                 # parent it to the lastGuide:
                 cmds.parent(self.cvJointLoc, self.guideName+"_JointLoc"+str(n-1), relative=True)
                 cmds.setAttr(self.cvJointLoc+".translateZ", 2)
                 # create a joint to use like an arrowLine:
                 self.jGuide = cmds.joint(name=self.guideName+"_JGuide"+str(n), radius=0.001)
                 cmds.setAttr(self.jGuide+".template", 1)
                 cmds.parent(self.jGuide, self.guideName+"_JGuide"+str(n-1))
                 cmds.parentConstraint(self.cvJointLoc, self.jGuide, maintainOffset=True, name=self.jGuide+"_ParentConstraint")
                 cmds.scaleConstraint(self.cvJointLoc, self.jGuide, maintainOffset=True, name=self.jGuide+"_ScaleConstraint")
         elif self.enteredNJoints < self.currentNJoints:
             # re-define cvEndJoint:
             self.cvJointLoc = self.guideName+"_JointLoc"+str(self.enteredNJoints)
             self.cvEndJoint = self.guideName+"_JointEnd"
             self.jGuide = self.guideName+"_JGuide"+str(self.enteredNJoints)
             # re-parent the children guides:
             childrenGuideBellowList = utils.getGuideChildrenList(self.cvJointLoc)
             if childrenGuideBellowList:
                 for childGuide in childrenGuideBellowList:
                     cmds.parent(childGuide, self.cvJointLoc)
             # delete difference of nJoints:
             cmds.delete(self.guideName+"_JointLoc"+str(self.enteredNJoints+1))
             cmds.delete(self.guideName+"_JGuide"+str(self.enteredNJoints+1))
         # re-parent cvEndJoint:
         cmds.parent(self.cvEndJoint, self.cvJointLoc)
         cmds.setAttr(self.cvEndJoint+".tz", 1.3)
         cmds.parent(self.jGuideEnd, self.jGuide)
         # actualise the nJoints in the moduleGrp:
         cmds.setAttr(self.moduleGrp+".nJoints", self.enteredNJoints)
         self.currentNJoints = self.enteredNJoints
         # reset changed scale values again:
         if scaledCtrl:
             for j in scaledCtrlDic:
                 if cmds.objExists(self.guideName+"_JointLoc"+str(j)):
                     cmds.setAttr(self.guideName+"_JointLoc"+str(j)+".scaleX", scaledCtrlDic[j][0])
                     cmds.setAttr(self.guideName+"_JointLoc"+str(j)+".scaleY", scaledCtrlDic[j][1])
                     cmds.setAttr(self.guideName+"_JointLoc"+str(j)+".scaleZ", scaledCtrlDic[j][2])
         # re-build the preview mirror:
         Layout.LayoutClass.createPreviewMirror(self)
     cmds.select(self.moduleGrp)