コード例 #1
0
    def on_action_create(self, *args):
        sName = self.ui.edtNewName.text()

        # loading Maya matrix node
        if not (cmds.pluginInfo("decomposeMatrix", query=True, loaded=True)):
            try:  # Maya 2012
                cmds.loadPlugin("decomposeMatrix.mll")
            except:
                try:  # Maya 2013 or earlier
                    cmds.loadPlugin("matrixNodes.mll")
                except:
                    print self.langDic[
                        self.langName]['e002_decomposeMatrixNotFound']

        aSel = pymel.selected()
        if (len(aSel) == 2):
            #Create the container of the system data
            pData = PoseReaderData()
            with pymel.UndoChunk():
                #Get Needed matrix information
                pData.nParent = aSel[1]
                pData.nChild = aSel[0]
                m4ParentMat = pData.nParent.getMatrix(worldSpace=True)
                m4ChildMat = pData.nChild.getMatrix(worldSpace=True)

                #Create the two node needed to extract the rotation
                pData.nPGrp = pymel.createNode("transform",
                                               name=sName +
                                               "_PoseReader_Parent_Grp",
                                               p=pData.nParent)
                pData.nPGrp.setMatrix(m4ChildMat, worldSpace=True)
                pData.nParentLoc = self.createLoc(
                    sName + "_AngExtract_ParentLoc", pData.nPGrp)

                pData.nCGrp = pymel.createNode("transform",
                                               name=sName +
                                               "_PoseReader_Child_Grp",
                                               p=pData.nChild)
                pData.nCGrp.setMatrix(m4ChildMat, worldSpace=True)
                pData.nChildLoc = self.createLoc(
                    sName + "_AngExtract_ChildLoc", pData.nCGrp)
                #Add usefull attributes for the tool
                pData.nChildLoc.setDynamicAttr("posereaderdata", True)
                pData.nChildLoc.addAttr("angleMaxValue", min=-360.0, max=360.0)
                pData.nChildLoc.setAttr("angleMaxValue",
                                        180,
                                        edit=True,
                                        keyable=False,
                                        lock=False)
                pData.nChildLoc.addAttr("axis", at="enum", enumName="X:Y:Z")
                pData.nChildLoc.setAttr("axis",
                                        1,
                                        edit=True,
                                        keyable=False,
                                        lock=False)

                #Setup the rotation extaction
                pData.nMultM = pymel.createNode("multMatrix",
                                                name=sName + "_ExtactAngle_MM")
                pymel.connectAttr(pData.nChildLoc.worldMatrix[0],
                                  pData.nMultM.matrixIn[0])
                pymel.connectAttr(pData.nParentLoc.worldInverseMatrix[0],
                                  pData.nMultM.matrixIn[1])
                pData.nDecM = pymel.createNode("decomposeMatrix",
                                               name=sName + "_ExtractAngle_DM")
                pymel.connectAttr(pData.nMultM.matrixSum,
                                  pData.nDecM.inputMatrix)

                #Setup the rotation affection
                pData.nMD = pymel.createNode("multiplyDivide",
                                             name=sName + "_NormValue_MD")
                pData.nMD.operation.set(2)
                pymel.connectAttr(pData.nDecM.outputRotateY, pData.nMD.input1X)
                pymel.connectAttr(pData.nChildLoc.angleMaxValue,
                                  pData.nMD.input2X)
                pData.nCD = pymel.createNode("condition",
                                             name=sName + "_SmallerThanOne_CD")
                pymel.connectAttr(pData.nMD.outputX, pData.nCD.firstTerm)
                pymel.connectAttr(pData.nMD.outputX, pData.nCD.colorIfTrueR)
                pData.nCD.secondTerm.set(1)
                pData.nCD.operation.set(5)  #Less or equal
                pData.nCDNoNeg = pymel.createNode("condition",
                                                  name=sName + "_OverZero_CD")
                pymel.connectAttr(pData.nCD.outColorR,
                                  pData.nCDNoNeg.firstTerm)
                pymel.connectAttr(pData.nCD.outColorR,
                                  pData.nCDNoNeg.colorIfTrueR)
                pData.nCDNoNeg.secondTerm.set(0)
                pData.nCDNoNeg.colorIfFalseR.set(0)
                pData.nCDNoNeg.operation.set(3)  #Greater or Equal

                #Node for manual activation connection
                pData.nMDActive = pymel.createNode("multiplyDivide",
                                                   name=sName + "_Active_MD")
                pymel.connectAttr(pData.nCDNoNeg.outColorR,
                                  pData.nMDActive.input1X)

            #for o in pData.__dict__:
            #print o

            libSerialization.export_network(pData)
            self.addItem(pData)
        else:
            pymel.confirmDialog(
                title='Selection Problem',
                message='You need to have exactly two nodes selected')
