Пример #1
0
def populate_files(*args):
    """
    clears the file list, then populates based on the phase and the selected asset in the asset TSL
    """
    clear_file_list()
    selTab = cmds.tabLayout(widgets["assetsTab"], q=True, st=True)

    tab, phase, assetPath, assetFiles = [None, None, None, None]

    if selTab != "STGS":
        tab, phase, assetPath, assetFiles = get_asset_info()
    else:
        tab, phase, assetPath, assetFiles = get_stage_info()

    if assetFiles:
        for file in assetFiles:
            cmds.textScrollList(widgets["filesTSL"],
                                e=True,
                                a=os.path.basename(file))
    else:
        cmds.textScrollList(widgets["filesTSL"], e=True, a="No Files")

    currFile = cmds.file(q=True, sn=True)
    if currFile:
        fileObj = uf.PathParser(currFile)
        if fileObj.compatible and (os.path.basename(currFile) in assetFiles):
            cmds.textScrollList(widgets["filesTSL"],
                                e=True,
                                si=os.path.basename(currFile))
    else:
        # get the last file and select that
        numItems = cmds.textScrollList(widgets["filesTSL"], q=True, ni=True)
        cmds.textScrollList(widgets["filesTSL"], e=True, sii=numItems)
Пример #2
0
def publish_fbx_folder(origScene=None, *args):
    """
    now go through the folder path and open each, open the gameexp, then populate the export path, then exportgo
    ARGS:
        path (string): the path to the folder that we need to parse through (path to mb files)
    """
    pathP = uf.PathParser(origScene)
    mbpubpath = pathP.phasePath + "/Publish/MB/{0}_v{1}".format(
        pathP.variant, pathP.versionString)
    fbxpubpath = pathP.phasePath + "/Publish/FBX/{0}_v{1}".format(
        pathP.variant, pathP.versionString)

    # get the maya files
    mbFiles = fnmatch.filter(os.listdir(mbpubpath), "*.mb")

    for mb in mbFiles:
        mel.eval("gameFbxExporter;")
        print "========= multiRefAnimExport.publish_fbx_folder: opening {0}/{1}".format(
            mbpubpath, mb)
        cmds.file("{0}/{1}".format(mbpubpath, mb), open=True, f=True)

        # delete textures
        shdEngines = cmds.ls(type="shadingEngine")
        for sh in shdEngines:
            shd = cmds.listConnections("{0}.surfaceShader".format(sh))
            inCons = cmds.listConnections(shd, s=True, d=False)
            if inCons:
                print "multiRefAnimExport.publish_fbx_folder: deleting:", inCons
                cmds.delete(inCons)

        # find anything that is not lining up with the file we've opened (ie. came in via export selected connections)
        lookfor = mb.split("_")[2]
        # print "LOOK FOR: {0}".format(lookfor)
        exclude = ["persp", "top", "side", "front"]

        assemblies = cmds.ls(assemblies=True)
        # print "ASSEMBLIES: ", assemblies
        for a in assemblies:
            if not a.startswith(lookfor) and (a not in exclude):
                print "------ deleting: ", a
                cmds.delete(a)

        cmds.file(s=True, f=True)
        filename = "{0}_{1}_{2}_{3}".format(pathP.name, pathP.variant,
                                            "_".join(mb.split("_")[3:-1]),
                                            "_".join(mb.split("_")[2:3]))

        if not os.path.isdir(fbxpubpath):
            os.makedirs(fbxpubpath)

        node = cmds.ls(type="gameFbxExporter")[-1]
        # set path and file name
        uf.set_gameExport_info(node, fbxpubpath, filename)

        # run exporter
        print "========= multiRefAnimExport.publish_fbx_folder: trying to publish FBX {0}/{1}".format(
            mbpubpath, mb)
        mel.eval("gameExp_DoExport;")

    return (True)
    def __init__(self, ns, ref, deferred, status):
        self.pathParse = uf.PathParser(ref)
        self.compatible = self.pathParse.compatible
        self.variant = None
        self.ref = ref  # the reference path
        self.namespace = ns  # the namespace
        self.versionNums = [
        ]  # list of strings of the version numberss (i.e. ["0001", "0003"])
        self.versionNum = ""  # astring of the version number (ie. "0005")
        self.status = status  # status = "current" or "pending"
        self.killState = False  # should this be killed?
        self.loadState = not deferred  # should this be loaded (vs. unloaded)?
        self.state = False  # False means it has NOT been changed
        self.vchange = False  # version change state
        self.lchange = False  # load change state
        self.kchange = False  # kill change state
        self.varchange = False  # variant change state

        if self.status == "current":
            ReferenceObject.currentObjList.append(self)
        if self.status == "pending":
            ReferenceObject.pendingObjList.append(self)
        ReferenceObject.existingRefList.append(self.ref)
        ReferenceObject.allObjectList.append(self)

        # create a dictionary of all variants and their versions
        self.variantDict = self.create_variant_dict()
        self.create_UI()
Пример #4
0
def change_stage_tab(*args):
    """
    when tab changes, just select first in the list
    """
    currTab = cmds.tabLayout(widgets["assetsTab"], q=True, st=True)
    currScene = cmds.file(q=True, sn=True)
    if currTab == "CHARS":
        tsl = "char"
    if currTab == "PROPS":
        tsl = "prop"
    if currTab == "SETS":
        tsl = "set"
    if currTab == "STGS":
        tsl = "stage"
    if currScene:
        # try to find in the current scene
        pp = uf.PathParser(currScene)
        if pp.compatible:
            if pp.name in cmds.textScrollList(widgets["{0}TSL".format(tsl)],
                                              q=True,
                                              allItems=True):
                cmds.textScrollList(widgets["{0}TSL".format(tsl)],
                                    e=True,
                                    si=pp.name)
            else:
                cmds.textScrollList(widgets["{0}TSL".format(tsl)],
                                    e=True,
                                    sii=1)
        else:
            cmds.textScrollList(widgets["{0}TSL".format(tsl)], e=True, sii=1)
    else:
        cmds.textScrollList(widgets["{0}TSL".format(tsl)], e=True, sii=1)

    populate_files()
Пример #5
0
def finish_up(versionUp=True, origScene=None, *args):
    """
    do final clean up stuff
    ARGS:
        pp (PathParser object)
    """
    pp = uf.PathParser(origScene)

    if versionUp:        
        verNum = int(pp.path[-7:-3])
        pp.get_version_info()
        nums = pp.versionNumbers
        newNum = nums[-1]

        verUpFile = "{0}{1}{2}".format(origScene[:-7], str(newNum).zfill(4),".mb")

        if os.path.isfile(verUpFile):
            print "multiRefAnimExport.finish_up: Opening version up file:", verUpFile
            cmds.file(verUpFile, open=True, force=True)
        else:
            print "multiRefAnimExport.finish_up: Couldn't find version up, opening original file: ",pp.path
            cmds.file(pp.path, open=True, force=True)
    else:
        print "multiRefAnimExport.finish_up: Opening original file: ",pp.path 
        cmds.file(pp.path, open=True, force=True)
    
    if cmds.window("gameExporterWindow", exists=True):
        cmds.deleteUI("gameExporterWindow")
    # reload file win
    fm.fileManager()

    cmds.confirmDialog(m="Animation published successfully!", t="Stage Publish")
Пример #6
0
def create_namespace(filepath, *args):
    """
        get a file path and trim that down to new namespace, which will be incremented based on existing namespaces
        ex. instead of "Fish_Main_Rigging_Publish_v0002", will be "Fish_Main_Rig" or "Fish_Main_Rig1"
        ARGS:
            filepath (string): the filepath to derive the name from
        RETURN:
            string: the incremented namespace
    """
    f = uf.PathParser(filepath)
    phase = f.phase
    if phase == "Modeling":
        phase = "Mdl"
    if phase == "Rigging":
        phase = "Rig"
    if phase == "Animation":
        phase = "Anm"
    if phase == "Lighting":
        phase = "Lgt"                    
    namespace = "{0}_{1}_{2}".format(f.name, f.variant, phase)

    if namespace in namespaceList:
        incrementedName = increment_namespace(namespace, namespaceList)
    else:
        incrementedName = namespace
    print "creating Namespace {0} for {1}".format(incrementedName, filepath)
    return(incrementedName)
