예제 #1
0
파일: skin.py 프로젝트: MongoWobbler/piper
    def unbind(self, meshes=None, bind_pose=True):
        """
        Unbinds the skin clusters from the given meshes (will use selection or all meshes in scene if None).
        Stores skin cluster weights in a temp file to be rebound with the rebind method.

        Args:
            meshes (list): Meshes to unbind.

            bind_pose (boolean): If True will move joints back to the bind pose before unbinding.

        Returns:
            (dictionary): All the info gathered  from unbinding joints.
        """
        # reset info
        self.info = {}
        scene_path = pm.sceneName()
        scene_name = os.path.splitext(
            scene_path.name)[0] + '_' if scene_path else ''
        meshes = myu.validateSelect(meshes, find='mesh', parent=True)
        pcu.validateDirectory(self.directory)

        for mesh in meshes:
            # get the skin of the mesh, if it doesnt exist then we don't need to store skin weights
            mesh_name = mesh.nodeName()
            skin = mesh.listHistory(type='skinCluster')

            if not skin:
                continue

            # get the info we need to rebind the mesh: skin name, max influences, and joints influencing mesh
            # stored as string in case object gets deleted and renamed after unbinding
            skin = skin[0].nodeName()
            max_influences = pm.skinCluster(mesh, q=True, mi=True)
            joints = [
                joint.nodeName()
                for joint in pm.skinCluster(skin, q=True, influence=True)
            ]

            if bind_pose:
                returnToBindPose(joints)

            # select mesh, export skin weights, and detach skin using MEL because pm.bindSkin(delete=True) has errors.
            pm.select(mesh)
            deformer_name = scene_name + mesh_name + '.xml'
            path = pm.deformerWeights(deformer_name,
                                      export=True,
                                      deformer=skin,
                                      path=self.directory)
            pm.mel.eval('doDetachSkin "2" { "1","1" }')

            self.info[mesh_name] = {
                'skin': skin,
                'max_influences': max_influences,
                'joints': joints,
                'path': path
            }

        pm.select(meshes)
        return self.info
예제 #2
0
    def onStart(export_path):
        """
        Called when the export is about happen, before writing the file.

        Args:
            export_path (string): Path to export to.
        """
        # make export directory if it does not exist already
        export_directory = os.path.dirname(export_path)
        pcu.validateDirectory(export_directory)
예제 #3
0
def setProject(directory):
    """
    Sets the maya project. Will create a directory if one does not already exist.

    Args:
        directory (string): path where project will be set to.
    """
    pcu.validateDirectory(directory)
    pm.workspace(directory, o=True)
    pm.workspace(fr=['scene', directory])
예제 #4
0
    def textures():
        shader = graphics.PiperShader()
        textures = shader.getTextures()

        for texture in textures:
            export_path = paths.getGameTextureExport(texture)
            pcu.validateDirectory(os.path.dirname(export_path))
            shutil.copyfile(texture, export_path)
            print('Copying ' + texture + ' to ' + export_path)

        print('Finished copying textures ' + '=' * 40)