コード例 #2
0
    def _action_execute(self):
        """
        Manage the different action that can happen on the tool. Will change depending on the selection
        """
        if (self.action == "#create"):

            if pymel.referenceQuery(self.nSelDriven, isNodeReferenced=True):
                bCreateParent = False
            else:
                bCreateParent = not self.ui.chkUseParent.isChecked()
            pNewSp = SpaceSwitcherLogic()
            with pymel.UndoChunk():
                if self.aSelDrivers:
                    pNewSp.setup_space_switch(self.nSelDriven,
                                              self.aSelDrivers,
                                              bCreateWolrdNode=False,
                                              bCreateParent=bCreateParent)
                else:  #There is no drivers, so the user want the world to be one of them
                    pNewSp.setup_space_switch(self.nSelDriven,
                                              self.aSelDrivers,
                                              bCreateWolrdNode=True,
                                              bCreateParent=bCreateParent)
            self._update_parentList(pNewSp)
            pNewSp.pNetwork = libSerialization.export_network(pNewSp)
            self.aSceneSpaceSwitch.append(pNewSp)
            pymel.select(self.nSelDriven)

        elif (self.action == "#add"):
            self.pSelSpSys.add_target(self.aSelDrivers)
            self._update_parentList(self.pSelSpSys)
            #Delete the old network before updating a new one
            if (self.pSelSpSys.pNetwork):
                pymel.delete(self.pSelSpSys.pNetwork)
                self.pSelSpSys.pNetwork = None
            self.pSelSpSys.pNetwork = libSerialization.export_network(
                self.pSelSpSys)
            pymel.select(self.nSelDriven)

        elif (self.action == "#switch"):
            pCurParent = self.ui.lstParent.selectedIndexes()[0]
            #Remove one to the index since the original parent doesn't really exist in the list of parent in the system
            self.pSelSpSys.do_switch(pCurParent.row() - 1)

        elif (self.action == "#remove"):
            for iIdx in self.toRemove:
                self.pSelSpSys.remove_target(iIdx - 1)

            #Check if it worth it to keep the system, if not, delete the network and parent constraint
            if not self.pSelSpSys.aDrivers:
                self.aSceneSpaceSwitch.remove(self.pSelSpSys)
                if (self.pSelSpSys.nSwConst):
                    pymel.delete(self.pSelSpSys.nSwConst)
                if (self.pSelSpSys.pNetwork):
                    pymel.delete(self.pSelSpSys.pNetwork)

                #Return to the create state action since the node is still selected, but everything is deleted
                self.action = "#create"
                self.ui.lblStatus.setText("Driven Node --> " +
                                          str(self.nSelDriven) + "")
                self.ui.lblStatus.setText(
                    self.ui.lblStatus.text() + " " +
                    self.colorTemplate.format("yellow", "(First Setup)"))
                self.ui.btnAction.setEnabled(True)
                self.ui.btnAction.setText("Setup Space Switch System for [" +
                                          self.nSelDriven.name() + "]")
            else:
                if (self.pSelSpSys.pNetwork):
                    pymel.delete(self.pSelSpSys.pNetwork)
                    self.pSelSpSys.pNetwork = None
                self.pSelSpSys.pNetwork = libSerialization.export_network(
                    self.pSelSpSys)
                pymel.select(self.nSelDriven)

            self._update_parentList(self.pSelSpSys)
