Example #1
0
    def skin_cluster(self):
        source_mobject = self.getMObject(self.source_geometry)
        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)])

        from smartDeformer_maya2018.modules import skincluster
        skinclu = skincluster.Skincluster()

        for index in range(loop):
            _targt_deformer = self.target_deformers[index]
            if not self.target_deformers[index]:
                name = '%s_skincluster_cluster' % self.source_deformers[
                    index].replace('.', '_')
                cluster, clusterhandle = self.create(name, clear=True)
                x, y, z = self.getJointPosition(self.source_deformers[index])
                self.setClusterPosition(clusterhandle, [x, y, z])
                _targt_deformer = clusterhandle
            joint_dag_path = self.getDagPath(self.source_deformers[index])
            cluster_mobject = self.getDependences(_targt_deformer,
                                                  OpenMaya.MFn.kClusterFilter)
            weight_data = skinclu.get_weight(joint_dag_path)
            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)
            self.setClusterWeights(self.target_geometrys[0],
                                   cluster_mobject[0], weight_array)
Example #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()
Example #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])