Пример #7
0
def select_initial(*args):
    """
    tries to select the first item in chars, if not, then props, etc. If no item, pass
    !! finish this later
    """

    # if we're in a scene with a name
    filename = cmds.file(q=True, sn=True)

    if filename:
        fileObj = uf.PathParser(filename)
        # if that scene is compatible
        if fileObj.compatible:
            # get the asset type - select the tab
            if fileObj.assetType == "Character":
                assType, assTab = "CHARS", "charTSL"
            if fileObj.assetType == "Props":
                assType, assTab = "PROPS", "propTSL"
            if fileObj.assetType == "Sets":
                assType, assTab = "SETS", "setTSL"
            if fileObj.assetType == "Stages":
                assType, assTab = "STGS", "stageTSL"
            cmds.tabLayout(widgets["assetsTab"], e=True, st=assType)
            # get the phase - select the menu
            cmds.optionMenu(widgets["phaseOM"], e=True, value=fileObj.phase)
            cmds.textScrollList(widgets[assTab], e=True, si=fileObj.name)
        else:
            cmds.textScrollList(widgets["charTSL"], e=True, sii=1)
    else:
        cmds.textScrollList(widgets["charTSL"], e=True, sii=1)

    populate_files()
Пример #8
0
def assetPublish(versionUp=True, *args):
    """
    checks the current scene if it's compatible, if not kick out
    ARGS:
        versionUp (bool): whether to version up the work file on publish
    """
    origScene = cmds.file(q=True, sn=True)
    pp = uf.PathParser(origScene)

    # bail if current scene is not compatible
    if not pp.compatible:
        cmds.warning("assetPublish.publish_maya_scene: You're not in a project compatible scene! Sorry. See a TD")
        return()
   
    # if it's not a stage file or a publish file and it's either modeling or rigging phase
    if pp.assetType != "Stages" and pp.phase in ["Rigging", "Modeling", "Texturing", "Lighting"] and pp.stage=="Work":
        mayapub = publish_maya_scene(versionUp, origScene)
        if not mayapub: # i.e. we've failed somewhere in the func
           return()
    else:
        print "===== not doing standard maya asset publish, since you're in {0} phase and {1} stage of the pipeline".format(pp.phase, pp.stage)

    # if it's modeling or texturing phase - fbx export
    if pp.assetType != "Stages" and pp.phase in ["Modeling", "Texturing"] and pp.stage=="Work":
        fbxPub = publish_fbx_model_file(versionUp, origScene)
        if not fbxPub:
            return()    

    # if it's a rig work file
    if pp.assetType != "Stages" and pp.phase in ["Rigging"] and pp.stage=="Work":
        fbxPub = publish_fbx_rig_file(versionUp, origScene)
        if not fbxPub:
            return()

    # if it's an anm work file
    if pp.assetType != "Stages" and pp.phase in ["Animation"] and pp.stage=="Work":
        fbxPub = publish_fbx_anim_file(versionUp, origScene)
        if not fbxPub:
            return()
        print "----- freezing so you can export anim"
        return()

    if versionUp:
        verNum = int(pp.path[-7:-3])
        pp.get_version_info()
        nums = pp.versionNumbers
        newNum = nums[-1]

        verUpFile = "{0}{1}{2}".format(origScene[:-7], str(newNum).zfill(4),".mb")

        if os.path.isfile(verUpFile):
            print "assetPublish.assetPublish: Opening version up file:", verUpFile
            cmds.file(verUpFile, open=True, force=True)
        else:
            print "assetPublish.assetPublish: Couldn't find version up, opening original file: ",pp.path
            cmds.file(pp.path, open=True, force=True)
    else:
        print "assetPublish.assetPublish: Opening original file: ",pp.path 
        cmds.file(pp.path, open=True, force=True)
def stagePublish(versionUp=True, *args):
    """
    checks the current scene if it's compatible, if not kick out
    ARGS:
        versionUp (bool): whether to version up the work file on publish
    """
    origScene = cmds.file(q=True, sn=True)
    pp = uf.PathParser(origScene)

    # bail if current scene is not compatible
    if not pp.compatible:
        cmds.warning(
            "assetPublish.publish_maya_scene: You're not in a project compatible scene! Sorry. See a TD"
        )
        return ()

    # # publish the current maya scene to Publish folder
    # if pp.phase in ["Animation"] and pp.stage=="Work":
    #     mayapub = publish_maya_scene(versionUp, origScene)
    #     if not mayapub: # i.e. we've failed somewhere in the func
    #        return()
    # else:
    #     print "===== not doing standard maya anim publish, since you're in {0} phase and {1} stage of the pipeline".format(pp.phase, pp.stage)

    # if it's an anm work file
    if pp.phase in ["Animation"] and pp.stage == "Work":
        get_reference_list_UI(versionUp, origScene)
    if not publishState:
        cmds.warning(
            "There was an issue publishing the assets somewhere. Leaving multiref publishing!"
        )
        return ()

    publish_fbx_folder(origScene)

    if versionUp:
        verNum = int(pp.path[-7:-3])
        pp.get_version_info()
        nums = pp.versionNumbers
        newNum = nums[-1]

        verUpFile = "{0}{1}{2}".format(origScene[:-7],
                                       str(newNum).zfill(4), ".mb")

        if os.path.isfile(verUpFile):
            print "assetPublish.assetPublish: Opening version up file:", verUpFile
            cmds.file(verUpFile, open=True, force=True)
        else:
            print "assetPublish.assetPublish: Couldn't find version up, opening original file: ", pp.path
            cmds.file(pp.path, open=True, force=True)
    else:
        print "assetPublish.assetPublish: Opening original file: ", pp.path
        cmds.file(pp.path, open=True, force=True)

    if cmds.window("gameExporterWindow", exists=True):
        cmds.deleteUI("gameExporterWindow")
Пример #10
0
def publish_maya_scene(versionUp=True, origScene=None, *args):
    """
    only do for rigging and modeling phase of assets
    ARGS:
        versionUp (bool): whether to version up the maya scene
        origScene (string): the full path to the file to publish
    """
    if not origScene:
        cmds.warning("assetPublish.publish_maya_scene: You haven't passed in a scene path!")
        return(False)

    pp = uf.PathParser(origScene)
    cmds.file(s=True)

    sel = cmds.ls(sl=True)
    if not sel:
        cmds.warning("assetManager.publish_maya_scene: You haven't selected anything in your scene. Please select what you wish to publish. (hint: for models, your geo/geo grp. For rigs, usually it will be your char group and ctrl set)")
        return(False)

    if versionUp:
        verNum = int(origScene[-7:-3])
        pp.get_version_info()
        nums = pp.versionNumbers
        newNum = nums[-1]+1

        verUpFile = "{0}{1}{2}".format(origScene[:-7], str(newNum).zfill(4),".mb")

    # parse the new path/name for publish(current scene)
    pubPath =  uf.fix_path(os.path.join(pp.phasePath, "Publish/MB/"))
    tokens = pp.fileName.split("_")
    tokens[-2] = "Publish"
    pubFileName = "_".join(tokens)
    pubFilePath = uf.fix_path(os.path.join(pubPath, pubFileName))

    if os.path.isfile(pubFilePath):
        overwrite = cmds.confirmDialog(title="Overwrite Confirmation", message = "A publish MB already exists for this file.\nShould we overwrite?", button = ("Overwrite", "Cancel"), defaultButton = "Overwrite", cancelButton = "Cancel", dismissString = "Cancel")

        if overwrite == "Cancel":
            print "Publish skipped (no overwrite) for maya file (.mb) stage of {0}".format(pubFilePath)
            return(True)

    if versionUp:
        # in background copy the orig to the new version 
        # (essentially just versioning up while staying in old version)
        copy2(origScene, verUpFile)
        print "===== Versioned up {0} to {1}!".format(origScene, verUpFile)
    else:
        print "===== Not versioning up publish of {0}".format(origScene)        

    # export selection to publish file
    print "===== AssetPublish.publish_maya_scene: Preparing to export items to publish file: {0}".format(sel)
    export = cmds.file(pubFilePath, exportSelected=True, type="mayaBinary")
    if export==pubFilePath:
        print "===== AssetPublish.publish_maya_scene: Succesfully published file to: {0}".format(pubFilePath)
    return(True)