コード例 #3
0
    def _action_execute(self):
        """
        Manage the different action that can happen on the tool. Will change depending on the selection
        """
        if (self.action == "#create"):

            if pymel.referenceQuery(self.nSelDriven, isNodeReferenced=True):
                bCreateParent = False
            else:
                bCreateParent = not self.ui.chkUseParent.isChecked()
            pNewSp = SpaceSwitcherLogic()
            with pymel.UndoChunk():
                if self.aSelDrivers:
                    pNewSp.setup_space_switch(self.nSelDriven, self.aSelDrivers, bCreateWolrdNode=False, bCreateParent=bCreateParent)
                else: #There is no drivers, so the user want the world to be one of them
                    pNewSp.setup_space_switch(self.nSelDriven, self.aSelDrivers, bCreateWolrdNode=True, bCreateParent=bCreateParent)
            self._update_parentList(pNewSp)
            pNewSp.pNetwork = libSerialization.export_network(pNewSp)
            self.aSceneSpaceSwitch.append(pNewSp)
            pymel.select(self.nSelDriven)

        elif (self.action == "#add"):
            self.pSelSpSys.add_target(self.aSelDrivers)
            self._update_parentList(self.pSelSpSys)
            #Delete the old network before updating a new one
            if (self.pSelSpSys.pNetwork):
                pymel.delete(self.pSelSpSys.pNetwork)
                self.pSelSpSys.pNetwork = None
            self.pSelSpSys.pNetwork = libSerialization.export_network(self.pSelSpSys)
            pymel.select(self.nSelDriven)

        elif (self.action == "#switch"):
            pCurParent = self.ui.lstParent.selectedIndexes()[0]
            #Remove one to the index since the original parent doesn't really exist in the list of parent in the system
            self.pSelSpSys.do_switch(pCurParent.row() - 1)

        elif (self.action == "#remove"):
            for iIdx in self.toRemove:
                self.pSelSpSys.remove_target(iIdx - 1)

            #Check if it worth it to keep the system, if not, delete the network and parent constraint
            if not self.pSelSpSys.aDrivers:
                self.aSceneSpaceSwitch.remove(self.pSelSpSys)
                if (self.pSelSpSys.nSwConst):
                    pymel.delete(self.pSelSpSys.nSwConst)
                if (self.pSelSpSys.pNetwork):
                    pymel.delete(self.pSelSpSys.pNetwork)

                #Return to the create state action since the node is still selected, but everything is deleted
                self.action = "#create"
                self.ui.lblStatus.setText("Driven Node --> " + str(self.nSelDriven) + "")
                self.ui.lblStatus.setText(self.ui.lblStatus.text() + " " + self.colorTemplate.format("yellow", "(First Setup)"))
                self.ui.btnAction.setEnabled(True)
                self.ui.btnAction.setText("Setup Space Switch System for [" + self.nSelDriven.name() + "]")
            else:
                if (self.pSelSpSys.pNetwork):
                    pymel.delete(self.pSelSpSys.pNetwork)
                    self.pSelSpSys.pNetwork = None
                self.pSelSpSys.pNetwork = libSerialization.export_network(self.pSelSpSys)
                pymel.select(self.nSelDriven)

            self._update_parentList(self.pSelSpSys)
