Python maya.OpenMaya.MDagPathArray() Examples

The following are 9 code examples of maya.OpenMaya.MDagPathArray(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module maya.OpenMaya , or try the search function .
Example #1
Source File: skin.py    From mgear_core with MIT License 6 votes vote down vote up
def collectInfluenceWeights(skinCls, dagPath, components, dataDic):
    weights = getCurrentWeights(skinCls, dagPath, components)

    influencePaths = OpenMaya.MDagPathArray()
    numInfluences = skinCls.__apimfn__().influenceObjects(influencePaths)
    numComponentsPerInfluence = weights.length() / numInfluences
    for ii in range(influencePaths.length()):
        influenceName = influencePaths[ii].partialPathName()
        influenceWithoutNamespace = pm.PyNode(influenceName).stripNamespace()
        # build a dictionary of {vtx: weight}. Skip 0.0 weights.
        inf_w = {
                jj: weights[jj * numInfluences + ii]
                for jj in range(numComponentsPerInfluence)
                if weights[jj * numInfluences + ii] != 0.0
                }
        # cast to float to avoid rounding errors when dividing integers?
        dataDic['vertexCount'] = int(weights.length() / float(numInfluences))
        # cast influenceWithoutNamespace as string otherwise it can end up
        # as DependNodeName(u'jointName') in the data.
        dataDic['weights'][str(influenceWithoutNamespace)] = inf_w 
Example #2
Source File: skinio.py    From cmt with MIT License 6 votes vote down vote up
def gather_influence_weights(self, dag_path, components):
        """Gathers all the influence weights

        :param dag_path: MDagPath of the deformed geometry.
        :param components: Component MObject of the deformed components.
        """
        weights = self.__get_current_weights(dag_path, components)

        influence_paths = OpenMaya.MDagPathArray()
        influence_count = self.fn.influenceObjects(influence_paths)
        components_per_influence = weights.length() // influence_count
        for ii in range(influence_paths.length()):
            influence_name = influence_paths[ii].partialPathName()
            # We want to store the weights by influence without the namespace so it is easier
            # to import if the namespace is different
            influence_without_namespace = shortcuts.remove_namespace_from_name(
                influence_name
            )
            self.data["weights"][influence_without_namespace] = [
                weights[jj * influence_count + ii]
                for jj in range(components_per_influence)
            ] 
Example #3
Source File: skin.py    From mgear_core with MIT License 5 votes vote down vote up
def setInfluenceWeights(skinCls, dagPath, components, dataDic, compressed):
    unusedImports = []
    weights = getCurrentWeights(skinCls, dagPath, components)
    influencePaths = OpenMaya.MDagPathArray()
    numInfluences = skinCls.__apimfn__().influenceObjects(influencePaths)
    numComponentsPerInfluence = weights.length() / numInfluences

    for importedInfluence, wtValues in dataDic['weights'].items():
        for ii in range(influencePaths.length()):
            influenceName = influencePaths[ii].partialPathName()
            nnspace = pm.PyNode(influenceName).stripNamespace()
            influenceWithoutNamespace = nnspace
            if influenceWithoutNamespace == importedInfluence:
                if compressed:
                    for jj in range(numComponentsPerInfluence):
                        # json keys can't be integers. The vtx number key
                        # is unicode. example: vtx[35] would be: u"35": 0.6974,
                        # But the binary format is still an int, so check both.
                        # if the key doesn't exist, set it to 0.0
                        wt = wtValues.get(jj) or wtValues.get(str(jj)) or 0.0
                        weights.set(wt, jj * numInfluences + ii)
                else:
                    for jj in range(numComponentsPerInfluence):
                        wt = wtValues[jj]
                        weights.set(wt, jj * numInfluences + ii)
                    break
        else:
            unusedImports.append(importedInfluence)

    influenceIndices = OpenMaya.MIntArray(numInfluences)
    for ii in range(numInfluences):
        influenceIndices.set(ii, ii)
    skinCls.__apimfn__().setWeights(dagPath,
                                    components,
                                    influenceIndices,
                                    weights,
                                    False) 
Example #4
Source File: fnData.py    From DeformationLearningSolver with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def listInfluences(self, asDagPath=True):
        """
        Returns:
          list
        """
        dagPaths = om.MDagPathArray()
        self.fn.influenceObjects(dagPaths)
        if asDagPath: return dagPaths
        else: return [dagPaths[i].partialPathName() for i in xrange(dagPaths.length())]

    #---------------------------------------------------------------------- 
Example #5
Source File: paintRemoveInfluenceCtxCommands.py    From maya-skinning-tools with GNU General Public License v3.0 5 votes vote down vote up
def reset(self):
        self._obj = None
        self._dag = None
        self._index = None
        self._influence = None
        self._influences = OpenMaya.MDagPathArray()
        self._influencesLocked = []
        
        self._skinCluster = None
        self._normalizeMode = None
        
        self.beforeSelection = OpenMaya.MIntArray()
        self.afterSelection = OpenMaya.MIntArray() 
Example #6
Source File: paintSmoothWeightsCtxCommands.py    From maya-skinning-tools with GNU General Public License v3.0 5 votes vote down vote up
def reset(self):
        self._obj = None
        self._dag = None
        self._skinCluster = None
        
        self._maxInfluences = 0
        self._normalizeMode = 0
        self._maintainMaxInfluences = False
        
        self._influences = OpenMaya.MDagPathArray()
        self._influencesLocked = [] 
Example #7
Source File: paintSmoothWeightsCtxCommands.py    From maya-skinning-tools with GNU General Public License v3.0 5 votes vote down vote up
def initialize(self, obj):
        # if no obj reset variables
        if not obj:
            self.reset()
            return 

        # get object data
        self._obj = api.asMObject(obj)
        self._dag = api.asMDagPath(self.obj)
        
        # get skin cluster
        self._skinCluster = api.asMFnSkinCluster(self.obj)
        
        # get skin cluster data
        maxPlug = self.skinCluster.findPlug("maxInfluences")
        normalPlug = self.skinCluster.findPlug("normalizeWeights")
        maintainPlug = self.skinCluster.findPlug("maintainMaxInfluences")
        
        self._maxInfluences = maxPlug.asInt()
        self._normalizeMode = normalPlug.asInt()
        self._maintainMaxInfluences = maintainPlug.asBool()
        
        # get influences
        self._influences = OpenMaya.MDagPathArray()
        self.skinCluster.influenceObjects(self._influences)
            
        # get locked influences
        self._influencesLocked = []
        for i in range(self.influences.length()):
            path = self.influences[i].fullPathName()
            locked = cmds.getAttr("{0}.liw".format(path))
            
            self._influencesLocked.append(locked)

    # ------------------------------------------------------------------------ 
Example #8
Source File: influence.py    From maya-skinning-tools with GNU General Public License v3.0 5 votes vote down vote up
def getInfluences(skinCluster):
    """
    Get all of the influence data connected to the skinCluster. This is a
    OpenMaya.MDagPathArray, OpenMaya.MIntArray() and a regular list of partial
    names.

    :param OpenMaya.MFnSkinCluster skinCluster:
    :return: Dag paths, integer and partial names
    :rtype: tuple(
        OpenMaya.MDagPathArray
        OpenMaya.MIntArray
        list of strings
    )
    """
    # variables
    influencesDag = OpenMaya.MDagPathArray()
    influencesI = OpenMaya.MIntArray()
    influencesN = []

    # get influences
    skinCluster.influenceObjects(influencesDag)

    # get influences data
    for i in range(influencesDag.length()):
        influencesI.append(i)
        influencesN.append(influencesDag[i].partialPathName())

    return influencesDag, influencesI, influencesN 
Example #9
Source File: skinio.py    From cmt with MIT License 5 votes vote down vote up
def set_influence_weights(self, dag_path, components):
        """Sets all the influence weights.

        :param dag_path: MDagPath of the deformed geometry.
        :param components: Component MObject of the deformed components.
        """
        influence_paths = OpenMaya.MDagPathArray()
        influence_count = self.fn.influenceObjects(influence_paths)

        elements = OpenMaya.MIntArray()
        fncomp = OpenMaya.MFnSingleIndexedComponent(components)
        fncomp.getElements(elements)
        weights = OpenMaya.MDoubleArray(elements.length() * influence_count)

        components_per_influence = elements.length()

        for imported_influence, imported_weights in self.data["weights"].items():
            imported_influence = imported_influence.split("|")[-1]
            for ii in range(influence_paths.length()):
                influence_name = influence_paths[ii].partialPathName()
                influence_without_namespace = shortcuts.remove_namespace_from_name(
                    influence_name
                )
                if influence_without_namespace == imported_influence:
                    # Store the imported weights into the MDoubleArray
                    for jj in range(components_per_influence):
                        weights.set(imported_weights[elements[jj]], jj * influence_count + ii)
                    break

        influence_indices = OpenMaya.MIntArray(influence_count)
        for ii in range(influence_count):
            influence_indices.set(ii, ii)
        self.fn.setWeights(dag_path, components, influence_indices, weights, False)