Пример #11
0
def get_version_up_name(origScene, *args):
    """
    from orig scene (assuming it's compatible with pipe) will return the fullpath to next version
    """
    pp2 = uf.PathParser(origScene)
    verNum = int(origScene[-7:-3])
    pp2.get_version_info()
    nums = pp2.versionNumbers
    newNum = nums[-1] + 1

    verUpFile = "{0}{1}{2}".format(origScene[:-7], str(newNum).zfill(4), ".mb")
    return (verUpFile)
Пример #12
0
def select_initial(proj, counter, *args):
    """
    tries to select the first item in chars, if not, then props, etc. If no item, pass
    !! finish this later
    
    ARGS:
        proj (AssetInfo object)
        counter (string) 
    """

    # if we're in a scene with a name
    filename = cmds.file(q=True, sn=True)

    if filename:
        fileObj = uf.PathParser(filename)
        # if that scene is compatible
        if fileObj.compatible and fileObj.stage == "Work":
            # get the asset type - select the tab
            if fileObj.assetType == "Character":
                assType, assTab = "CHARS", "charTSL"
            if fileObj.assetType == "Props":
                assType, assTab = "PROPS", "propTSL"
            if fileObj.assetType == "Sets":
                assType, assTab = "SETS", "setTSL"
            if fileObj.assetType == "Stages":
                assType, assTab = "STGS", "stageTSL"
            cmds.tabLayout(widgets["assetsTab"], e=True, st=assType)
            # get the phase - select the menu
            cmds.optionMenu(widgets["phaseOM"], e=True, value=fileObj.phase)
            cmds.textScrollList(widgets[assTab], e=True, si=fileObj.name)
        else:
            #get current tab, select the first item in the corresponding tsl
            tab = cmds.tabLayout(widgets["assetsTab"], q=True, st=True)
            if tab == "CHARS":
                asstab = "charTSL"
            if tab == "PROPS":
                asstab = "propTSL"
            if tab == "SETS":
                asstab = "setTSL"
            if tab == "STGS":
                asstab = "stageTSL"
            cmds.textScrollList(widgets[asstab], e=True, sii=1)
    else:
        cmds.tabLayout(widgets["assetsTab"], e=True, st="CHARS")
        cmds.textScrollList(widgets["charTSL"], e=True, sii=1)
    if counter:
        load = load_layout()
        if load:
            cmds.optionMenu(widgets["phaseOM"], e=True, v=load)

    counter = None

    populate_files(proj)
Пример #13
0
def publish_fbx_model_file(versionUp=True, origScene=None, *args):
    """
    publishes fbx for model and texture files
    ARGS:
        versionUp (bool): whether we should version up the Maya scene after publish or not
        origScene (string): the full to the original Maya scene file
    RETURN:
        bool: whether we've successfully published or not
    """
    # all happens in current:
    if not origScene:
        cmds.warning(
            "assetPublish.publish_fbx_rig_file: You haven't passed in a scene path!"
        )
        return (False)

    pp = uf.PathParser(origScene)

    sel = cmds.ls(sl=True)
    if not sel:
        cmds.warning("You need to select the objects to export! Try again.")
        return (False)

    pubFbxPath = uf.fix_path(os.path.join(pp.phasePath, "Publish/FBX/"))
    tokens = pp.fileName.split("_")
    tokens[-2] = "Publish"
    pubFileName = "_".join(tokens)[:-3] + ".fbx"
    pubFilePath = uf.fix_path(os.path.join(pubFbxPath, pubFileName))

    # check for references in selection? Or just import references from the fbx exporter?

    if os.path.isfile(pubFilePath):
        overwrite = cmds.confirmDialog(
            title="Overwrite Confirmation",
            message=
            "A publish FBX already exists for this file.\nShould we overwrite?",
            button=("Overwrite", "Cancel"),
            defaultButton="Overwrite",
            cancelButton="Cancel",
            dismissString="Cancel")

        if overwrite == "Cancel":
            print "Publish skipped for FBX file (.fbx) called {0}".format(
                pubFilePath)
            return (True)

    mel.eval('FBXLoadExportPresetFile -f "{0}";'.format(modelPreset))
    mel.eval(
        'FBXExport -f "{0}" -s'.format(pubFilePath))  # f-> force, s->selected

    return (True)
Пример #14
0
 def __init__(self, filePath=None, selectionBased=False, *args):
     self.dict = {}
     self.projEnvPath = os.environ["MAYA_PROJECT_PATH"]
     self.selBased = selectionBased
     self.filePath = filePath
     print "filePath: ", self.filePath
     self.proj = ai.AssetInfo()
     self.pp = uf.PathParser(filePath)
     if not self.pp.compatible:
         # dummy check that the folders exist
         files = self.proj.get_asset_contents(self.proj.charsPath[0])
         self.filepath = "{0}{1}".format(self.proj.charsPath[0], files[0])
     self.assetList = self.proj.get_asset_name_list()
     self.saveAs_UI()
    def create_variant_dict(self):
        self.pathParse.get_variants_list()
        phase = "/".join(self.pathParse.path.split("/")[:7])
        varDict = {}
        for variant in self.pathParse.variantList:
            varFile = self.pathParse.fileName.split("_")
            varFile[-4] = variant
            varName = "_".join(varFile)
            varPath = "{0}/{1}".format(self.pathParse.stagePath, varName)

            tempPath = uf.PathParser(varPath)
            tempPath.get_version_info()
            versions = tempPath.versionNumbersString
            varDict[variant] = versions
        return (varDict)
Пример #16
0
def stagePublish(versionUp=True, *args):
    """
    checks the current scene if it's compatible, if not kick out
    ARGS:
        versionUp (bool): whether to version up the work file on publish
    """
    origScene = cmds.file(q=True, sn=True)
    pp = uf.PathParser(origScene)

    # bail if current scene is not compatible
    if not pp.compatible:
        cmds.warning("assetPublish.publish_maya_scene: You're not in a project compatible scene! Sorry. See a TD")
        return()
   
    # if it's an anm work file
    if pp.phase in ["Animation"] and pp.stage=="Work":
        get_reference_list_UI(versionUp, origScene)
Пример #17
0
def populate_files(proj, *args):
    """
    clears the file list, then populates based on the phase and the selected asset in the asset TSL
    """
    proj = ai.AssetInfo()

    clear_file_list()

    selTab = cmds.tabLayout(widgets["assetsTab"], q=True, st=True)

    tab, phase, assetPath, assetFiles = [None, None, None, None]

    if selTab != "STGS":
        tab, phase, assetPath, assetFiles = get_asset_info(proj)
    else:
        tab, phase, assetPath, assetFiles = get_stage_info(proj)

    if assetFiles:
        for file in assetFiles:
            a = cmds.textScrollList(widgets["filesTSL"],
                                    e=True,
                                    a=os.path.basename(file))
    else:
        cmds.textScrollList(widgets["filesTSL"], e=True, a="No Files")

    # add popmenu to the list object to go to explorer
    cmds.popupMenu(p=widgets["filesTSL"])
    cmds.menuItem(l="Open Folder in Explorer", c=get_path_explorer)

    # try to line up the current scene in the file list
    currFile = cmds.file(q=True, sn=True)
    if currFile:
        fileObj = uf.PathParser(currFile)
        if fileObj.compatible and (os.path.basename(currFile) in assetFiles):
            cmds.textScrollList(widgets["filesTSL"],
                                e=True,
                                si=os.path.basename(currFile))
    else:
        # get the last file and select that
        numItems = cmds.textScrollList(widgets["filesTSL"], q=True, ni=True)
        cmds.textScrollList(widgets["filesTSL"], e=True, sii=numItems)