コード例 #4
0
    def on_action_create(self, *args):
        sName = self.ui.edtNewName.text()

        # loading Maya matrix node
        if not (cmds.pluginInfo("decomposeMatrix", query=True, loaded=True)):
            try: # Maya 2012
                cmds.loadPlugin("decomposeMatrix.mll")
            except:
                try: # Maya 2013 or earlier
                    cmds.loadPlugin("matrixNodes.mll")
                except:
                    print self.langDic[self.langName]['e002_decomposeMatrixNotFound']
                    
        aSel = pymel.selected()
        if (len(aSel) == 2):
            #Create the container of the system data
            pData = PoseReaderData()
            with pymel.UndoChunk():
                #Get Needed matrix information
                pData.nParent = aSel[1]
                pData.nChild = aSel[0]
                m4ParentMat = pData.nParent.getMatrix(worldSpace=True)
                m4ChildMat = pData.nChild.getMatrix(worldSpace=True)

                #Create the two node needed to extract the rotation
                pData.nPGrp = pymel.createNode("transform", name=sName + "_PoseReader_Parent_Grp", p=pData.nParent)
                pData.nPGrp.setMatrix(m4ChildMat, worldSpace=True)
                pData.nParentLoc = self.createLoc(sName+"_AngExtract_ParentLoc", pData.nPGrp)

                pData.nCGrp = pymel.createNode("transform", name=sName+"_PoseReader_Child_Grp", p=pData.nChild)
                pData.nCGrp.setMatrix(m4ChildMat, worldSpace=True)
                pData.nChildLoc = self.createLoc(sName+"_AngExtract_ChildLoc", pData.nCGrp)
                #Add usefull attributes for the tool
                pData.nChildLoc.setDynamicAttr("posereaderdata", True)
                pData.nChildLoc.addAttr("angleMaxValue", min=-360.0, max=360.0)
                pData.nChildLoc.setAttr("angleMaxValue", 180, edit=True, keyable=False, lock=False)
                pData.nChildLoc.addAttr("axis", at="enum", enumName="X:Y:Z")
                pData.nChildLoc.setAttr("axis", 1, edit=True, keyable=False, lock=False)

                #Setup the rotation extaction
                pData.nMultM = pymel.createNode("multMatrix", name=sName+"_ExtactAngle_MM")
                pymel.connectAttr(pData.nChildLoc.worldMatrix[0], pData.nMultM.matrixIn[0])
                pymel.connectAttr(pData.nParentLoc.worldInverseMatrix[0], pData.nMultM.matrixIn[1])
                pData.nDecM = pymel.createNode("decomposeMatrix", name=sName+"_ExtractAngle_DM")
                pymel.connectAttr(pData.nMultM.matrixSum, pData.nDecM.inputMatrix)

                #Setup the rotation affection
                pData.nMD = pymel.createNode("multiplyDivide", name=sName+"_NormValue_MD")
                pData.nMD.operation.set(2)
                pymel.connectAttr(pData.nDecM.outputRotateY, pData.nMD.input1X)
                pymel.connectAttr(pData.nChildLoc.angleMaxValue, pData.nMD.input2X)
                pData.nCD = pymel.createNode("condition", name=sName+"_SmallerThanOne_CD")
                pymel.connectAttr(pData.nMD.outputX, pData.nCD.firstTerm)
                pymel.connectAttr(pData.nMD.outputX, pData.nCD.colorIfTrueR)
                pData.nCD.secondTerm.set(1)
                pData.nCD.operation.set(5) #Less or equal
                pData.nCDNoNeg = pymel.createNode("condition", name=sName+"_OverZero_CD")
                pymel.connectAttr(pData.nCD.outColorR, pData.nCDNoNeg.firstTerm)
                pymel.connectAttr(pData.nCD.outColorR, pData.nCDNoNeg.colorIfTrueR)
                pData.nCDNoNeg.secondTerm.set(0)
                pData.nCDNoNeg.colorIfFalseR.set(0)
                pData.nCDNoNeg.operation.set(3) #Greater or Equal

                #Node for manual activation connection
                pData.nMDActive = pymel.createNode("multiplyDivide", name=sName+"_Active_MD")
                pymel.connectAttr(pData.nCDNoNeg.outColorR, pData.nMDActive.input1X)

            #for o in pData.__dict__:
                #print o

            libSerialization.export_network(pData)
            self.addItem(pData)
        else:
            pymel.confirmDialog( title='Selection Problem', message='You need to have exactly two nodes selected')