コード例 #1
0
ファイル: deformerData.py プロジェクト: lefan2016/glTools
    def buildData(self, deformer):
        '''
		Build Deformer Data.
		@param deformer: Deformer to initialize data for
		@type deformer: str
		'''
        # ==========
        # - Checks -
        # ==========

        # Deformer
        if not deformer: return
        if not glTools.utils.deformer.isDeformer(deformer):
            raise Exception(
                'Object ' + deformer +
                ' is not a valid deformer! Unable to instantiate DeformerData() class object!'
            )

        # ==============
        # - Build Data -
        # ==============

        # Start timer
        timer = mc.timerX()

        # Reset Data Object - (Maintain Incoming Attribute Lists)
        attrValueList = copy.deepcopy(self._data['attrValueList'])
        attrConnectionList = copy.deepcopy(self._data['attrConnectionList'])
        self.reset()
        self._data['attrValueList'] = copy.deepcopy(attrValueList)
        self._data['attrConnectionList'] = copy.deepcopy(attrConnectionList)

        # Get basic deformer info
        self._data['name'] = deformer
        self._data['type'] = mc.objectType(deformer)

        # Get geometry affected by deformer
        affectedGeo = glTools.utils.deformer.getAffectedGeometry(
            deformer, returnShapes=False)
        self._data['affectedGeometry'] = [
            str(i) for i in
            glTools.utils.arrayUtils.dict_orderedKeyListFromValues(affectedGeo)
        ]

        # Build data lists for each affected geometry
        for geo in self._data['affectedGeometry']:
            geoShape = mc.listRelatives(geo, s=True, ni=True, pa=True)[0]
            self._data[geo] = {}
            self._data[geo]['index'] = affectedGeo[geo]
            self._data[geo]['geometryType'] = str(mc.objectType(geoShape))
            self._data[geo][
                'membership'] = glTools.utils.deformer.getDeformerSetMemberIndices(
                    deformer, geo)
            self._data[geo]['weights'] = glTools.utils.deformer.getWeights(
                deformer, geo)

            if self._data[geo]['geometryType'] == 'mesh':
                self._data[geo]['mesh'] = meshData.MeshData(geo)

        # =========================
        # - Custom Attribute Data -
        # =========================

        # Add Pre-Defined Custom Attributes
        self.customDeformerAttributes(self._data['type'])
        self.getDeformerAttrValues()
        self.getDeformerAttrConnections()

        # Get Timer Val
        buildTime = mc.timerX(st=timer)
        print('DeformerData: Data build time for "' + deformer + '": ' +
              str(buildTime))

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

        return deformer
コード例 #2
0
    def buildData(self, skinCluster):
        '''
		Build skinCluster data and store as class object dictionary entries
		@param skinCluster: SkinCluster deformer to store data for.
		@type skinCluster: list
		'''
        # ==========
        # - Checks -
        # ==========

        # Check skinCluster
        self.verifySkinCluster(skinCluster)

        # Clear Data
        self.reset()

        # =======================
        # - Build Deformer Data -
        # =======================

        # Start Timer
        timer = mc.timerX()

        self._data['name'] = skinCluster
        self._data['type'] = 'skinCluster'

        # Get affected geometry
        skinGeoShape = mc.skinCluster(skinCluster, q=True, g=True)
        if len(skinGeoShape) > 1:
            raise Exception('SkinCluster "' + skinCluster +
                            '" output is connected to multiple shapes!')
        if not skinGeoShape:
            raise Exception(
                'Unable to determine affected geometry for skinCluster "' +
                skinCluster + '"!')
        skinGeo = mc.listRelatives(skinGeoShape[0], p=True, pa=True)
        if not skinGeo:
            raise Exception(
                'Unable to determine geometry transform for object "' +
                skinGeoShape + '"!')
        self._data['affectedGeometry'] = skinGeo
        skinGeo = skinGeo[0]

        skinClusterSet = glTools.utils.deformer.getDeformerSet(skinCluster)

        self._data[skinGeo] = {}
        self._data[skinGeo]['index'] = 0
        self._data[skinGeo]['geometryType'] = str(mc.objectType(skinGeoShape))
        self._data[skinGeo][
            'membership'] = glTools.utils.deformer.getDeformerSetMemberIndices(
                skinCluster, skinGeo)
        self._data[skinGeo]['weights'] = []

        if self._data[skinGeo]['geometryType'] == 'mesh':
            self._data[skinGeo]['mesh'] = meshData.MeshData(skinGeo)

        # ========================
        # - Build Influence Data -
        # ========================

        # Get skinCluster influence list
        influenceList = mc.skinCluster(skinCluster, q=True, inf=True)
        if not influenceList:
            raise Exception(
                'Unable to determine influence list for skinCluster "' +
                skinCluster + '"!')

        # Get Influence Wieghts
        weights = glTools.utils.skinCluster.getInfluenceWeightsAll(skinCluster)

        # For each influence
        for influence in influenceList:

            # Initialize influence data
            self._influenceData[influence] = {}

            # Get influence index
            infIndex = glTools.utils.skinCluster.getInfluenceIndex(
                skinCluster, influence)
            self._influenceData[influence]['index'] = infIndex

            # Get Influence BindPreMatrix
            bindPreMatrix = mc.listConnections(
                skinCluster + '.bindPreMatrix[' + str(infIndex) + ']',
                s=True,
                d=False,
                p=True)
            if bindPreMatrix:
                self._influenceData[influence][
                    'bindPreMatrix'] = bindPreMatrix[0]
            else:
                self._influenceData[influence]['bindPreMatrix'] = ''

            # Get Influence Type (Transform/Geometry)
            infGeomConn = mc.listConnections(skinCluster + '.driverPoints[' +
                                             str(infIndex) + ']')
            if infGeomConn:
                self._influenceData[influence]['type'] = 1
                self._influenceData[influence]['polySmooth'] = mc.skinCluster(
                    skinCluster, inf=influence, q=True, ps=True)
                self._influenceData[influence][
                    'nurbsSamples'] = mc.skinCluster(skinCluster,
                                                     inf=influence,
                                                     q=True,
                                                     ns=True)
            else:
                self._influenceData[influence]['type'] = 0

            # Get Influence Weights
            pInd = glTools.utils.skinCluster.getInfluencePhysicalIndex(
                skinCluster, influence)
            self._influenceData[influence]['wt'] = weights[pInd]

        # =========================
        # - Custom Attribute Data -
        # =========================

        # Add Pre-Defined Custom Attributes
        self.getDeformerAttrValues()
        self.getDeformerAttrConnections()

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

        skinTime = mc.timerX(st=timer)
        print('SkinClusterData: Data build time for "' + skinCluster + '": ' +
              str(skinTime))