Пример #18
0
def update_all_references(*args):

    # if scene is modded, should we save?
    mod = cmds.file(q=True, modified=True)
    if mod:
        test = save_current_dialog()
        if not test:
            return ()

    # get all refs
    refs = cmds.file(q=True, r=True)

    # # for each ref file
    for ref in refs:
        # make path object
        print "updateAllReferences: checking: {0}".format(ref)
        rfn = cmds.file(ref, q=True, rfn=True)
        path = None
        pathparse = uf.PathParser(ref)
        if pathparse.compatible:
            brackets = ""
            if fnmatch.fnmatch(ref, "*{*}"):
                parts = ref.partition("{")
                brackets = parts[1] + parts[2]
            # get current version string
            thisVer = pathparse.versionString
            #   get the version list for that file
            pathparse.get_version_info()
            print "Current: {0} vs. {1}".format(
                thisVer, pathparse.versionNumbersString[-1])
            if thisVer != pathparse.versionNumbersString[-1]:
                print "----- updating {1} to version {1}".format(
                    rfn, pathparse.versionNumbersString[-1])
                path = pathparse.pathNoNum + pathparse.versionNumbersString[
                    -1] + ".mb" + brackets
                cmds.file(path, loadReference=rfn, type="mayaBinary")
        else:
            print "Not a pipeline compatible ref. Skipping! -- {0}".format(ref)

        pathparse = None
Пример #19
0
def publish_fbx_folder(path, *args):
    """
    now go through the folder path and open each, open the gameexp, then populate the export path, then exportgo
    """
    pathP = uf.PathParser(path)
    mbpubpath = pathP.phasePath + "/Publish/MB/{0}_v{1}".format(
        pathP.variant, pathP.versionString)
    fbxpubpath = pathP.phasePath + "/Publish/FBX/{0}_v{1}".format(
        pathP.variant, pathP.versionString)

    # get the maya files
    mbFiles = fnmatch.filter(os.listdir(mbpubpath), "*.mb")

    for mb in mbFiles:
        mel.eval("gameFbxExporter;")
        print "========= multiRefAnimExport.publish_fbx_folder: opening {0}/{1}".format(
            mbpubpath, mb)
        cmds.file("{0}/{1}".format(mbpubpath, mb), open=True, f=True)

        filename = "{0}_{1}_{2}".format(pathP.name, pathP.variant,
                                        "_".join(mb.split("_")[3:-1]))
        # check if there is more than two assemblies
        # excludeAss = ["persp", "front", "side", "top"]
        # assemblies = [x for x in cmds.ls(assemblies=True) if x not in excludeAss]
        # if len(assemblies)>2:
        #     # grab pairs and export

        if not os.path.isdir(fbxpubpath):
            os.makedirs(fbxpubpath)

        node = cmds.ls(type="gameFbxExporter")[-1]
        # set path and file name
        uf.set_gameExport_info(node, fbxpubpath, filename)
        # run exporter
        print "========= multiRefAnimExport.publish_fbx_folder: trying to publish FBX {0}/{1}".format(
            mbpubpath, mb)
        mel.eval("gameExp_DoExport;")
Пример #20
0
def publish_fbx_anim_file(versionUp=True, origScene=None, *args):
    # THIS IS FOR ANIM EXPORTING

    # save current scene
    # check whether gameexport plug in is loaded
    mel.eval("gameFbxExporter;")
    # version up
    if versionUp:
        verUpFile = get_version_up_name(origScene)
        copy2(origScene, verUpFile)
        print "===== Versioned up {0} to {1}!".format(origScene, verUpFile)
    else:
        print "===== Not versioning up publish of {0}".format(origScene)

    if not origScene:
        cmds.warning(
            "assetPublish.publish_fbx_anim_file: You haven't passed in a scene path!"
        )
        return (False)

# assuming references
    refs = cmds.file(q=True, r=True)
    if not refs:
        cmds.warning("There are no references in this scene. . .")
        return (False)
    if len(refs) > 1:
        cmds.warning("There are too many references in this scene. . .")
        return (False)


# below would all be under a for loop for each reference in the stages?
    pp = uf.PathParser(origScene)

    # assuming a namespace
    geoGrp = cmds.ls("*:GEO")
    jntGrp = cmds.ls("*:EXPORT_JNT_Grp")

    # check for geo grps
    if not geoGrp or len(geoGrp) > 1:
        cmds.warning(
            "AssetPublish.publish_fbx_anim_file:You either have no grp called 'GEO' -IN A NAMESPACE-, or too many objects called 'GEO'.\n fbx export aborted!"
        )
        return (False)
    geos = child_match_check(geoGrp[0], "*_Geo_Grp")
    if not geos:
        return (False)

    # check for jnt grps
    if not jntGrp or len(jntGrp) > 1:
        cmds.warning(
            "AssetPublish.publish_fbx_anim_file:You either have no grp called 'EXPORT_JNT_Grp' -IN A NAMESPACE-, or too many objects called 'EXPORT_JNT_Grp'.\n fbx export aborted!"
        )
        return (False)
    roots = child_match_check(jntGrp[0], "*_Root_Jnt")
    if not roots:
        return (False)

    # check correspondence of geo and root jnts
    correspond = check_correspondence(geos, roots)
    if not correspond:
        return (False)

    cmds.file(refs[0], ir=True)

    pubFbxPath = uf.fix_path(os.path.join(pp.phasePath, "Publish/FBX/"))
    tokens = pp.fileName.split("_")
    tokens[-2] = "Publish"
    pubFileName = "_".join(tokens)[:-3] + ".fbx"
    pubFilePath = uf.fix_path(os.path.join(pubFbxPath, pubFileName))

    start, end = uf.get_frame_range()

    # bake joints
    for r in roots:
        # get child roots if joints
        allD = cmds.listRelatives(r, allDescendents=True)
        jnts = [x for x in allD if cmds.objectType(x, isa="joint")]
        # function to bake selected on all jnts under this root
        bake_selected(jnts, start, end)

    namespace = cmds.file(refs[0], q=True, ns=True)
    uf.remove_namespaces()

    # delete constraints
    cmds.delete(cmds.ls(type="constraint"))
    cmds.select(cl=True)
    # move jnts and geo into world parent
    for root in roots:
        rootremove = "{0}:".format(namespace)
        basename = root.split(":")[1].split("_Root_Jnt")[0]
        geo = "{0}_Geo_Grp".format(basename)
        root = "{0}_Root_Jnt".format(basename)
        cmds.parent([geo, root], w=True)
        tokens[-2] = basename
        pubFileName = "_".join(tokens)[:-3]
        pubFilePath = uf.fix_path(os.path.join(pubFbxPath, pubFileName))
        rootremove = "{0}:".format(namespace)
        cmds.select([root, geo], r=True)
        # do this the cmds way
        nodes = mel.eval("gameExp_GetGameFbxExporterNodeList()")
        cmds.select(nodes, add=True)

        keep = [root, geo]
        for node in nodes:
            keep.append(node)

        # delete all other top level nodes
        delete_other_top_level_nodes(keep)

        # if this exists, should we overwrite?
        if os.path.isfile(pubFilePath):
            overwrite = cmds.confirmDialog(
                title="Overwrite Confirmation",
                message=
                "A publish FBX already exists for this file.\nShould we overwrite?",
                button=("Overwrite", "Cancel"),
                defaultButton="Overwrite",
                cancelButton="Cancel",
                dismissString="Cancel")

            if overwrite == "Cancel":
                print "Publish skipped for FBX file (.fbx) called {0}".format(
                    pubFilePath)
                return (True)

        # get path for maya publish
        pubsplits = pubFilePath.split("/")
        pubsplits[-2] = "MB"
        mayapubpath = "/".join(pubsplits)

        # just export maya scene here. . . to publish (need to get mb path)
        # get the latest "gameExporterPreset*" for export (not sure if latest what we want?)
        if not nodes:
            cmds.warning(
                "You don't have any game export nodes in your scene. Just exporting a straight fbx clip!"
            )
            mel.eval('FBXLoadExportPresetFile -f "{0}";'.format(anmPreset))
            mel.eval('FBXExport -f "{0}" -s'.format(pubFilePath + ".fbx"))

        else:
            print "===== anim publish:\n- saving {0}".format(mayapubpath +
                                                             ".mb")
            cmds.file(mayapubpath + ".mb", es=True, f=True, type="mayaBinary")
            print "- opening {0}".format(mayapubpath + ".mb")
            hold = cmds.file(mayapubpath + ".mb", o=True, f=True)
            print "-formatting and exporting"
            # check that we're doing all we can here. . . .
            # uf.set_gameExport_info(gnodes[-1], filepath, filename)
            ge.set_and_export(pubFilePath + ".fbx")

    return (True)
