예제 #1
0
    def cluster(self):
        source_mobject = self.getMObject(self.source_geometry)

        from smartDeformer_maya2017.modules import cluster
        clu = cluster.Cluster()

        if not self.target_deformers:
            self.target_deformers = []
            for x in range(len(self.source_deformers)):
                self.target_deformers.append(None)
        loop = min([len(self.target_deformers), len(self.source_deformers)])
        for index in range(loop):
            _targt_deformer = self.target_deformers[index]
            if not self.target_deformers[index]:
                name = '%s_cluster_joint' % self.source_deformers[
                    index].replace('.', '_')
                joint_dag_path, joint_name = self.create(name, clear=True)
                x, y, z = self.getClusterPosition(self.source_deformers[index])
                self.setJointPosition(joint_name, [x, y, z])
                self.addInfluence(joint_name, self.target_geometrys)
                _targt_deformer = joint_name
            cluster_mobject = self.getDependences(_targt_deformer,
                                                  OpenMaya.MFn.kClusterFilter)
            weight_data = clu.get_weight(self.source_deformers[index])
            weight_object = weight_data['geometry'].keys()[0]
            weights = weight_data['geometry'][weight_object]['weights']
            weight_array = OpenMaya.MFloatArray()
            mscript_util = OpenMaya.MScriptUtil()
            mscript_util.createFloatArrayFromList(weights, weight_array)
            for each_geometry in self.target_geometrys:
                self.setSkinclusterWeights(each_geometry, _targt_deformer,
                                           weight_array)
예제 #2
0
 def __init__(self, parent=None):
     super(Weights, self).__init__(parent=None)
     self.setup_ui()
     self.cluster = cluster.Cluster()
     self.skincluster = skincluster.Skincluster()
     self.my_maya = studioMaya.Maya()
예제 #3
0
    def convert(self, lineedit, treewidget):
        if not self.source_geometry:
            OpenMaya.MGlobal.displayWarning(
                'Not select any source geometry!...')
            return
        if not self.target_geometry:
            OpenMaya.MGlobal.displayWarning(
                'Not select any target geometry!...')
            return

        if not self.source_deformer:
            OpenMaya.MGlobal.displayWarning(
                'Not select any source deformers!...')
            return
        if not self.target_deformer:
            OpenMaya.MGlobal.displayWarning(
                'Not select any target deformers!...')
            return
        if self.target_deformer[0] == 1:  # to cluster
            my_cluster = cluster.Cluster(
                source_geometry=self.source_geometry,
                target_geometrys=[self.target_geometry],
                source_deformers=self.source_deformers,
                target_deformers=self.target_deformers)
            if self.source_deformer[0] == 1:  # to softSelection
                try:
                    my_cluster.soft_selection()
                    OpenMaya.MGlobal.displayInfo(
                        'Soft selection to Cluster Success!..')
                except Exception as error:
                    raise Exception(error)
            else:
                if not self.source_deformers:
                    OpenMaya.MGlobal.displayWarning(
                        'Not select any source deformers!...')
                    return

            if self.source_deformer[0] == 2:  # to blendShape
                try:
                    my_cluster.blend_shape()
                    OpenMaya.MGlobal.displayInfo(
                        'Blendshape to Cluster Success!..')
                except Exception as error:
                    raise Exception(error)

            if self.source_deformer[0] == 3:  # to wire
                try:
                    my_cluster.wire()
                    OpenMaya.MGlobal.displayInfo('Wire to Cluster Success!..')
                except Exception as error:
                    raise Exception(error)

            if self.source_deformer[0] == 4:  # to lattice
                try:
                    my_cluster.lattice()
                    OpenMaya.MGlobal.displayInfo(
                        'Lattice to Cluster Success!..')
                except Exception as error:
                    raise Exception(error)

            if self.source_deformer[0] == 5:  # to cluster
                try:
                    my_cluster.to_cluster()
                    OpenMaya.MGlobal.displayInfo(
                        'Cluster to Cluster Success!..')
                except Exception as error:
                    raise Exception(error)

            if self.source_deformer[0] == 6:  # to skincluster
                try:
                    my_cluster.skin_cluster()
                    OpenMaya.MGlobal.displayInfo(
                        'Cluster to Skincluster Success!..')
                except Exception as error:
                    raise Exception(error)

        if self.target_deformer[0] == 2:  # to skincluster
            m_skinclusters = self.my_maya.getSkincluster(
                self.target_geometry.encode())
            if not m_skinclusters:
                QtWidgets.QMessageBox.warning(
                    self, 'Warning',
                    'sorry can not find skincluster on the geometry,\nbind the geometry with joint first',
                    QtWidgets.QMessageBox.Ok)
                return
            my_skincluster = skincluster.Skincluster(
                source_geometry=self.source_geometry,
                target_geometrys=[self.target_geometry],
                source_deformers=self.source_deformers,
                target_deformers=self.target_deformers)
            if self.source_deformer[0] == 1:  # to softSelection
                try:
                    my_skincluster.soft_selection()
                    OpenMaya.MGlobal.displayInfo(
                        'Soft selection to Skincluster Success!..')
                except Exception as error:
                    raise Exception(error)
            else:
                if not self.source_deformers:
                    OpenMaya.MGlobal.displayWarning(
                        'Not select any source deformers!...')
                    return

            if self.source_deformer[0] == 2:  # to blendShape
                try:
                    my_skincluster.blend_shape()
                    OpenMaya.MGlobal.displayInfo(
                        'Blendshape to Skincluster Success!..')
                except Exception as error:
                    raise Exception(error)

            if self.source_deformer[0] == 3:  # to wire
                try:
                    my_skincluster.wire()
                    OpenMaya.MGlobal.displayInfo(
                        'Wire to Skincluster Success!..')
                except Exception as error:
                    raise Exception(error)

            if self.source_deformer[0] == 4:  # to lattice
                try:
                    my_skincluster.lattice()
                    OpenMaya.MGlobal.displayInfo(
                        'Lattice to Skincluster Success!..')
                except Exception as error:
                    raise Exception(error)

            if self.source_deformer[0] == 5:  # to cluster
                try:
                    my_skincluster.cluster()
                    OpenMaya.MGlobal.displayInfo(
                        'Cluster to Skincluster Success!..')
                except Exception as error:
                    raise Exception(error)

            if self.source_deformer[0] == 6:  # to skincluster
                try:
                    my_skincluster.to_skincluster()
                    OpenMaya.MGlobal.displayInfo(
                        'Skincluster to Skincluster Success!..')
                except Exception as error:
                    raise Exception(error)

        self.set_current_deformer(lineedit, treewidget, self.titles[1],
                                  self.target_deformer[0])