def save_as_new(selectionBased=False, *args): proj = ai.AssetInfo() # construct the paths filePath = None selTab = cmds.tabLayout(widgets["assetsTab"], q=True, st=True) if selTab != "STGS": tab, phase, assetPath, assetFiles = get_asset_info(proj) else: tab, phase, assetPath, assetFiles = get_stage_info(proj) selItem = None if cmds.textScrollList(widgets["filesTSL"], q=True, sii=True): selIndex = cmds.textScrollList(widgets["filesTSL"], q=True, sii=True)[0] selItem = cmds.textScrollList(widgets["filesTSL"], q=True, si=True)[0] if not selItem or selItem == "No Files": if tab == "CHARS": asset = cmds.textScrollList(widgets["charTSL"], q=True, si=True)[0] if tab == "PROPS": asset = cmds.textScrollList(widgets["propTSL"], q=True, si=True)[0] if tab == "SETS": asset = cmds.textScrollList(widgets["setTSL"], q=True, si=True)[0] if tab == "STGS": asset = cmds.textScrollList(widgets["stageTSL"], q=True, si=True)[0] filename = "{0}_main_{1}_Work_v0001.mb".format(asset, phase) filePath = uf.fix_path(os.path.join(assetPath, filename)) # or use the path from selections else: filePath = uf.fix_path(os.path.join(assetPath, assetFiles[selIndex - 1])) savenewdata = snw.SaveNewAssetUI(filePath, selectionBased)
def gather_info(self, *args): """ gets the info from the UI we'll need to create/edit the refs """ if self.state == "default": state = False if self.state == "changed": state = True if self.compatible: self.versionNum = cmds.optionMenu(self.verOM, q=True, value=True) # THIS PART IS WRONG - IN SOME CASES i NEED THE ORIG REF, MAYBE AND THE NEW INFORMATION - SHOULD I USE THE RFN NODE TO DO THIS? variant = cmds.optionMenu(self.variantOM, q=True, value=True) name = "{0}_{1}_{2}_{3}_v{4}".format(self.pathParse.name, variant, self.pathParse.phase, self.pathParse.stage, self.versionNum) if fnmatch.fnmatch(self.ref, "*{*}"): brackets = "{" + self.ref.partition("{")[2] path = uf.fix_path(self.pathParse.stagePath + "/" + name + ".mb" + brackets) else: path = uf.fix_path(self.pathParse.stagePath + "/" + name + ".mb") return (path, self.state, self.namespace, self.killState, self.loadState) else: # not compatible return (self.ref, self.state, self.namespace, self.killState, self.loadState)
def get_asset_path_lists(self, *args): """ find the lists of assets in the folders, also gets the stage list """ self.charsPaths = sorted([ uf.fix_path(os.path.join(self.charPath, y)) for y in os.listdir(self.charPath) ], key=str.upper) self.propsPaths = sorted([ uf.fix_path(os.path.join(self.propPath, y)) for y in os.listdir(self.propPath) ], key=str.upper) self.setsPaths = sorted([ uf.fix_path(os.path.join(self.setPath, y)) for y in os.listdir(self.setPath) ], key=str.upper) self.stagesPaths = sorted([ uf.fix_path(os.path.join(self.stagePath, y)) for y in os.listdir(self.stagePath) ], key=str.upper) # clean for lst in [ self.charsPaths, self.propsPaths, self.setsPaths, self.stagesPaths ]: for x in lst: if not os.path.isdir(x): lst.remove(x)
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)
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)
def set_and_export(filepath): pathField = None fileField = None filepath = uf.fix_path(filepath) path = "/".join(filepath.split("/")[:-1]) file = os.path.basename(filepath).split(".")[0] # open the exporter mel.eval("gameFbxExporter;") # get the exporter nodes (I'm still not sure which one, so we'll use the last later) nodes = mel.eval("gameExp_GetGameFbxExporterNodeList()") # preset = "X:/Production/Code/Maya/Tools/PipelineTools/Python/Publishing/assetAnimGameExpPreset.mel" # can we get the whole frame range? # set it to the correct tab tab = "gameExporterWindow|gameExporterTabFormLayout|gameExporterTabLayout" cmds.tabLayout(tab, e=True, st="gameExporterAnimationTab") # assign preset (on the last node?) # hold = mel.eval('gameExp_ApplyPresetOnNode("{0}", "{1}");'.format(nodes[-1], preset)) # find the text fields for ctrl in cmds.lsUI(ctl=True, l=True): if ctrl.startswith("gameExporterWindow") and ctrl.split("|")[-1]=="anim_gameExporterExportFilename": fileField = ctrl if ctrl.startswith("gameExporterWindow") and ctrl.split("|")[-1]=="anim_gameExporterExportPath": pathField = ctrl mel.eval('gameExp_BrowseFolder')
def __init__(self): if "MAYA_PROJECT_PATH" in os.environ: self.basePath = os.environ["MAYA_PROJECT_PATH"] else: # self.basePath = "X:/Production" cmds.warning( "assetInfo.__init__: couldn't find the MAYA_PROJECT_PATH environment variable. See a TD!" ) self.charPath = uf.fix_path( os.path.join(self.basePath, "Assets/3D/Character/")) self.propPath = uf.fix_path( os.path.join(self.basePath, "Assets/3D/Props/")) self.setPath = uf.fix_path( os.path.join(self.basePath, "Assets/3D/Sets/")) self.stagePath = uf.fix_path(os.path.join(self.basePath, "Stages/")) self.get_asset_path_lists()
def gather_info(self, *args): """ gets the info from the UI we'll need to create/edit the refs """ if self.state == "default": state = False if self.state == "changed": state = True if self.compatible: self.versionNum = cmds.optionMenu(self.verOM, q=True, value=True) if fnmatch.fnmatch(self.ref, "*{*}"): brackets = "{" + self.ref.partition("{")[2] # deal with the fact that the {} might contain an arbitrary amount of digits!!!! path = uf.fix_path(self.pathParse.pathNoNum + self.versionNum + ".mb" + brackets) else: path = uf.fix_path(self.pathParse.pathNoNum + self.versionNum + ".mb") return(path, self.state, self.namespace, self.killState, self.loadState) else: # not compatible return(self.ref, self.state, self.namespace, self.killState, self.loadState)
def get_stage_contents(self, stagepath, *args): exclude = ["0.txt", "edits"] self.stageAnmPath = uf.fix_path( os.path.join(stagepath, "Animation/Production/Maya/scenes")) # self.stageAudPath = os.path.join(stagepath, "Audio/Production/Maya/scenes") # self.stageFxPath = os.path.join(stagepath, "FX/Production/Maya/scenes") # self.stageLgtPath = os.path.join(stagepath, "Lighting/Production/Maya/scenes") # self.stageTrkPath = os.path.join(stagepath, "Tracking/Production/Maya/scenes") stageAnmWorkFiles = [ f for f in os.listdir(self.stageAnmPath) if (os.path.isfile(os.path.join(self.stageAnmPath, f)) and f not in exclude) ] self.stageAnmWorkFiles = sorted(stageAnmWorkFiles)
def create_new_ref(*args): """ creates a new reference obj in the UI """ # get selected asset, parse whether there are files in that particular phase tab, phase, assetPath, assetFiles = [None, None, None, None] tab, phase, assetPath, assetFiles = get_asset_info() if not assetFiles: cmds.warning("There are no published files for that asset") return() filePath = uf.fix_path(os.path.join(assetPath, assetFiles[-1])) # create the namespace from the file path ns = create_namespace(filePath) # create the ref object y = ReferenceObject(ns, filePath, False, "pending") namespaceList.append(ns)
def run(path=None, *args, **kwargs): #required scenes folder folder = pg.filefolder path = uf.fix_path(path) if path: # print path #derive new workspace from selected file path if "%s/" % folder in path: workspace = path.split(folder)[0] else: workspace = "/".join(path.split("/")[:-2]) #try to list subdirectories subDir = [] try: subDir = os.listdir(workspace) except: mc.warning("%s is not valid file directory" % workspace) #check if file is in project directory if folder not in subDir: mc.confirmDialog( m= "Selected File Not In Project Directory. Please Save Version Into Project Directory.", b="Ok") else: #open selected file print "SETTING PROJECT: %s" % workspace mel.eval('setProject "{0}";'.format(workspace)) #mc.workspace(workspace, o=1) mc.workspace(dir=workspace) #open the file if it exists if mc.file(path, q=1, ex=1): mc.file(path, o=1, f=1, iv=1) #setAutoSave() else: print "%s doesn't exist." % path else: pass """
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)
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)
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): # 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)
def get_asset_contents(self, assetpath, *args): """ get asset file contents for each area Args: assetpath (string) - the path to the top level of the asset folder ("X://.../Production/Assets/3D/Character/Fish") """ exclude = ["0.txt", "edits", "incremental", "_old"] self.anmPath = uf.fix_path( os.path.join(assetpath, "Animation/Work/Maya/scenes")) self.lgtPath = uf.fix_path( os.path.join(assetpath, "Lighting/Work/Maya/scenes")) self.mdlPath = uf.fix_path( os.path.join(assetpath, "Modeling/Work/Maya/scenes")) self.rigPath = uf.fix_path( os.path.join(assetpath, "Rigging/Work/Maya/scenes")) self.txtPath = uf.fix_path( os.path.join(assetpath, "Texturing/Work/Maya/scenes")) self.anmPubPath = uf.fix_path( os.path.join(assetpath, "Animation/Publish/MB/")) self.lgtPubPath = uf.fix_path( os.path.join(assetpath, "Lighting/Publish/MB/")) self.mdlPubPath = uf.fix_path( os.path.join(assetpath, "Modeling/Publish/MB/")) self.rigPubPath = uf.fix_path( os.path.join(assetpath, "Rigging/Publish/MB/")) self.txtPubPath = uf.fix_path( os.path.join(assetpath, "Texturing/Publish/MB/")) self.anmWorkFiles = [ f for f in os.listdir(self.anmPath) if (os.path.isfile(os.path.join(self.anmPath, f)) and f not in exclude) ] self.lgtWorkFiles = [ f for f in os.listdir(self.lgtPath) if (os.path.isfile(os.path.join(self.lgtPath, f)) and f not in exclude) ] self.mdlWorkFiles = [ f for f in os.listdir(self.mdlPath) if (os.path.isfile(os.path.join(self.mdlPath, f)) and f not in exclude) ] self.rigWorkFiles = [ f for f in os.listdir(self.rigPath) if (os.path.isfile(os.path.join(self.rigPath, f)) and f not in exclude) ] self.txtWorkFiles = [ f for f in os.listdir(self.txtPath) if (os.path.isfile(os.path.join(self.txtPath, f)) and f not in exclude) ] self.anmPubFiles = [ f for f in os.listdir(self.anmPubPath) if f not in exclude ] # self.lgtPubFiles = [f for f in os.listdir(self.lgtPubPath) if (os.path.isfile(os.path.join(self.lgtPubPath, f)) and f not in exclude)] self.mdlPubFiles = [ f for f in os.listdir(self.mdlPubPath) if f not in exclude ] self.rigPubFiles = [ f for f in os.listdir(self.rigPubPath) if f not in exclude ]
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)
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)
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)