Пример #21
0
def publish_fbx_rig_file(versionUp=True, origScene=None, *args):
    """
    requires an EXPORT_JNT_Grp group with one root for each export rig named: 'name_Root_Jnt'
    requires a GEO group with one folder for each export rig named: 'name_Geo_Grp'
    names should correspond ("fish_Root_Jnt", "fish_Geo_Grp")
    """
    # all happens in current:
    if not origScene:
        cmds.warning(
            "assetPublish.publish_fbx_rig_file: You haven't passed in a scene path!"
        )
        return (False)

    pp = uf.PathParser(origScene)

    geoGrp = cmds.ls("GEO")
    jntGrp = cmds.ls("EXPORT_JNT_Grp")

    # check for geo grps
    if not geoGrp or len(geoGrp) > 1:
        cmds.warning(
            "AssetPublish.publish_fbx_rig_file:You either have no grp called 'GEO', or too many objects called 'GEO'.\n fbx export aborted!"
        )
        return (False)
    geos = child_match_check(geoGrp, "*_Geo_Grp")
    if not geos:
        return (False)

    # check for jnt grps
    if not jntGrp or len(jntGrp) > 1:
        cmds.warning(
            "AssetPublish.publish_fbx_rig_file:You either have no grp called 'EXPORT_JNT_Grp', or too many objects called 'EXPORT_JNT_Grp'.\n fbx export aborted!"
        )
        return (False)

    roots = child_match_check(jntGrp, "*_Root_Jnt")
    if not roots:
        cmds.warning(
            "AssetPublish.publish_fbx_rig_file: Couldn't find anything under {0} called '*_Root_Jnt'"
            .format(jntGrp))
        return (False)

    # check correspondence
    correspond = check_correspondence(geos, roots)
    if not correspond:
        return (False)

    pubFbxPath = uf.fix_path(os.path.join(pp.phasePath, "Publish/FBX/"))
    tokens = pp.fileName.split("_")
    tokens[-2] = "Publish"
    pubFileName = "_".join(tokens)[:-3] + ".fbx"
    pubFilePath = uf.fix_path(os.path.join(pubFbxPath, pubFileName))

    # check if there's any animation in the file (time based), abort if there is
    # check for references, etc. .

    # delete constraints
    cmds.delete(cmds.ls(type="constraint"))
    cmds.select(cl=True)
    # move jnts and geo into world parent
    for root in roots:
        basename = root.split("_Root_Jnt")[0]
        geo = "{0}_Geo_Grp".format(basename)
        cmds.parent([geo, root], w=True)
        # create filename
        tokens[-2] = basename
        pubFileName = "_".join(tokens)[:-3] + ".fbx"
        pubFilePath = uf.fix_path(os.path.join(pubFbxPath, pubFileName))
        cmds.select([root, geo], r=True)

        # if this exists, should we overwrite?
        if os.path.isfile(pubFilePath):
            overwrite = cmds.confirmDialog(
                title="Overwrite Confirmation",
                message=
                "A publish FBX already exists for this file.\nShould we overwrite?",
                button=("Overwrite", "Cancel"),
                defaultButton="Overwrite",
                cancelButton="Cancel",
                dismissString="Cancel")

            if overwrite == "Cancel":
                print "Publish skipped for FBX file (.fbx) called {0}".format(
                    pubFilePath)
                return (True)

        mel.eval('FBXLoadExportPresetFile -f "{0}";'.format(rigPreset))
        mel.eval('FBXExport -f "{0}" -s'.format(pubFilePath))

    return (True)
Пример #22
0
def publish_fbx_anim_file(versionUp=True, origScene=None, *args):
    """
    This is for asset anim exporting. File requires ONE AND ONLY ONE reference
    """
    # save current scene
    # check whether gameexport plug in is loaded
    mel.eval("gameFbxExporter;")
    # version up
    if versionUp:
        verUpFile = get_version_up_name(origScene)
        copy2(origScene, verUpFile)
        print "===== Versioned up {0} to {1}!".format(origScene, verUpFile)
    else:
        print "===== Not versioning up publish of {0}".format(origScene)

    if not origScene:
        cmds.warning(
            "assetPublish.publish_fbx_anim_file: You haven't passed in a scene path!"
        )
        return (False)

    refs = cmds.file(q=True, r=True)
    if not refs:
        cmds.warning("There are no references in this scene. . .")
        return (False)
    if len(refs) > 1:
        cmds.warning("There are too many references in this scene. . .")
        return (False)
    pp = uf.PathParser(origScene)

    # assuming a namespace
    geoGrp = cmds.ls("*:GEO")
    jntGrp = cmds.ls("*:EXPORT_JNT_Grp")

    # check for geo grps
    if not geoGrp or len(geoGrp) > 1:
        cmds.warning(
            "AssetPublish.publish_fbx_anim_file:You either have no grp called 'GEO' -IN A NAMESPACE-, or too many objects called 'GEO'.\n fbx export aborted!"
        )
        return (False)
    geos = child_match_check(geoGrp[0], "*_Geo_Grp")
    if not geos:
        return (False)

    # check for jnt grps
    if not jntGrp or len(jntGrp) > 1:
        cmds.warning(
            "AssetPublish.publish_fbx_anim_file:You either have no grp called 'EXPORT_JNT_Grp' -IN A NAMESPACE-, or too many objects called 'EXPORT_JNT_Grp'.\n fbx export aborted!"
        )
        return (False)
    roots = child_match_check(jntGrp[0], "*_Root_Jnt")
    if not roots:
        return (False)

    # check correspondence of geo and root jnts
    correspond = check_correspondence(geos, roots)
    if not correspond:
        return (False)

    cmds.file(refs[0], ir=True)

    pubFbxPath = uf.fix_path(
        os.path.join(
            pp.phasePath,
            "Publish/FBX/{0}_v{1}".format(pp.variant, pp.versionString)))
    print pubFbxPath

    if not os.path.isdir(pubFbxPath):
        os.makedirs(pubFbxPath)

    tokens = pp.fileName.split("_")[:3]
    pubFileName = "_".join(tokens) + ".fbx"
    pubFilePath = uf.fix_path(os.path.join(pubFbxPath, pubFileName))

    start, end = uf.get_frame_range()

    # bake joints
    for r in roots:
        # get child roots if joints
        allD = cmds.listRelatives(r, allDescendents=True)
        jnts = [x for x in allD if cmds.objectType(x, isa="joint")]
        # function to bake selected on all jnts under this root
        bake_selected(jnts, start, end)

    namespace = cmds.file(refs[0], q=True, ns=True)
    uf.remove_namespaces()

    # delete constraints
    cmds.delete(cmds.ls(type="constraint"))
    cmds.select(cl=True)
    # move jnts and geo into world parent
    for root in roots:
        rootremove = "{0}:".format(namespace)
        basename = root.split(":")[1].split("_Root_Jnt")[0]
        geo = "{0}_Geo_Grp".format(basename)
        root = "{0}_Root_Jnt".format(basename)
        cmds.parent([geo, root], w=True)
        tokens[-1] = basename
        pubFileName = "_".join(tokens)
        pubFilePath = uf.fix_path(os.path.join(pubFbxPath, pubFileName))
        rootremove = "{0}:".format(namespace)
        cmds.select([root, geo], r=True)

        nodes = cmds.ls(type="gameFbxExporter")
        if not nodes:
            cmds.warning(
                "AssetPublish.publish_fbx_anim_files: You don't have any game exporter nodes in your scene! Aborting!"
            )
            return ()
        cmds.select(nodes, add=True)

        keep = [root, geo]
        for node in nodes:
            keep.append(node)

        # delete all other top level nodes
        delete_other_top_level_nodes(keep)

        # if this exists, should we overwrite?
        if os.path.isfile(pubFilePath):
            overwrite = cmds.confirmDialog(
                title="Overwrite Confirmation",
                message=
                "A publish FBX already exists for this file.\nShould we overwrite?",
                button=("Overwrite", "Cancel"),
                defaultButton="Overwrite",
                cancelButton="Cancel",
                dismissString="Cancel")

            if overwrite == "Cancel":
                print "Publish skipped for FBX file (.fbx) called {0}".format(
                    pubFilePath)
                return (True)

        # get path for maya publish
        pubsplits = pubFilePath.split("/")
        pubsplits[-3] = "MB"
        mayapubpath = "/".join(pubsplits)

        # if there's not a game export node, just export an fbx, otherwise do the game export all to one clip
        if not nodes:
            cmds.warning(
                "You don't have any game export nodes in your scene. Just exporting a straight fbx animation!"
            )
            mel.eval('FBXLoadExportPresetFile -f "{0}";'.format(anmPreset))
            mel.eval('FBXExport -f "{0}" -s'.format(pubFilePath + ".fbx"))

        else:
            print "===== anim publish:\n- saving {0}".format(mayapubpath +
                                                             ".mb")
            cmds.file(mayapubpath + ".mb", es=True, f=True, type="mayaBinary")
            print "multiRefAnimExport.publish_fbx_anim_file: opening {0}".format(
                mayapubpath + ".mb")
            hold = cmds.file(mayapubpath + ".mb", o=True, f=True)
            # set the export parameters
            uf.set_gameExport_info(nodes[-1], pubFbxPath, pubFileName)
            print "========= multiRefAnimExport.publish_fbx_anim_file: trying to publish FBX {0}/{1}".format(
                pubFbxPath, pubFileName + ".fbx")
            #game export
            mel.eval("gameExp_DoExport;")

    return (True)
