Beispiel #1
0
def setInfluenceWeights(skinCluster,
                        influence,
                        weightList,
                        normalize=True,
                        componentList=[]):
    ''' Set the weights of an influence for a specified skinCluster using an input weight list
    :param skinCluster str: SkinCluster to set influence weights for
    :param influence str: Influence to set weights for
    :param weightList list: Influence weight list to apply.
    :param normalize bool: Normalize weights as they are applied
    :param componentList list: List of components to set weights for
    :return: list of old weights
    :rtype: list
    '''
    # Verify skinCluster
    if not isSkinCluster(skinCluster):
        raise Exception(
            'Invalid skinCluster {0} specified!'.format(skinCluster))

    # Check influence
    if not cmds.objExists(influence):
        raise Exception(
            'Influence object {0} does not exist!'.format(influence))

    # Get geometry
    affectedGeo = easy.getAffectedGeometry(skinCluster).keys()[0]

    # Get skinCluster Fn
    skinFn = getSkinClusterFn(skinCluster)

    # Get Influence Index
    influenceIndex = getInfluencePhysicalIndex(skinCluster, influence)

    # Check component list
    if not componentList:
        componentList = easy.getComponentStrList(affectedGeo)
    componentSel = easy.getSelectionElement(componentList, 0)

    # Encode argument arrays
    infIndexArray = om.MIntArray()
    infIndexArray.append(influenceIndex)

    wtArray = om.MDoubleArray()
    oldWtArray = om.MDoubleArray()
    [wtArray.append(i) for i in weightList]

    # Set skinCluster weight values
    skinFn.setWeights(componentSel[0], componentSel[1], infIndexArray, wtArray,
                      normalize, oldWtArray)

    # Return result
    return list(oldWtArray)
Beispiel #2
0
def clearWeights(geometry):
    ''' Reset the skinCluster weight values (set to 0.0) for the specified objects/components
    :param geometry list: Geometry whose skinCluster weights will have its weights reset to 0.0
    '''
    # Check Geometry
    if not cmds.objExists(geometry):
        raise Exception('Geometry object {0} does not exist!'.format(geometry))

    # Get SkinCluster
    skinCluster = findRelatedSkinCluster(geometry)
    if not cmds.objExists(skinCluster):
        raise Exception(
            'Geometry object {0} is not attached to a valid skinCluster!'.
            format(geometry))

    # =================
    # - Clear Weights -
    # =================

    # Get geometry component list
    componentList = easy.getComponentStrList(geometry)
    componentSel = easy.getSelectionElement(componentList, 0)

    # Build influence index array
    infList = cmds.skinCluster(skinCluster, q=True, inf=True)
    infIndexArray = om.MIntArray()
    for inf in infList:
        infIndex = getInfluencePhysicalIndex(skinCluster, inf)
        infIndexArray.append(infIndex)

    # Build master weight array
    wtArray = om.MDoubleArray()
    oldWtArray = om.MDoubleArray()
    [wtArray.append(0.0) for i in range(len(componentList) * len(infList))]

    # Set skinCluster weights
    skinFn = getSkinClusterFn(skinCluster)
    skinFn.setWeights(componentSel[0], componentSel[1], infIndexArray, wtArray,
                      False, oldWtArray)
Beispiel #3
0
def getInfluenceWeights(skinCluster, influence, componentList=[]):
    ''' Return the weights of an influence for a specified skinCluster
    :param skinCluster str: SkinCluster to query influence weights from
    :param influence str: Influence to query weights from
    :param componentList list: List of components to query weights for
    :return: returns list of weights of an influence for specified skinCluster
    :rtype: list
    '''
    # Verify skinCluster
    if not isSkinCluster(skinCluster):
        raise Exception(
            'Invalid skinCluster {0} specified!'.format(skinCluster))

    # Check influence
    if not cmds.objExists(influence):
        raise Exception(
            'Influence object {0} does not exist!'.format(influence))

    # Get geometry
    affectedGeo = easy.getAffectedGeometry(skinCluster).keys()[0]

    # Check component list
    if not componentList:
        componentList = easy.getComponentStrList(affectedGeo)
    componentSel = easy.getSelectionElement(componentList, 0)

    # Get skinCluster Fn
    skinFn = getSkinClusterFn(skinCluster)

    # Get Influence Index
    influenceIndex = getInfluencePhysicalIndex(skinCluster, influence)

    # Get weight values
    weightList = om.MDoubleArray()
    skinFn.getWeights(componentSel[0], componentSel[1], influenceIndex,
                      weightList)

    # Return weight array
    return list(weightList)
Beispiel #4
0
def getInfluenceWeightsAll(skinCluster, componentList=[]):
    ''' Return the weights of all influence for a specified skinCluster
    :param skinCluster str: SkinCluster to query influence weights from
    :param componentList list: List of components to query weights for
    :return: weights of all influences for specified skinCluster
    :rtype: list
    '''
    # Verify skinCluster
    if not isSkinCluster(skinCluster):
        raise Exception(
            'Invalid skinCluster {0} specified!'.format(skinCluster))

    # Get Geometry
    affectedGeo = easy.getAffectedGeometry(skinCluster).keys()[0]

    # Check component list
    if not componentList: componentList = easy.getComponentStrList(affectedGeo)
    componentSel = easy.getSelectionElement(componentList, 0)

    # Get skinClusterFn
    skinFn = getSkinClusterFn(skinCluster)

    # Get weight values
    weightList = om.MDoubleArray()
    infCountUtil = om.MScriptUtil(0)
    infCountPtr = infCountUtil.asUintPtr()
    skinFn.getWeights(componentSel[0], componentSel[1], weightList,
                      infCountPtr)
    infCount = om.MScriptUtil(infCountPtr).asUint()

    # Break List Per Influence
    wtList = list(weightList)
    infWtList = [wtList[i::infCount] for i in xrange(infCount)]

    # Return Result
    return infWtList
