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 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) # 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 () 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 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)