Пример #23
0
def publish_fbx_anim_file(versionUp=True, origScene=None, references=None, *args):
    """
    Assumes we're in an anim assembly scene that contains referenced rigs (only one namespace)
    This will spit out maya scenes that are ready for fbx export. One maya scene per reference object in the current scene, each of which contains only the mesh and joint groups that need to be exported. These scenes contain all available 'rigs' from that asset.
    Args:
        versionup (bool): whether we should version up the current scene
        origscene (string): the full path to the original scene we're trying to publish
        references (list): list of the reference paths in the scene to deal with
    Returns:
        bool: whether we've run through all successfully
    """
    cmds.file(s=True)

    # check whether game exporter plugin is loaded, load if not
    uf.plugin_load("gameFbxExporter")

# check if there are any gmae export nodes, bail if not? or bail in the later stage - calling function

    # version up
    if versionUp:
        verUpFile = get_version_up_name(origScene)
        copy2(origScene, verUpFile)
        print "===== Versioned up {0} to {1}!".format(origScene, verUpFile)
    else:
        print "===== Not versioning up publish of {0}".format(origScene) 

    if not origScene:
        cmds.warning("assetPublish.publish_fbx_anim_file: You haven't passed in a scene path!")
        publishState = False
        return()

    # assuming references
    refs = references
    if not refs:
        cmds.warning("There are no references in this scene. . .")
        publishState = False
        return()

    # cull out the bad references from our input list
    goodRefs = cull_bad_references(refs)


# bake all jnts THEN do all the rest
    for ref in goodRefs:
        namespace = cmds.file(ref, q=True, ns=True)
        print "BAKING JOINTS FOR: {0}".format(namespace)        
        geoGrp = cmds.ls("{0}:GEO".format(namespace))
        jntGrp = cmds.ls("{0}:EXPORT_JNT_Grp".format(namespace))        
        
        geos = child_match_check(geoGrp[0], "*_Geo_Grp")
        roots = child_match_check(jntGrp[0], "*_Root_Jnt")

        start, end = uf.get_frame_range()

       # bake joints
        for r in roots:
            # get child roots if joints
            allD = cmds.listRelatives(r, allDescendents=True)
            jnts = [x for x in allD if cmds.objectType(x, isa="joint")]
            # function to bake selected on all jnts under this root
            bake_selected(jnts, start, end)

    for ref in goodRefs:
        pp = uf.PathParser(origScene)
        
        namespace = cmds.file(ref, q=True, ns=True)
        
        geoGrp = cmds.ls("{0}:GEO".format(namespace))
        jntGrp = cmds.ls("{0}:EXPORT_JNT_Grp".format(namespace))        
        
        # imports the reference
        cmds.file(ref, ir=True)

        geos = child_match_check(geoGrp[0], "*_Geo_Grp")
        roots = child_match_check(jntGrp[0], "*_Root_Jnt")

        # here's where we'd do the folder (figure out path stuff) - add the variant name
        pubFbxPath = uf.fix_path(os.path.join(pp.phasePath, "Publish/MB/{0}_v{1}".format(pp.variant, pp.versionString)))
        print "------- trying to make directory: {0}".format(pubFbxPath)
        if not os.path.exists(pubFbxPath):
            os.makedirs(pubFbxPath)
        tokens = pp.fileName.split("_")
        tokens[-2] = namespace

        start, end = uf.get_frame_range()

        # delete constraints
        cmds.delete(cmds.ls("{0}:*".format(namespace), type="constraint"))
        cmds.select(cl=True)

        # get list of roots in this ref
        fullKeepList = []
        for root in roots:
            basename = root.split(":")[1].split("_Root_Jnt")[0]
            geo = "{0}:{1}_Geo_Grp".format(namespace, basename)
            root = "{0}:{1}_Root_Jnt".format(namespace, basename)
            cmds.parent([geo, root], w=True)
            fullKeepList.append(geo)
            fullKeepList.append(root)
        cmds.select(fullKeepList, r=True)
        delete_other_top_level_nodes(cmds.ls(sl=True))

        try:
            cmds.namespace(mv=[namespace, ":"], f=True)
            cmds.namespace(rm=namespace)
        except:
            cmds.warning("NAMESPACE PROBLEM!", namespace)

        # collect the roots to export
        for root in roots:
            exportList = []
            basename = root.split(":")[1].split("_Root_Jnt")[0]
            geo = "{0}_Geo_Grp".format(basename)
            root = "{0}_Root_Jnt".format(basename)
            nodes = cmds.ls(type="gameFbxExporter")
            exportList.append(root)
            exportList.append(geo)
            for node in nodes:
                exportList.append(node)

            cmds.select(exportList, r=True)
            print "multiRefAnimExport.publish_fbx_anim_file: exporting -- \n {0}".format(exportList)
            # strip away namespace (if it's there)
            tokens[2] = basename
            pubFileName = "_".join(tokens)
            pubFilePath = uf.fix_path(os.path.join(pubFbxPath, pubFileName))

            # if this exists, should we overwrite?
            if os.path.isfile(pubFilePath):
                overwrite = cmds.confirmDialog(title="Overwrite Confirmation", message = "A publish FBX already exists for this file.\nShould we overwrite?", button = ("Overwrite", "Cancel"), defaultButton = "Overwrite", cancelButton = "Cancel", dismissString = "Cancel")

                if overwrite == "Cancel":
                    print "multiRefAnimExport.publish_fbx_anim_file:Publish skipped for FBX file (.fbx) called {0}".format(pubFilePath)
                    return() 

            print "===== anim publish:\n- saving {0}".format(pubFilePath)
            cmds.file(pubFilePath + ".mb", es=True, f=True, type="mayaBinary")

    return(True)