Beispiel #5
0
def setInfluenceWeightsAll(skinCluster,
                           weightList,
                           normalize=False,
                           componentList=[]):
    '''
    :param skinCluster str: SkinCluster to set influence weights for
    :param weightList list: Influence weight list to apply.
    :param normalize bool: Normalize weights as they are applied
    :param componentList list: List of components to set weights for
    :return: list of old weights
    :rtype: list
    '''
    # Verify skinCluster
    if not isSkinCluster(skinCluster):
        raise Exception(
            'Invalid skinCluster {0} specified!'.format(skinCluster))

    # Get SkinCluster Influence List
    influenceList = cmds.skinCluster(skinCluster, q=True, inf=True)
    infIndexArray = om.MIntArray()
    [
        infIndexArray.append(getInfluencePhysicalIndex(skinCluster, inf))
        for inf in influenceList
    ]
    infDict = {}
    for inf in influenceList:
        infDict[inf] = getInfluencePhysicalIndex(skinCluster, inf)

    # Get SkinCluster Geometry
    skinGeo = easy.getAffectedGeometry(skinCluster).keys()[0]
    if not cmds.objExists(skinGeo):
        raise Exception(
            'SkinCluster geometry {0} does not exist!'.format(skinGeo))

    # Check Component List
    if not componentList: componentList = easy.getComponentStrList(skinGeo)
    componentSel = easy.getSelectionElement(componentList, 0)

    # Get Component Index List
    indexList = om.MIntArray()
    componentFn = om.MFnSingleIndexedComponent(componentSel[1])
    componentFn.getElements(indexList)
    componentIndexList = list(indexList)

    # Check SkinCluster Weights List
    if len(weightList) != len(influenceList):
        raise Exception('Influence and weight list miss-match!')

    # Build Master Weight Array
    wtArray = om.MDoubleArray()
    oldWtArray = om.MDoubleArray()
    for c in componentIndexList:
        for inf in influenceList:
            wtArray.append(weightList[infDict[inf]][c])

    # Get skinCluster function set
    skinFn = getSkinClusterFn(skinCluster)

    # Set skinCluster weights
    skinFn.setWeights(componentSel[0], componentSel[1], infIndexArray, wtArray,
                      normalize, oldWtArray)

    # Return result
    return list(oldWtArray)
Beispiel #6
0
    def loadWeights(self,
                    skc=None,
                    influenceList=None,
                    componentList=None,
                    normalize=True):
        ''' Apply the stored skinCluster weights.
        :param skc str: The list of components to apply skc weights to.
        :param influenceList list or None: The list of skc influences to apply weights for.
        :param componentList list or None: The list of components to apply skc weights to.
        :param normalize bool: Normalize influence weights.
        '''
        # ==========
        # - Checks -
        # ==========

        # Check SkinCluster
        if not skc: skc = self._data['name']
        self.verifySkinCluster(skc)

        # Check Geometry
        skinGeo = self._data['affectedGeometry'][0]
        if not cmds.objExists(skinGeo):
            raise Exception(
                'SkinCluster geometry {0} does not exist! Use remapGeometry() to load skinCluster data to a different geometry!'
                .format(skinGeo))

        # Check Influence List
        if not influenceList: influenceList = self._influenceData.keys() or []
        for influence in influenceList:
            if not influence in cmds.skinCluster(skc, q=True, inf=True) or []:
                raise Exception('Object "' + influence +
                                '" is not a valid influence of skinCluster "' +
                                skc + '"! Unable to load influence weights...')
            if not self._influenceData.has_key(influence):
                raise Exception('No influence data stored for "' + influence +
                                '"! Unable to load influence weights...')

        # Check Component List
        if not componentList:
            componentList = easy.getComponentStrList(skinGeo)
        componentSel = easy.getSelectionElement(componentList, 0)

        # Get Component Index List
        componentIndexList = easy.getSingleIndexComponentList(componentList)
        componentIndexList = componentIndexList[componentIndexList.keys()[0]]

        # Get Influence Index
        infIndexArray = om.MIntArray()
        for influence in influenceList:
            infIndex = skinCluster.getInfluencePhysicalIndex(skc, influence)
            infIndexArray.append(infIndex)

        # Build Weight Array
        wtArray = om.MDoubleArray()
        oldWtArray = om.MDoubleArray()
        for c in componentIndexList:
            for i in range(len(influenceList)):
                if self._influenceData.has_key(influenceList[i]):
                    wtArray.append(
                        self._influenceData[influenceList[i]]['wt'][c])
                else:
                    wtArray.append(0.0)

        # Get skinCluster function set
        skinFn = skinCluster.getSkinClusterFn(skc)

        # Set skinCluster weights
        skinFn.setWeights(componentSel[0], componentSel[1], infIndexArray,
                          wtArray, normalize, oldWtArray)

        # =================
        # - Return Result -
        # =================

        return list(wtArray)