Пример #1
0
    def resetSkinInfluences(self):

        """
        !@Brief Reset skin influences weights.
        """

        self.setInfluences(self.INFLUENCES.values(), lock_value=False)
        points_shape = len(pmc.ls("%s.cp[*]" % self.SHAPE.name(), flatten=True))

        progress_bar = ProgressBar(len(self.INFLUENCES.values()), "Reset Influences")
        influences = []
        for idf, (key, value) in enumerate(self.INFLUENCES.items()):
            influences.append((value, 0.0))
            progress_bar.update(idf)
        progress_bar.kill()

        component_type = 'vtx'
        if isinstance(self.SHAPE, (pmc.nodetypes.NurbsSurface, pmc.nodetypes.NurbsCurve)):
            component_type = 'cv'

        pmc.skinPercent(
            self.SKIN_NODE.name(),
            ('%s.%s[0:%s]' % (self.SHAPE, component_type, points_shape)),
            transformValue=influences
        )
Пример #2
0
    def getBindPrematrix(self):

        """
        !@Brief Get BindPreMatrix node of SkinCluster

        :rtype: dict:
        :return: Dictionnary of BindPreMatrix node and connection Attribute. {"Input name": [Skin pymel.core.general.Attribute, Input pymel.core.general.Attribute]}
        """

        #   Check
        if not self.SKIN_NODE:
            raise RuntimeError("\n\tNo SkinCluster given !!!\n")

        #   Get BindPreMatrix connections
        bpm_connections = self.SKIN_NODE.bindPreMatrix.inputs(plugs=True, connections=True)

        #   Push connection to dict
        BIND_PRE_MATRIX = {}
        progress_bar = ProgressBar(len(bpm_connections), "Get BindPreMatrix")

        for idx, bpm_connection in enumerate(bpm_connections):
            input_name = bpm_connection[1].name().split(".")[0]
            BIND_PRE_MATRIX[input_name] = bpm_connection

            progress_bar.update(idx)
        progress_bar.kill()

        return BIND_PRE_MATRIX
Пример #3
0
    def getSkinInfluences(self):

        """
        !@Brief Get influences of SkinCluster with maya API

        :rtype: dict
        :return: Dictionnary of influences nodes. {"Skin input index": pymel.core.nodetypes}
        """

        #   Check
        if not self.MFN_SKIN:
            raise RuntimeError("\n\tNo SkinCluster given !!!\n")

        #   Get influences in MDagPathArray
        influences_dagpath = OpenMaya.MDagPathArray()
        self.MFN_SKIN.influenceObjects(influences_dagpath)

        #   Transform MDagPathArray to python dict
        progress_bar = ProgressBar(influences_dagpath.length(), "Get skin influecnes")
        skin_influences = {}
        for index in xrange(influences_dagpath.length()):
            influence_path = influences_dagpath[index].partialPathName()
            influence_id = self.MFN_SKIN.indexForInfluenceObject(influences_dagpath[index])
            skin_influences[influence_id] = influence_path

            progress_bar.update(index)
        progress_bar.kill()

        return skin_influences
Пример #4
0
    def setSkinWeight(self):

        """
        !@Brief Set SkinCluster weight from SkinTools instance.
        """

        progress_bar = ProgressBar(len(self.WEIGHTS), "Set Skin Weights")

        for idl, influences in self.WEIGHTS.items():
            for idf, weight in influences.items():
                self.SKIN_NODE.attr("weightList[%d].weights[%d]" % (idl, idf)).set(weight)

            progress_bar.update(idl)
        progress_bar.kill()
Пример #5
0
    def setBindPreMatrix(self):

        """
        !@Brief Connect BindPreMatrix to SkinCluster.
        """

        #   Check
        if not self.SKIN_NODE:
            raise RuntimeError("\n\tNo datas for restore SkinCluster !!!\n")

        #   Connect nodes
        progress_bar = ProgressBar(len(self.WEIGHTS), "Set Skin Weights")

        for idb, attributes in enumerate(self.BIND_PRE_MATRIX.values()):
            attributes[1] >> attributes[0]
            progress_bar.update(idb)
        progress_bar.kill()
Пример #6
0
    def getSkinWeights(self):

        """
        !@Brief Get SkinCluster weight with maya API

        :rtype: dict
        :return: Dictionnary of weight influences. {"Point index": {"Skin input index": weight value}}
        """

        #   Check
        if not self.MFN_SKIN:
            raise RuntimeError("\n\tNo SkinCluster given !!!\n")

        #   Get weights attribute
        weight_list = self.MFN_SKIN.findPlug('weightList')
        weights = self.MFN_SKIN.findPlug('weights')
        attribute = weight_list.attribute()
        weights_attributes = weights.attribute()
        influences_id = OpenMaya.MIntArray()

        #   Get Weights datas and push to python dict
        dic_weight = {}
        progress_bar = ProgressBar(weight_list.numElements(), "Get Skin Weights")

        for idx in xrange(weight_list.numElements()):

            #   Get influences nodes associate to vertex
            weights.selectAncestorLogicalIndex(idx, attribute)
            weights.getExistingArrayAttributeIndices(influences_id)
            influences = OpenMaya.MPlug(weights)

            dic_weight[idx] = {}

            #   Get weight of influences nodes
            for idf in influences_id:
                influences.selectAncestorLogicalIndex(idf, weights_attributes)
                dic_weight[idx][idf] = influences.asDouble()

            progress_bar.update(idx)
        progress_bar.kill()

        return dic_weight
Пример #7
0
    def setInfluences(cls, influences, lock_value):

        """
        !@Brief Lock/Unlock influences of SkinCluster.

        :type influences: list
        :param influences: List of influences node or influences name
        :type lock_value: bool
        :param lock_value: Value of lock
        """

        progress_bar = ProgressBar(len(influences), "Set Influences")

        for idf, inf in enumerate(influences):

            if isinstance(inf, basestring):
                inf = pmc.PyNode(inf)

            if inf.hasAttr('liw'):
                inf.liw.set(lock_value)

            progress_bar.update(idf)
        progress_bar.kill()