Пример #24
0
def assetPublish(versionUp=True, *args):
    """
    checks the current scene if it's compatible, if not kick out
    ARGS:
        versionUp (bool): whether to version up the work file on publish
    """
    origScene = cmds.file(q=True, sn=True)
    print "-------ORIG SCENE line 414", origScene
    pp = uf.PathParser(origScene)

    # bail if current scene is not compatible
    if not pp.compatible:
        cmds.warning(
            "assetPublish.assetPublish: You're not in a project compatible scene! Sorry. See a TD"
        )
        return ()

    # if it's not a stage file or a publish file and it's either modeling or rigging phase
    if pp.assetType != "Stages" and pp.phase in [
            "Rigging", "Modeling", "Texturing", "Lighting"
    ] and pp.stage == "Work":
        mayapub = publish_maya_scene(versionUp, origScene)
        if not mayapub:  # i.e. we've failed somewhere in the func
            return ()
    else:
        print "===== not doing standard maya asset publish, since you're in {0} phase and {1} stage of the pipeline".format(
            pp.phase, pp.stage)

    # lets check if the fbx plugin is loaded
    uf.plugin_load("fbxmaya")

    # if it's modeling or texturing phase - fbx export
    if pp.assetType != "Stages" and pp.phase in ["Modeling", "Texturing"
                                                 ] and pp.stage == "Work":
        fbxPub = publish_fbx_model_file(versionUp, origScene)
        if not fbxPub:
            return ()

    # if it's a rig work file
    if pp.assetType != "Stages" and pp.phase in ["Rigging"
                                                 ] and pp.stage == "Work":
        fbxPub = publish_fbx_rig_file(versionUp, origScene)
        if not fbxPub:
            return ()

    # if it's an anm work file
    if pp.assetType != "Stages" and pp.phase in ["Animation"
                                                 ] and pp.stage == "Work":
        fbxPub = publish_fbx_anim_file(versionUp, origScene)
        if not fbxPub:
            return ()

    if versionUp:
        verNum = int(pp.path[-7:-3])
        pp.get_version_info()
        nums = pp.versionNumbers
        newNum = nums[-1]

        verUpFile = "{0}{1}{2}".format(origScene[:-7],
                                       str(newNum).zfill(4), ".mb")

        if os.path.isfile(verUpFile):
            print "assetPublish.assetPublish: Opening version up file:", verUpFile
            cmds.file(verUpFile, open=True, force=True)
        else:
            print "assetPublish.assetPublish: Couldn't find version up, opening original file: ", pp.path
            cmds.file(pp.path, open=True, force=True)
    else:
        print "assetPublish.assetPublish: Opening original file: ", pp.path
        cmds.file(pp.path, open=True, force=True)

    # close the game export window
    if cmds.window("gameExporterWindow", exists=True):
        cmds.deleteUI("gameExporterWindow")
    # reload file win
    fm.fileManager()

    cmds.confirmDialog(m="Asset Publish Sucessful!", t="AssetPublish")
Пример #25
0
def publish_fbx_anim_file(versionUp=True, origScene=None, *args):
    # THIS IS FOR ANIM EXPORTING

    if not origScene:
        cmds.warning("assetPublish.publish_fbx_anim_file: You haven't passed in a scene path!")
        return(False)
# assuming references
    refs = cmds.file(q=True, r=True)
    if not refs:
        cmds.warning("There are no references in this scene. . .")
        return(False)
    if len(refs) > 1:
        cmds.warning("There are too many references in this scene. . .")
        return(False)
# below would all be under a for loop for each reference in the stages? 
    pp = uf.PathParser(origScene)

# assuming a namespace
    geoGrp = cmds.ls("*:GEO")
    jntGrp = cmds.ls("*:EXPORT_JNT_Grp")

    # check for geo grps
    if not geoGrp or len(geoGrp)>1:
        cmds.warning("AssetPublish.publish_fbx_anim_file:You either have no grp called 'GEO' -IN A NAMESPACE-, or too many objects called 'GEO'.\n fbx export aborted!")
        return(False)
    geos = child_match_check(geoGrp[0], "*_Geo_Grp")
    if not geos:
        return(False)

    # check for jnt grps
    if not jntGrp or len(jntGrp)>1:
        cmds.warning("AssetPublish.publish_fbx_anim_file:You either have no grp called 'EXPORT_JNT_Grp' -IN A NAMESPACE-, or too many objects called 'EXPORT_JNT_Grp'.\n fbx export aborted!")
        return(False)    
    roots = child_match_check(jntGrp[0], "*_Root_Jnt")
    if not roots:
        return(False)

    cmds.file(refs[0], ir=True)

    # check correspondence of geo and root jnts
    correspond = check_correspondence(geos, roots)
    if not correspond:
        return(False)

    pubFbxPath = uf.fix_path(os.path.join(pp.phasePath, "Publish/FBX/"))
    tokens = pp.fileName.split("_")
    tokens[-2] = "Publish"
    pubFileName = "_".join(tokens)[:-3] + ".fbx"
    pubFilePath = uf.fix_path(os.path.join(pubFbxPath, pubFileName))

    # bake joints
    for r in roots:
        # get child roots if joints
        allD = cmds.listRelatives(r, allDescendents=True)
        jnts = [x for x in allD if cmds.objectType(x, isa="joint")]
        # function to bake selected
        for j in jnts:
            attr=["t","r","s"]
            co=["x","y","z"]
            attrLs=[]
            for at in attr:
                for c in co:
                    attrLs.append("%s.%s%s"%(j,at,c))
            for x in attrLs:
                try:
                    mc.setAttr(x, k=1)
                except:
                    pass

    namespace = cmds.file(refs[0], q=True, ns=True)
    uf.remove_namespaces()

    # delete constraints
    cmds.delete(cmds.ls(type="constraint"))
    cmds.select(cl=True)
    # move jnts and geo into world parent
    for root in roots:
        basename = root.split("_Root_Jnt")[0]
        geo = "{0}_Geo_Grp".format(basename)
        cmds.parent([geo, root], w=True)
        # create filename
        tokens[-2] = basename
        pubFileName = "_".join(tokens)[:-3] + ".fbx"
        pubFilePath = uf.fix_path(os.path.join(pubFbxPath, pubFileName))
        cmds.select([root, geo], r=True)

        # if this exists, should we overwrite?
        if os.path.isfile(pubFilePath):
            overwrite = cmds.confirmDialog(title="Overwrite Confirmation", message = "A publish FBX already exists for this file.\nShould we overwrite?", button = ("Overwrite", "Cancel"), defaultButton = "Overwrite", cancelButton = "Cancel", dismissString = "Cancel")

            if overwrite == "Cancel":
                print "Publish skipped for FBX file (.fbx) called {0}".format(pubFilePath)
                return(True) 

        mel.eval('FBXLoadExportPresetFile -f "{0}";'.format(preset))
        mel.eval('FBXExport -f "{0}" -s'.format(pubFilePath))

    return(True)    


    # loop through namespaces/references:
    #   import reference
    #   delete namespace
    #   loop through joint grps, geo grps:
    #       bake jnts
    #       clean up joints shit

    #       "CloudStage_Tree_main_Rig1_A_v0001.fbx"
    #           stage     asset ns    subgrp  version
        
    #       check for version folder, create it if it doesn't exist
    pass
def publish_fbx_anim_file(versionUp=True, origScene=None, *args):
    """
    Assumes we're in an anim assembly scene that contains referenced rigs (only one namespace)
    This will spit out maya scenes that are ready for fbx export. One maya scene per reference object in the current scene, each of which contains only the mesh and joint groups that need to be exported. These scenes contain all available 'rigs' from that asset.
    Args:
        versionup (bool): whether we should version up the current scene
        origscene (string): the full path to the original scene we're trying to publish
    Returns:
        bool: whether we've run through all successfully
    """
    cmds.file(s=True)

    # check whether game exporter plugin is loaded, load if not
    uf.plugin_load("gameFbxExporter")

    # version up
    if versionUp:
        verUpFile = get_version_up_name(origScene)
        copy2(origScene, verUpFile)
        print "===== Versioned up {0} to {1}!".format(origScene, verUpFile)
    else:
        print "===== Not versioning up publish of {0}".format(origScene)

    if not origScene:
        cmds.warning(
            "assetPublish.publish_fbx_anim_file: You haven't passed in a scene path!"
        )
        return (False)

    # assuming references
    refs = cmds.file(q=True, r=True)
    if not refs:
        cmds.warning("There are no references in this scene. . .")
        return (False)

    for ref in refs:
        pp = uf.PathParser(origScene)
        namespace = cmds.file(ref, q=True, ns=True)

        # assuming a namespace
        geoGrp = cmds.ls("{0}:GEO".format(namespace))
        jntGrp = cmds.ls("{0}:EXPORT_JNT_Grp".format(namespace))

        # check for geo grps
        if not geoGrp:
            cmds.warning(
                "AssetPublish.publish_fbx_anim_file:You have no grp called 'GEO' -IN A NAMESPACE-.\n fbx export aborted!"
            )
            return (False)
        geos = child_match_check(geoGrp[0], "*_Geo_Grp")
        if not geos:
            return (False)

        # check for jnt grps
        if not jntGrp:
            cmds.warning(
                "AssetPublish.publish_fbx_anim_file:You either have no grp called 'EXPORT_JNT_Grp' -IN A NAMESPACE-.\n fbx export aborted!"
            )
            return (False)
        roots = child_match_check(jntGrp[0], "*_Root_Jnt")
        if not roots:
            return (False)

        # imports the reference
        cmds.file(ref, ir=True)

        # check correspondence of geo and root jnts
        correspond = check_correspondence(geos, roots)
        if not correspond:
            return (False)

        # here's where we'd do the folder (figure out path stuff) - add the variant name
        pubFbxPath = uf.fix_path(
            os.path.join(
                pp.phasePath,
                "Publish/MB/{0}_v{1}".format(pp.variant, pp.versionString)))
        print "------- trying to make dirctory: {0}".format(pubFbxPath)
        if not os.path.exists(pubFbxPath):
            os.mkdir(pubFbxPath)
        tokens = pp.fileName.split("_")
        tokens[-2] = namespace

        start, end = uf.get_frame_range()

        # bake joints
        for r in roots:
            # get child roots if joints
            allD = cmds.listRelatives(r, allDescendents=True)
            jnts = [x for x in allD if cmds.objectType(x, isa="joint")]
            # function to bake selected on all jnts under this root
            bake_selected(jnts, start, end)

        # delete constraints
        cmds.delete(cmds.ls("{0}:*".format(namespace), type="constraint"))
        cmds.select(cl=True)

        # list for what to keep in this reference
        keepList = []

        # parent each root to world
        for root in roots:
            basename = root.split(":")[1].split("_Root_Jnt")[0]
            geo = "{0}:{1}_Geo_Grp".format(namespace, basename)
            root = "{0}:{1}_Root_Jnt".format(namespace, basename)
            cmds.parent([geo, root], w=True)
            # make this a more generic way to get the game nodes!! (search for type)
            nodes = cmds.ls(type="gameFbxExporter")
            keepList.append(root)
            keepList.append(geo)
            for node in nodes:
                keepList.append(node)

        cmds.select(keepList, r=True)
        # strip away namespace
        cmds.namespace(mv=[namespace, ":"], f=True)
        cmds.namespace(rm=namespace)
        # delete all other top level nodes
        delete_other_top_level_nodes(cmds.ls(sl=True))
        pubFileName = "_".join(tokens)
        pubFilePath = uf.fix_path(os.path.join(pubFbxPath, pubFileName))

        # if this exists, should we overwrite?
        if os.path.isfile(pubFilePath):
            overwrite = cmds.confirmDialog(
                title="Overwrite Confirmation",
                message=
                "A publish FBX already exists for this file.\nShould we overwrite?",
                button=("Overwrite", "Cancel"),
                defaultButton="Overwrite",
                cancelButton="Cancel",
                dismissString="Cancel")

            if overwrite == "Cancel":
                print "Publish skipped for FBX file (.fbx) called {0}".format(
                    pubFilePath)
                return (True)

        # else:
        print "===== anim publish:\n- saving {0}".format(pubFilePath + ".mb")
        cmds.file(pubFilePath + ".mb", es=True, f=True, type="mayaBinary")

    return (True)
Пример #27
0
def publish_fbx_anim_file(versionUp=True, origScene=None, *args):
    # THIS IS FOR ANIM EXPORTING

    # save current scene
    # move this to end and use Zed's script to version up afterwards? ? maybe?
    # version up
    if versionUp:
        verUpFile = get_version_up_name(origScene)
        copy2(origScene, verUpFile)
        print "===== Versioned up {0} to {1}!".format(origScene, verUpFile)
    else:
        print "===== Not versioning up publish of {0}".format(origScene)

    if not origScene:
        cmds.warning(
            "assetPublish.publish_fbx_anim_file: You haven't passed in a scene path!"
        )
        return (False)

# assuming references
    refs = cmds.file(q=True, r=True)
    if not refs:
        cmds.warning("There are no references in this scene. . .")
        return (False)
    if len(refs) > 1:
        cmds.warning("There are too many references in this scene. . .")
        return (False)


# below would all be under a for loop for each reference in the stages?
    pp = uf.PathParser(origScene)

    # assuming a namespace
    geoGrp = cmds.ls("*:GEO")
    jntGrp = cmds.ls("*:EXPORT_JNT_Grp")

    # check for geo grps
    if not geoGrp or len(geoGrp) > 1:
        cmds.warning(
            "AssetPublish.publish_fbx_anim_file:You either have no grp called 'GEO' -IN A NAMESPACE-, or too many objects called 'GEO'.\n fbx export aborted!"
        )
        return (False)
    geos = child_match_check(geoGrp[0], "*_Geo_Grp")
    if not geos:
        return (False)

    # check for jnt grps
    if not jntGrp or len(jntGrp) > 1:
        cmds.warning(
            "AssetPublish.publish_fbx_anim_file:You either have no grp called 'EXPORT_JNT_Grp' -IN A NAMESPACE-, or too many objects called 'EXPORT_JNT_Grp'.\n fbx export aborted!"
        )
        return (False)
    roots = child_match_check(jntGrp[0], "*_Root_Jnt")
    if not roots:
        return (False)

    cmds.file(refs[0], ir=True)

    # check correspondence of geo and root jnts
    correspond = check_correspondence(geos, roots)
    if not correspond:
        return (False)

    pubFbxPath = uf.fix_path(os.path.join(pp.phasePath, "Publish/FBX/"))
    tokens = pp.fileName.split("_")
    tokens[-2] = "Publish"
    pubFileName = "_".join(tokens)[:-3] + ".fbx"
    pubFilePath = uf.fix_path(os.path.join(pubFbxPath, pubFileName))

    start, end = uf.get_frame_range()

    # bake joints
    for r in roots:
        # get child roots if joints
        allD = cmds.listRelatives(r, allDescendents=True)
        jnts = [x for x in allD if cmds.objectType(x, isa="joint")]
        # function to bake selected on all jnts under this root
        bake_selected(jnts, start, end)

    namespace = cmds.file(refs[0], q=True, ns=True)
    uf.remove_namespaces()

    # delete constraints
    cmds.delete(cmds.ls(type="constraint"))
    cmds.select(cl=True)
    # move jnts and geo into world parent
    for root in roots:
        rootremove = "{0}:".format(namespace)
        basename = root.split(":")[1].split("_Root_Jnt")[0]
        geo = "{0}_Geo_Grp".format(basename)
        root = "{0}_Root_Jnt".format(basename)
        cmds.parent([geo, root], w=True)
        tokens[-2] = basename
        pubFileName = "_".join(tokens)[:-3] + ".fbx"
        pubFilePath = uf.fix_path(os.path.join(pubFbxPath, pubFileName))
        rootremove = "{0}:".format(namespace)
        cmds.select([root, geo], r=True)

        # if this exists, should we overwrite?
        if os.path.isfile(pubFilePath):
            overwrite = cmds.confirmDialog(
                title="Overwrite Confirmation",
                message=
                "A publish FBX already exists for this file.\nShould we overwrite?",
                button=("Overwrite", "Cancel"),
                defaultButton="Overwrite",
                cancelButton="Cancel",
                dismissString="Cancel")

            if overwrite == "Cancel":
                print "Publish skipped for FBX file (.fbx) called {0}".format(
                    pubFilePath)
                return (True)

        mel.eval('FBXLoadExportPresetFile -f "{0}";'.format(anmPreset))
        mel.eval('FBXExport -f "{0}" -s'.format(pubFilePath))

    return (True)