def mmConvAndExportAllAnimsSequential_3(mmExportedPathsList=[], *args): #--------------------------------------------- #This re-loads the rig, and informs the user that the script has finished its work. mmExportedPaths = "" mmRigFilepathAndFilename = mmExportedPathsList[0][2] #Get the filepath mmMainFilepath = mmRFOF.main(str(mmRigFilepathAndFilename), 0) #print "mmMainFilepath", mmMainFilepath #Get the file name mmMainFilename = mmRFOF.main(str(mmRigFilepathAndFilename), 1) #print "mmMainFilepath", mmMainFilepath mmExportedPaths = "rig: " + mmMainFilename + "\n" print "mmExportedPathsList", mmExportedPathsList for mmList in mmExportedPathsList: mmAnimName = mmList[0] mmAnimFilePath = mmList[1] mmExportedPaths = mmExportedPaths + "anim: " + mmAnimName + "\n" #Open the file cmds.file(mmRigFilepathAndFilename, open=1) #--------------------------------------------- #display to the user that their export is complete, and what was exported. cmds.confirmDialog(title='Export Complete', message='File(s) Exported:\n' + mmExportedPaths + '\nFilepath exported to:\n' + mmMainFilepath + "animations/", button=['OK'], defaultButton='OK')
def main( mmRigFilepathAndFilename = None, mmOldAnimFilePath = None, *args): ############ #There is a huge problem here - if the export window has its properties changed outside this script, this script doesn't reset those changes. # This causes the script to fail. To fix, you need to go into the Atom Export window in Maya, and reset the tool so it exports animations based on the timeline. ############ #Verify if a rig was passed in mmPassedRig = False if ( mmRigFilepathAndFilename != None and mmOldAnimFilePath != None ): mmPassedRig = True # print "" # print "Start of mmTATDR" # print "mmRigFilepathAndFilename", mmRigFilepathAndFilename # print "type( mmRigFilepathAndFilename )", type( mmRigFilepathAndFilename ) # print "mmOldAnimFilePath", mmOldAnimFilePath # print "type( mmOldAnimFilePath )", type( mmOldAnimFilePath ) # print "" #--------------------------------------------- mmCM2M.mmFixUI() #Cycle the Atom Export window just to make sure it is alive and working mel.eval( "ExportAnimOptions;" ) mel.eval( "performExportAnim 1;" ) mel.eval( "hideOptionBox;" ) #Select everything we want to have selected selectionList = [] selectionList = mmSAP.main(["mesh", "nurbsCurve"]) #Copy selectionList just in case originalSelectionList = list(selectionList) #--------------------------------------------- #Next we need to copy the animations from the original Rig onto the new Replacement Rig #--------------------------------------------- #Don't want to create a template here, just want to use the existing one from the Rig export # A template must exist already for this rig to be used in our game. # (it is part of rig creation) #--------------------------------------------- #if the rig is not passed in, then ask where to do the work. if ( mmPassedRig == False ): #--------------------------------------------- #Don't need to ask the user what the name should be - we have the name because we can grab it from the file we are on. mmATOMFilepathAndFilename = cmds.file(q = 1, loc = 1) #Grab just the file name mmExportImportFilename = mmRFOF.main( mmATOMFilepathAndFilename , 1 ) #--------------------------------------------- #Need info for grabbing a rig #Ask the user what Rig should be referenced in and have animation applied to. mmStartingDirectory = "C:/Radiant/stonehearth-assets/assets/models" mmDialogueCaption = "Please select the Rig to Reference in and apply animation to." mmRigNamespace = "ReferencedAnimRig_Male" #Open a dialogue box where user can input information mmRigFilepathAndFilename = cmds.fileDialog2( cap = mmDialogueCaption, fm = 1, fileFilter = 'MA (*.ma)', selectFileFilter = 'MA (*.ma)', dir = mmStartingDirectory ) #print "mmRigFilename " #print mmRigFilename mmSavedDirectory = mmRFOF.main( mmRigFilepathAndFilename, 0 ) mmSavedFilename = mmRFOF.main( mmRigFilepathAndFilename, 1 ) #--------------------------------------------- #Create a filepath for the atom export mmATOMFilepathAndFilename = mmSavedDirectory else: #if the rig is passed in, then don't ask about where to do anything. #create names to use later mmOldAnimSavedDirectory = mmRFOF.main( mmOldAnimFilePath, 0 ) mmOldAnimSavedFilename = mmRFOF.main( mmOldAnimFilePath, 1 ) #create names to use later mmNewRigSavedDirectory = mmRFOF.main( mmRigFilepathAndFilename, 0 ) mmNewRigSavedFilename = mmRFOF.main( mmRigFilepathAndFilename, 1 ) # #Else: use the passed in information # mmSavedDirectory = mmRFOF.main( mmRigFilepathAndFilename, 0 ) # mmRigNamespace = mmRFOF.main( mmRigFilepathAndFilename, 1 ) mmExportImportFilename = mmOldAnimSavedFilename #Tailor make a filepath and name to export an animation mmATOMFilepathAndFilename = mmNewRigSavedDirectory # print "mmNewRigSavedDirectory", mmNewRigSavedDirectory # print "type( mmNewRigSavedDirectory )", type( mmNewRigSavedDirectory ) #--------------------------------------------- #Need info for grabbing a rig mmSavedDirectory = mmNewRigSavedDirectory mmSavedFilename = mmNewRigSavedFilename #--------------------------------------------- #Either way, ensure there is an "atom_exports" folder, and composite a proper filepath & name for the atom export mmNameChecker = True for item in os.listdir( mmATOMFilepathAndFilename ): if ( item == "atom_exports" ): mmNameChecker == False if ( mmNameChecker ): cmds.sysFile( mmSavedDirectory + "atom_exports/", makeDir=True ) mmATOMFilepathAndFilename = mmATOMFilepathAndFilename + "atom_exports/" + mmExportImportFilename + ".atom" #--------------------------------------------- #Export animation to specified file. mmMelExportAtomLine = 'doExportAtom(1,{ "' + mmATOMFilepathAndFilename + '" });' mel.eval(mmMelExportAtomLine) #Removing this line, as it was messing everything up in the other anim. #mel.eval('fileCmdCallback;') #--------------------------------------------- #Next import the new Referenced Rig cmds.file( mmRigFilepathAndFilename, r = 1, type = "mayaAscii", ignoreVersion = 1, gl = 1, mergeNamespacesOnClash = False, namespace = mmSavedFilename, options = "v=0;" ) #--------------------------------------------- #Then remove the old referenced rig #Grab the first thing we selected before and grab its reference name. #We can assume this will always work because all files MUST be referenced in our game # (from this point onward) mmPrefixRemoved = originalSelectionList[0].split(':')[0] #Create name of referenced node mmReferencedNode = mmPrefixRemoved + 'RN' #Remove the referenced file cmds.file( referenceNode = mmReferencedNode, removeReference = 1 ) #The scene should now be empty. #--------------------------------------------- #Check if a folder called "animations" exists for the future folder structure mmNewRigAnimFolderCheck = cmds.file( mmSavedDirectory + "animations/", q = 1, ex = 1 ) # print "mmNewRigAnimFolderCheck", mmNewRigAnimFolderCheck #If there isn't an animations folder for the new rig, need to make one if ( mmNewRigAnimFolderCheck == False ): cmds.sysFile( mmNewRigSavedDirectory + "animations/", makeDir=True ) #--------------------------------------------- #Need to modify the original slection list so that it looks like what I am looking for #Not sure if this step is needed, I think I actually need to get the ATOM importer # to do this for me. - Nah, its ok that i do it here. #create empty list mmModifiedSelectionList = [] # print "originalSelectionList", originalSelectionList for mmOldName in originalSelectionList: # print "mmOldName", mmOldName #Split out the old namespace and attach the new one mmStoredBoneName = mmOldName.split( ':' )[1] #Add new namespace to the front mmNewBoneName = mmSavedFilename + ':' + mmStoredBoneName if cmds.objExists ( mmNewBoneName ): mmModifiedSelectionList.append( mmNewBoneName ) cmds.select( mmNewBoneName, add = 1 ) #Copy the list just in case mmOriginalBones = list(mmModifiedSelectionList) #--------------------------------------------- #--------------------------------------------- #Cycle the import window to make sure it is capable of running stuff. mel.eval("ImportAnimOptions;") mel.eval("performImportAnim 1;") mmSearchName = mmPrefixRemoved mmReplaceName = mmSavedFilename mmImportAnimFilePath = [mmATOMFilepathAndFilename] mmNameSpace = mmExportImportFilename # print "mmSearchName", mmSearchName # print "mmReplaceName", mmReplaceName # print "mmImportAnimFilePath", mmImportAnimFilePath # print "mmNameSpace", mmNameSpace mmCompiledOptionsForImportAnimations = ";;targetTime=3;option=insert;match=string;;selected=selectedOnly;search=" + mmSearchName + ";replace=" + mmReplaceName + ";prefix=;suffix=;mapFile=C:/Users/mmalley/Documents/maya/projects/default/data/;" #Importing animations onto new Rig cmds.file( mmImportAnimFilePath, i = 1, type = "atomImport", ra = True, namespace = mmNameSpace, options = mmCompiledOptionsForImportAnimations ) #print "File Command: " + mmImportAnimFilePath + ", i = 1, type = 'atomImport', ra = True, namespace = " + mmNameSpace + ", options = " + mmCompiledOptionsForImportAnimations #mel.eval("fileCmdCallback;") # Removing this because it caused problems in other areas. #--------------------------------------------- #Need to save out the file as .MA #Just place it in the "Animations" folder under where the rig was saved out. mmNewAnimFilenameAndFilepath = mmSavedDirectory + "animations/" + mmExportImportFilename + ".ma" cmds.file( rename = mmNewAnimFilenameAndFilepath ) cmds.file( force = 1, save = 1, type = 'mayaAscii' ) #--------------------------------------------- if ( mmPassedRig == False ): #Export an animation as well mmEAAJ.main() else: #Export an animation as well mmEAAJ.main(False)
def main(mmRigFilepathAndFilename=None, mmAnimFilePath=None, *args): mmPassedRig = False if (mmRigFilepathAndFilename != None and mmAnimFilePath != None): mmPassedRig = True mmCM2M.mmFixUI() #Cycle the Atom Export window just to make sure it is alive and working mel.eval("ExportAnimOptions;") mel.eval("performExportAnim 1;") mel.eval("hideOptionBox;") #Grab everything that should be selected selectionList = [] selectionList = mmSAP.main() #print "selectionList", selectionList #create lists for use later mmOriginalBones = list(selectionList) mmProperBoneName = [] mmProperBoneList = [] mmCopyLocList = [] mmModifiedNames = [] mmTransferFromMaxBool = True mmSearchingSuffix = "_Control" mmTempLocSuffix = "_TransferLoc" #Clear out duplicates & then sort #Just converting the list to a "set" and back to a "list" causes all duplicates to be removed. mmOriginalBones = list(set(mmOriginalBones)) mmOriginalBones.sort() #First need to ensure the scale of the animation is 1 so transfer works properly objectName = 'root' if objectName in mmOriginalBones: #clear selection cmds.select(cl=1) #select only the root cmds.select(objectName) #Scale down the selected value #This is an assumption - may want to have a check before running this. mmScaleDownFrom3DSMax.main(objectName) #Find out total number of frames #Store the original time before running the script mmOriginalTime = cmds.currentTime(query=True) #Find First Frame of Timeline mmFirstFrame = cmds.playbackOptions(minTime=1, query=True) #Find Last Frame of Timeline mmLastFrame = cmds.playbackOptions(maxTime=1, query=True) #mmLastFrame -= 1 #Find Total Frames mmTotalFrames = mmLastFrame - mmFirstFrame #Set animation to first frame mmCurrentTime = cmds.currentTime(mmFirstFrame, update=False) #Need to parent constrain a locator to every bone.. then pull animation out of these attached locators. # This is because the axis are expected to be rotated 90 degrees in X #--------------------------------------------- ###################################### #Think I need to import the new rig now so I can use it for the Transfer_Loc rig creation ###################################### #if the rig is passed in, then don't ask about where to do anything if (mmPassedRig == False): #--------------------------------------------- #Ask the user what Rig should be referenced in and have animation applied to. #--------------------------------------------- mmStartingDirectory = "C:/Radiant/stonehearth-assets/assets/models/entities/" mmDialogueCaption = "Please select the Rig to Reference in and apply animation to." mmRigNamespace = "ReferencedAnimRig_Male" #Open a dialogue box where user can input information mmRigFilename = cmds.fileDialog2(cap=mmDialogueCaption, fm=1, fileFilter='MA (*.ma)', selectFileFilter='MA (*.ma)', dir=mmStartingDirectory) #print mmRigFilename mmSavedDirectory = mmRFOF.main(mmRigFilename, 0) #print mmSavedDirectory mmRigNamespace = mmRFOF.main(mmRigFilename, 1) #And then import those animations onto the Referenced Rig #Need to import Referenced Rig #Original Mel: #file -r -type "mayaAscii" -ignoreVersion -gl -mergeNamespacesOnClash false -namespace "ReferencedAnimRig_Male" -options "v=0;" "C:/Radiant/stonehearth-assets/assets/models/entities/humans/male/ReferencedAnimRig_Male.ma"; cmds.file(mmRigFilename, r=1, type="mayaAscii", ignoreVersion=1, gl=1, mergeNamespacesOnClash=False, namespace=mmRigNamespace, options="v=0;") #--------------------------------------------- else: #use the passed in information # mmAnimFilePath # mmRigFilepathAndFilename #Else: use the passed in information mmSavedDirectory = mmRFOF.main(mmRigFilepathAndFilename, 0) mmRigNamespace = mmRFOF.main(mmRigFilepathAndFilename, 1) #Need to import Referenced Rig #Original Mel: #file -r -type "mayaAscii" -ignoreVersion -gl -mergeNamespacesOnClash false -namespace "ReferencedAnimRig_Male" -options "v=0;" "C:/Radiant/stonehearth-assets/assets/models/entities/humans/male/ReferencedAnimRig_Male.ma"; cmds.file(mmRigFilepathAndFilename, r=1, type="mayaAscii", ignoreVersion=1, gl=1, mergeNamespacesOnClash=False, namespace=mmRigNamespace, options="v=0;") #Need to save bones and parents mmNewRigStoreArray = [] mmCounterA = 0 #Select all of the original selection bones for objectCounter in mmOriginalBones: #print "objectCounter", objectCounter #While we are here, lets check to see if there are non suffix items. #We don't know if this is an animation from 3dsmax where the suffixs do not exist, or one from Maya where they do. #If this is TRUE, then it means we have Controls in the scene, and we should be transfering from THEM instead of geo, #And we save the names for later to replace the original bones names. ##################################### #? I dont think this will pick up referenced assets - it isn't searching for names with ":" in front. # Maybe we should be checking for both referenced and not? or.. not really, non-referenced controls shouldn't happen. # Some confusion here - does this script need to transfer between a 3dsmax anim and the maya rig, or also from two maya rigs? # The difference is whether or not the anim which is being transfered is coming from a referenced rig or not. ##################################### #? There is another issue where someone (me) screws up and animates on a rig in maya which is not referenced. # Its happened twice so far, I should probably account for it. ##################################### mmNameChecker = objectCounter.split(":") if (len(mmNameChecker) > 1): #Then this should mean I have a referenced rig which I am pulling from. mmProperBoneName = mmNameChecker[1].split("_") #mmSearchingSuffix is up above just incase I need to change it at some point (without digging through the code to find this line). #Here we are comparing the mmSearchingSuffix with the mmProperBoneName[1] and verifying that we have a control selected. mmTempSuffix = mmSearchingSuffix.split("_")[1] if (len(mmProperBoneName) > 1 and mmProperBoneName[1] == mmTempSuffix): #If everything checks out, we save the bone name in a list mmProperBoneList.append(mmProperBoneName[0]) mmTransferFromMaxBool = False else: #This means I am pulling from either a 3dsmax transfered rig, or a maya rig which is not referenced. #? The later I do not believe we account for, # though it is possible we converted it over at some point and didn't maintain the original purpose :(. #Each new bone is given an array to store its name and its parent. mmNewBoneStoreArray = [] #Store the name of the bone into the array, as well as its parent. objectCounterNewName = objectCounter + mmTempLocSuffix mmNewBoneStoreArray.append(objectCounterNewName) objectParent = cmds.listRelatives(objectCounter, p=1) #Also create the names of the bones which the rig will have. mmModifiedName = mmRigNamespace + ":" + objectCounter + mmSearchingSuffix mmModifiedNames.append(mmModifiedName) # print "mmModifiedNames[mmCounterA]", mmModifiedNames[mmCounterA] if (objectParent != None): objectParent[0] += mmTempLocSuffix mmNewBoneStoreArray.append(objectParent[0]) else: mmNewBoneStoreArray.append(None) mmNewRigStoreArray.append(mmNewBoneStoreArray) # print "mmNewBoneStoreArray", mmNewBoneStoreArray mmCounterA += 1 mmTransferFromMaxBool = True mmRootBone = "" mmRootTempLoc = "" if (mmTransferFromMaxBool): mmCounterB = 0 for objectCounter in mmOriginalBones: #Create a locator and parent it to the correct bone so it mimics the movement of its parent, then transfer that animation over. #?This assumes that my rig is clean - but my rigs are NOT clean, I know this. So instead, I need a way to create these locators, # then pin them in place where they SHOULD be, then move them to where they ARE, THEN transfer the animation. mmTempLoc = cmds.spaceLocator(n=objectCounter + mmTempLocSuffix)[0] #################################### #################################### #This is where I need to constrain to the rig, freeze transforms, then re-constrain to the original meshes (and do not freeze transforms). #Hopefully this gets us to the correct location, and proper animation after that. NOPE #################################### #################################### mmTempPC1 = cmds.pointConstraint(mmModifiedNames[mmCounterB], mmTempLoc, mo=0) cmds.delete(mmTempPC1) cmds.select(mmTempLoc) mmCopyLocList.append(mmTempLoc) #This may not be needed if the root temploc is set to world space # if (objectCounter == "root"): # mmRootBone = objectCounter # mmRootTempLoc = mmModifiedNames[mmCounterB] mmCounterB += 1 #Clear out duplicates & Sort #Just converting the list to a "set" and back to a "list" causes all duplicates to be removed. if (mmTransferFromMaxBool == False): mmProperBoneList = list(set(mmProperBoneList)) mmProperBoneList.sort() if (mmTransferFromMaxBool == True): mmCopyLocList = list(set(mmCopyLocList)) mmCopyLocList.sort() mmModifiedNames = list(set(mmModifiedNames)) mmModifiedNames.sort() #Think this only applies if its a 3dsmax rig - not sure. for rigStoredArray in mmNewRigStoreArray: if (rigStoredArray[1] != None): cmds.parent(rigStoredArray[0], rigStoredArray[1]) if (rigStoredArray[0] != "root" + mmTempLocSuffix): cmds.select(rigStoredArray[0]) cmds.makeIdentity(apply=True, t=1, r=1, s=1, n=0, pn=1) #Next need to move the templocs to where they should be in space #################################### #I'm sure this is horrible, because they are parented, and now we are not maintaining offset constrainting them : / # Seems to work regardless - I should check. #################################### #This is actually horrible because this is assuming that mmCopyLocList exists, but if it is not a 3dsmax rig, then it wont. This script is half unfinished. # Think I started combining this and 'mmTransferAnimToDifferentRig' #################################### #FIRST: the root must line up mmCounterC = 0 while mmCounterC < len(mmOriginalBones): #Padding it wont help : ( #mmLocPad = mmOF.mmGroupInPlace( mmCopyLocList[mmCounterC] ) print "mmOriginalBones[mmCounterC]", mmOriginalBones[mmCounterC] print "mmCopyLocList[mmCounterC]", mmCopyLocList[mmCounterC] mmTempPC2 = cmds.parentConstraint(mmOriginalBones[mmCounterC], mmCopyLocList[mmCounterC], mo=0) cmds.delete(mmTempPC2) #Must fix the rotation from Max somehow cmds.select(mmCopyLocList[mmCounterC]) #Arbitrary 90 degree rotation isn't benefical, just does wonky stuff. What is actually happening? cmds.rotate(90, 0, 0, r=1, os=1) #Try swapping Y and Z values (probably wont work, but trying it) #mmBoneRot = cmds.getAttr(mmOriginalBones[mmCounterC] + ".rotate") #print "mmBoneRot", mmBoneRot #cmds.rotate( mmBoneRot[0][0], -mmBoneRot[0][2], mmBoneRot[0][1], r =1 ) mmTempPC3 = cmds.parentConstraint(mmOriginalBones[mmCounterC], mmCopyLocList[mmCounterC], mo=1) mmCounterC += 1 #This selects all temp locs and export the animation. if (mmTransferFromMaxBool): cmds.select(cl=1) for mmTempLoc in mmCopyLocList: cmds.select(mmTempLoc, add=True) if (mmPassedRig == False): #--------------------------------------------- #Ask the user what location the ATOM Animation should be saved to. #--------------------------------------------- #Export animations as ATOM animations to a file location which the user specifies #mmExportImportFilename = "C:/Users/mmalley/Documents/Work/AnimationExports/idle_breathe/idle_breathe.atom" ##################### #Change this starting directory to be more generic once set up - probably in the Radiant folder ##################### mmStartingDirectory = "C:/Users/mmalley/Documents/Work/AnimationExports" mmDialogueCaption = "Please select a name and location for ATOM Animations." mmfileFilterName = 'ATOM' mmfileFilterType = '.atom' #Open a dialogue box where user can input information mmFullDirectoryPathFiletype = cmds.fileDialog2( cap=mmDialogueCaption, fm=0, fileFilter=mmfileFilterName + ' (*' + mmfileFilterType + ')', selectFileFilter=mmfileFilterName + ' (*' + mmfileFilterType + ')', dir=mmStartingDirectory) #print mmExportImportFilenameAndPath mmExportImportFilename = mmRFOF.main(mmFullDirectoryPathFiletype, 1) #print mmFullDirectoryPathFiletype #Export animation to specified file. mmMelExportAtomLine = 'doExportAtom(1,{ "' + mmFullDirectoryPathFiletype[ 0] + '" });' #print mmMelExportAtomLine mel.eval(mmMelExportAtomLine) mel.eval('fileCmdCallback;') else: mmExportImportFilename = mmRFOF.main(mmAnimFilePath, 1) mmFullDirectoryPathFiletype = mmSavedDirectory + mmExportImportFilename + ".atom" #Export animation to specified file. mmMelExportAtomLine = 'doExportAtom(1,{ "' + mmSavedDirectory + mmExportImportFilename + '" });' #print mmMelExportAtomLine mel.eval(mmMelExportAtomLine) mel.eval('fileCmdCallback;') #print "mmOriginalBones", mmOriginalBones #print "mmProperBoneList", mmProperBoneList #Next we need to copy the animations from the original Rig onto the new Replacement Rig ''' #Don't want to create a template here, just want to use the existing one from the Rig export #**Are templates even needed? Why not just overload onto 'trash' every time? #Python version of Atom Template Creator - saves it as the file name specified #mel.eval('atomTemplateCallback OptionBoxWindow|formLayout242|tabLayout37|formLayout244|tabLayout38|columnLayout172 1; hideOptionBox;') #Ask the user what location the Character Template should be saved to. mmStartingDirectory = "C:/Users/mmalley/Documents/Work/CharacterTemplates" mmDialogueCaption = "Please select a name and location for the Character Template." mmATOMOriginalName = "HumanMaleOriginal" #Open a dialogue box where user can input information mmTemplateFilename = cmds.fileDialog2( cap = mmDialogueCaption, fm = 0, fileFilter = 'Template (*.template)', selectFileFilter = 'template (*.template)', dir = mmStartingDirectory) print "mmTemplateFilename[0]", mmTemplateFilename[0] mmATOMOriginalName = mmRFOF.main( mmTemplateFilename , 1 ) print "mmATOMOriginalName", mmATOMOriginalName #Old, Doesn't work: cmds.containerTemplate( mmATOMOriginalName, force = 1, edit = 1, layoutMode = 1, addView = 0, fromSelection = 1, useHierarchy = 1, allKeyable = 1, save = 1, fileName = mmTemplateFilename[0] ) if (mmTemplateFilename[0]): #cmds.containerTemplate( "HumanMaleOriginal", force = 1, edit = 1, layoutMode = 1, addView = 0, fromSelection = 1, useHierarchy = 1, allKeyable = 1, save = 1, fileName = mmTemplateFilename[0] ) cmds.containerTemplate( mmATOMOriginalName, force = 1, fromSelection = 1, useHierarchy = 1, allKeyable = 1 ) cmds.containerTemplate( mmATOMOriginalName, save = 1, fileName = mmTemplateFilename[0] ) cmds.containerTemplate( mmATOMOriginalName, force = 1, edit = 1, layoutMode = 1, addView = 0, fromSelection = 1, useHierarchy = 1, allKeyable = 1 ) cmds.containerTemplate( mmATOMOriginalName, save = 1, fileName = mmTemplateFilename[0] ) ''' #--------------------------------------------- #remove the gathering of selectionList again #selectionList = cmds.ls(orderedSelection = True) #Clear selection cmds.select(cl=1) #Create counter and set to 0 mmCounterA = 0 #Check to see if there are any "mmProperBoneName"s in the mmProperBoneList #Take all the original bones and select the Suffix version of them within the Referenced Rig file for mmBone in mmOriginalBones: if (mmTransferFromMaxBool == True): # mmModifiedName = mmRigNamespace + ":" + mmBone + mmSearchingSuffix # mmModifiedNames.append(mmModifiedName) # print "mmModifiedNames[mmCounterA]", mmModifiedNames[mmCounterA] cmds.select(mmModifiedNames[mmCounterA], add=True) else: ################################### #This looks broken - unsure what this was even supposed to do.. why would I only want to select one bone? ################################### if (mmCounterA == 1): cmds.select(mmBone, add=True) mmCounterA += 1 mmSelectedNames = cmds.ls(sl=1) # print "mmSelectedNames - right before import: ", mmSelectedNames #***Forcing test, these lines are trash in the long run*** #mmExportImportFilename = "run" #mmRigNamespace = "ReferencedAnimRig_Male" #mmFullDirectoryPathFiletype = "C:/Users/mmalley/Documents/Work/AnimationExports/run.atom" #mmATOMOriginalName = "HumanMaleOriginal" if (mmTransferFromMaxBool == True): mmATOMImportPrefix = mmRigNamespace + ":" mmATOMImportSuffix = "" mmSearchName = mmTempLocSuffix mmReplaceName = mmSearchingSuffix else: mmATOMImportPrefix = mmRigNamespace + ":" mmATOMImportSuffix = "" mmSearchName = "" mmReplaceName = "" # print mmExportImportFilename # print mmRigNamespace # print mmFullDirectoryPathFiletype[0] # print mmATOMOriginalName # print "mmATOMImportPrefix", mmATOMImportPrefix # print "mmATOMImportSuffix", mmATOMImportSuffix ''' #not working #mmCompileMelCommandForImportAnimations = 'file -import -type "atomImport" -ra true -namespace "' + mmExportImportFilename + '" -options ";;targetTime=3;option=insert;match=string;;template=' + mmATOMOriginalName + ';;selected=template;view=0;search=;replace=;prefix=' + mmATOMImportPrefix + ';suffix=' + mmATOMImportSuffix + ';mapFile=C:/Users/mmalley/Documents/maya/projects/default/data/;" "' + mmFullDirectoryPathFiletype + '";' #removing template mmCompileMelCommandForImportAnimations = 'file -import -type "atomImport" -ra true -namespace "' + mmExportImportFilename + '" -options ";;targetTime=3;option=insert;match=string;;selected=selectedOnly;search=;replace=;prefix=' + mmATOMImportPrefix + ';suffix=' + mmATOMImportSuffix + ';mapFile=C:/Users/mmalley/Documents/maya/projects/default/data/;" "' + mmFullDirectoryPathFiletype[0] + '";' #print mmCompileMelCommandForImportAnimations #Importing animations onto new Locator Rig mel.eval(mmCompileMelCommandForImportAnimations) mel.eval("fileCmdCallback;") #mel.eval('file -import -type "atomImport" -ra true -namespace "run" -options ";;targetTime=3;option=insert;match=string;;template=HumanMaleOriginal;;selected=template;search=;replace=;prefix=ReferencedAnimRig_Male:;suffix=_loc;mapFile=C:/Users/mmalley/Documents/maya/projects/default/data/;" "C:/Users/mmalley/Documents/Work/AnimationExports/run.atom";') #Trying to find python equivalent, Failing #cmds.file( import = True, type = "atomImport", ra = True, namespace = "idle_breathe", options = ";;targetTime=3;option=insert;match=string;selected=template;suffix='_loc';mapFile=C:/Users/mmalley/Documents/maya/projects/default/data/;" "C:/Users/mmalley/Documents/Work/AnimationExports/idle_breathe/idle_breathe.atom") ''' #Copying from 'mmTransferAnimToDifferentRig' #Re-select the desired components # print "mmFullDirectoryPathFiletype", mmFullDirectoryPathFiletype #Should this be mmFullDirectoryPathFiletype[0]? - NOPE!?!?!! I dont know, it works now. mmImportAnimFilePath = mmFullDirectoryPathFiletype mmCompiledOptionsForImportAnimations = ";;targetTime=3;option=insert;match=string;;selected=selectedOnly;search=" + mmSearchName + ";replace=" + mmReplaceName + ";prefix=" + mmATOMImportPrefix + ";suffix=" + mmATOMImportSuffix + ";mapFile=C:/Users/mmalley/Documents/maya/projects/default/data/;" #Importing animations onto new Rig cmds.file(mmImportAnimFilePath, i=1, type="atomImport", ra=1, namespace="run", options=mmCompiledOptionsForImportAnimations) # Works, but I don't want to waste 5 seconds every time - and maybe I'll need to wait 10 seconds for some.. who knows? #time.sleep( 5 ) #input("Press Enter to continue...") #os.system("pause") #doesn't work because maya waits til the end of the function to call this import cmds.viewFit(all=True) #Can't do this, it creates an infinite loop. # while bob == bob: # cmds.pause( sec = 0.1 ) #--------------------------------------------- #Need to delete old 3dsmax Rig #Need to clear selection cmds.select(cl=1) #Take all the original bones and delete them - because we just brought in a replacement for objectCounter in mmOriginalBones: cmds.select(objectCounter, add=True) #Check for Parent Pads as well mmAreThereParents = cmds.listRelatives(objectCounter, p=1) if (mmAreThereParents): cmds.select(mmAreThereParents[0], add=True) cmds.delete() #Also need to delete the created temp locator rig for mmTempLoc in mmNewRigStoreArray: cmds.select(mmTempLoc[0], add=True) cmds.delete() #--------------------------------------------- #Clean Up #Reset time to original frame cmds.currentTime(mmOriginalTime) #--------------------------------------------- #Don't want to save out the file right now #Need to save out the file as .MA #Just place it in the "Animations" folder under where the rig was saved out. mmNewAnimFilenameAndFilepath = mmSavedDirectory + "animations/" + mmExportImportFilename + ".ma" cmds.file(rename=mmNewAnimFilenameAndFilepath) cmds.file(force=1, save=1, type='mayaAscii') #--------------------------------------------- #Export an animation as well mmEAAJ.main(True)
def mmExportAllAnimsSequential_1(*args): #First the user must manually transfer all the animations for the particular rig # from max to maya and save them in a folder called "max_animconversions" - mmSaveFileAs should help them do this. #Disable the viewport # Translation into python is easy, how to figure out the name of the panelayout is not #mel.eval("paneLayout -e -manage false $gMainPane") #cmds.refresh(suspend=True) #Works! #Find out the current file name mmRigFilepathAndFilename = cmds.file(q=1, loc=1) #print "mmRigFilepathAndFilename", mmRigFilepathAndFilename #Get the filepath mmMainFilepath = mmRFOF.main(str(mmRigFilepathAndFilename), 0) #print "mmMainFilepath", mmMainFilepath #Check if a folder called "max_animconversions" exists mmAnimFolderCheck = cmds.file(mmMainFilepath + "animations/", q=1, ex=1) #print "mmAnimFolderCheck", mmAnimFolderCheck #If the "max_animconversions" folder doesn't exist, stop - we have nothing to do. if (mmAnimFolderCheck == False): print "animation folder not found, canceling script" return else: mmExportedPathsList = [] #If it does, we need to: # First export the skeleton. # Find out how many files are in the animations folder. # Load in every file which is in the folder (individually). # Run the transfer to referenced rig script - which also exports the animations. # And ensure that the file is being saved as the proper name in the proper location. #--------------------------------------------- # First export the skeleton. mmESAJ.main(False) # Ensure that the file is being saved. #Save the file cmds.file(save=1, force=1) #--------------------------------------------- # Find out how many files are in the animations folder. for item in os.listdir(mmMainFilepath + "animations/"): # print "item", item mmNameChecker = item.split(".") if (len(mmNameChecker) > 1 and mmNameChecker[1] == "ma" and item != ".mayaSwatches"): mmExportInfoList = [] mmAnimFilePath = mmMainFilepath + "animations/" + item #print "mmAnimFilePath", mmAnimFilePath mmExportInfoList.append(item) mmExportInfoList.append(mmAnimFilePath) mmExportInfoList.append(mmRigFilepathAndFilename) mmExportInfoList.append(mmMainFilepath) #Store all animation filenames in a list mmExportedPathsList.append(mmExportInfoList) #Next we need to end with a call to a function which will call itself until it is done.. right? mmIterate = 0 mmExportAllAnimsSequential_2(mmExportedPathsList, mmIterate)
def mmConvAndExportAllAnimsSequential_2(mmExportedPathsList=[], mmIterate=None, *args): #--------------------------------------------- #This loads in an animation file and runs the transfer to referenced rig script #print "mmExportedPathsList", mmExportedPathsList mmAnimName = mmExportedPathsList[mmIterate][0] mmAnimFilePath = mmExportedPathsList[mmIterate][1] mmRigFilepathAndFilename = mmExportedPathsList[mmIterate][2] mmMainFilepath = mmExportedPathsList[mmIterate][3] #print "mmRigFilepathAndFilename", mmRigFilepathAndFilename #--------------------------------------------- # Load in the next file which is in the folder. #Open the file cmds.file(mmAnimFilePath, open=1) #Disable the viewport #mel.eval("paneLayout -e -manage false $gMainPane") #cmds.refresh(suspend=True) #--------------------------------------------- #--------------------------------------------- # Run the transfer to referenced rig script - which also exports the animations. ############################################ #Instead need to transplant the anim transfer script here so we actually wait for its functionality - don't see another way to do this #mmTATRR.main( str(mmRigFilepathAndFilename), str(mmAnimFilePath) ) mmCM2M.mmFixUI() #Cycle the Atom Export window just to make sure it is alive and working mel.eval("ExportAnimOptions;") mel.eval("performExportAnim 1;") mel.eval("hideOptionBox;") #Grab everything that should be selected selectionList = [] selectionList = mmSAP.main() #print "selectionList", selectionList #create lists for use later mmOriginalBones = list(selectionList) mmProperBoneList = [] mmCopyLocList = [] mmModifiedNames = [] mmTransferFromMaxBool = True mmSearchingSuffix = "_Control" mmTempLocSuffix = "_TransferLoc" #First need to ensure the scale of the animation is 1 so transfer works properly objectName = 'root' if objectName in selectionList: #clear selection cmds.select(cl=1) #select only the root cmds.select(objectName) #Scale down the selected value mmSDF3M.main(objectName) #Find out total number of frames #Store the original time before running the script mmOriginalTime = cmds.currentTime(query=True) #Find First Frame of Timeline mmFirstFrame = cmds.playbackOptions(minTime=1, query=True) #Find Last Frame of Timeline mmLastFrame = cmds.playbackOptions(maxTime=1, query=True) #mmLastFrame -= 1 #Find Total Frames mmTotalFrames = mmLastFrame - mmFirstFrame #Set animation to first frame mmCurrentTime = cmds.currentTime(mmFirstFrame, update=False) #Need to parent constrain a locator to every bone.. then pull animation out of these attached locators. # This is because the axis are expected to be rotated 90 degrees in X #Clear out duplicates & Sort #Just converting the list to a "set" and back to a "list" causes all duplicates to be removed. mmOriginalBones = list(set(mmOriginalBones)) mmOriginalBones.sort() #--------------------------------------------- ###################################### #Think I need to import the new rig now so I can use it for the Transfer_Loc rig creation ###################################### #Had to move this upwards in the script because I need the information sooner, *should* be no issues. # The list of selected items was made before this was pulled in, should be ok. #use the passed in information # mmAnimFilePath # mmRigFilepathAndFilename mmSavedDirectory = mmRFOF.main(mmRigFilepathAndFilename, 0) mmRigNamespace = mmRFOF.main(mmRigFilepathAndFilename, 1) #Need to import Referenced Rig #Original Mel: #file -r -type "mayaAscii" -ignoreVersion -gl -mergeNamespacesOnClash false -namespace "ReferencedAnimRig_Male" -options "v=0;" "C:/Radiant/stonehearth-assets/assets/models/entities/humans/male/ReferencedAnimRig_Male.ma"; cmds.file(mmRigFilepathAndFilename, r=1, type="mayaAscii", ignoreVersion=1, gl=1, mergeNamespacesOnClash=False, namespace=mmRigNamespace, options="v=0;") #Need to save bones and parents mmNewRigStoreArray = [] mmCounterA = 0 #Select all of the original selection bones for objectCounter in mmOriginalBones: #print "objectCounter", objectCounter #While we are here, lets check to see if there are non suffix items. #We don't know if this is an animation from 3dsmax where the suffixs do not exist, or one from Maya where they do. #If this is TRUE, then it means we have Controls in the scene, and we should be transfering from THEM instead of geo, #And we save the names for later to replace the original bones names. ##################################### #I dont think this will pick up referenced assets - it isn't searching for names with ":" in front. # Maybe we should be checking for both referenced and not? or.. not really, non-referenced controls shouldn't happen. ##################################### mmNameChecker = objectCounter.split(":") if (len(mmNameChecker) > 1): mmProperBoneName = mmNameChecker[1].split("_") mmTempSuffix = mmSearchingSuffix.split("_")[1] if (len(mmProperBoneName) > 1 and mmProperBoneName[1] == mmTempSuffix): mmProperBoneList.append(mmProperBoneName[0]) print "Added Proper Bone: ", mmProperBoneName[0] mmTransferFromMaxBool = False else: #Each new bone is given an array to store its name and its parent. mmNewBoneStoreArray = [] #Store the name of the bone into the array, as well as its parent. objectCounterNewName = objectCounter + mmTempLocSuffix mmNewBoneStoreArray.append(objectCounterNewName) objectParent = cmds.listRelatives(objectCounter, p=1) #Also create the names of the bones which the rig will have. mmModifiedName = mmRigNamespace + ":" + objectCounter + mmSearchingSuffix mmModifiedNames.append(mmModifiedName) #print "mmModifiedNames[mmCounterA]", mmModifiedNames[mmCounterA] if (objectParent != None): objectParent[0] += mmTempLocSuffix mmNewBoneStoreArray.append(objectParent[0]) else: mmNewBoneStoreArray.append(None) mmNewRigStoreArray.append(mmNewBoneStoreArray) #print "mmNewBoneStoreArray", mmNewBoneStoreArray mmCounterA += 1 mmTransferFromMaxBool = True #Clear out duplicates & Sort #Just converting the list to a "set" and back to a "list" causes all duplicates to be removed. if (mmTransferFromMaxBool == False): mmProperBoneList = list(set(mmProperBoneList)) mmProperBoneList.sort() elif (mmTransferFromMaxBool == True): mmCopyLocList = list(set(mmCopyLocList)) mmCopyLocList.sort() mmModifiedNames = list(set(mmModifiedNames)) mmModifiedNames.sort() mmRootBone = "" mmRootTempLoc = "" if (mmTransferFromMaxBool): mmCounterB = 0 for objectCounter in mmOriginalBones: #Create a locator and parent it to the correct bone so it mimics the movement of its parent, then transfer that animation over. #This assumes that my rig is clean - but my rigs are NOT clean, I know this. So instead, I need a way to create these locators, # then pin them in place where they SHOULD be, then move them to where they ARE, THEN transfer the animation. mmTempLoc = cmds.spaceLocator(n=objectCounter + mmTempLocSuffix)[0] #################################### #################################### #This is where I need to constrain to the rig, freeze transforms, then re-constrain to the original meshes (and do not freeze transforms). #Hopefully this gets us to the correct location, and proper animation after that. NOPE #################################### #################################### mmTempPC1 = cmds.pointConstraint(mmModifiedNames[mmCounterB], mmTempLoc, mo=0) cmds.delete(mmTempPC1) cmds.select(mmTempLoc) mmCopyLocList.append(mmTempLoc) #This may not be needed if the root temploc is set to world space # if (objectCounter == "root"): # mmRootBone = objectCounter # mmRootTempLoc = mmModifiedNames[mmCounterB] mmCounterB += 1 #Next need to take the templocs and parent them appropriately objectStoredArray = [] for rigStoredArray in mmNewRigStoreArray: #print objectStoredArray if (rigStoredArray[1] != None): cmds.parent(rigStoredArray[0], rigStoredArray[1]) if (rigStoredArray[0] != "root" + mmTempLocSuffix): cmds.select(rigStoredArray[0]) cmds.makeIdentity(apply=True, t=1, r=1, s=1, n=0, pn=1) #Next need to move the templocs to where they should be in space #################################### #I'm sure this is horrible, because they are parented, and now we are not maintaining offset constrainting them : / #################################### #FIRST: the root must line up mmCounterC = 0 while mmCounterC < len(mmOriginalBones): #Padding it wont help : ( #mmLocPad = mmOF.mmGroupInPlace( mmCopyLocList[mmCounterC] ) mmTempPC2 = cmds.parentConstraint(mmOriginalBones[mmCounterC], mmCopyLocList[mmCounterC], mo=0) cmds.delete(mmTempPC2) #Must fix the rotation from Max somehow cmds.select(mmCopyLocList[mmCounterC]) #Arbitrary 90 degree rotation isn't benefical, just does wonky stuff. What is actually happening? cmds.rotate(90, 0, 0, r=1, os=1) #Try swapping Y and Z values (probably wont work, but trying it) #mmBoneRot = cmds.getAttr(mmOriginalBones[mmCounterC] + ".rotate") #print "mmBoneRot", mmBoneRot #cmds.rotate( mmBoneRot[0][0], -mmBoneRot[0][2], mmBoneRot[0][1], r =1 ) mmTempPC3 = cmds.parentConstraint(mmOriginalBones[mmCounterC], mmCopyLocList[mmCounterC], mo=1) mmCounterC += 1 #This selects all temp locs and export the animation. if (mmTransferFromMaxBool): cmds.select(cl=1) for mmTempLoc in mmCopyLocList: cmds.select(mmTempLoc, add=True) #Else: use the passed in information mmSavedDirectory = mmRFOF.main(mmRigFilepathAndFilename, 0) mmRigNamespace = mmRFOF.main(mmRigFilepathAndFilename, 1) mmExportImportFilename = mmRFOF.main(mmAnimFilePath, 1) mmFullDirectoryPathFiletype = mmSavedDirectory + "atom_exports/" + mmExportImportFilename + ".atom" #----------------------------- ############ #Need to make sure that the atom_exports folder exists, and if not, create it. ############ for item in os.listdir(mmMainFilepath): if (item != "atom_exports"): cmds.sysFile(mmMainFilepath + "atom_exports/", makeDir=True) #----------------------------- #Export animation to specified file. mmMelExportAtomLine = 'doExportAtom(1,{ "' + mmSavedDirectory + "atom_exports/" + mmExportImportFilename + '" });' #print mmMelExportAtomLine mel.eval(mmMelExportAtomLine) #mel.eval('fileCmdCallback;') #print "mmOriginalBones", mmOriginalBones #print "mmProperBoneList", mmProperBoneList #Next we need to copy the animations from the original Rig onto the new Replacement Rig #--------------------------------------------- #remove the gathering of selectionList again #selectionList = cmds.ls(orderedSelection = True) #Clear selection cmds.select(cl=1) #Create counter and set to 0 mmCounterA = 0 #Check to see if there are any "mmProperBoneName"s in the mmProperBoneList #Take all the original bones and select the Suffix version of them within the Referenced Rig file for mmBone in mmOriginalBones: if (mmTransferFromMaxBool == True): # mmModifiedName = mmRigNamespace + ":" + mmBone + mmSearchingSuffix # mmModifiedNames.append(mmModifiedName) # print "mmModifiedNames[mmCounterA]", mmModifiedNames[mmCounterA] cmds.select(mmModifiedNames[mmCounterA], add=True) else: ################################### #This looks broken - unsure what this was even supposed to do.. why would I only want to select one bone? ################################### if (mmCounterA == 1): cmds.select(mmBone, add=True) mmCounterA += 1 mmSelectedNames = cmds.ls(sl=1) #print "mmSelectedNames - right before import: ", mmSelectedNames #***Forcing test, these lines are trash in the long run*** #mmExportImportFilename = "run" #mmRigNamespace = "ReferencedAnimRig_Male" #mmFullDirectoryPathFiletype = "C:/Users/mmalley/Documents/Work/AnimationExports/run.atom" #mmATOMOriginalName = "HumanMaleOriginal" if (mmTransferFromMaxBool == True): mmATOMImportPrefix = mmRigNamespace + ":" mmATOMImportSuffix = "" mmSearchName = mmTempLocSuffix mmReplaceName = mmSearchingSuffix else: mmATOMImportPrefix = mmRigNamespace + ":" mmATOMImportSuffix = "" mmSearchName = "" mmReplaceName = "" # print mmExportImportFilename # print mmRigNamespace # print mmFullDirectoryPathFiletype[0] # print mmATOMOriginalName # print "mmATOMImportPrefix", mmATOMImportPrefix # print "mmATOMImportSuffix", mmATOMImportSuffix ''' #not working #mmCompileMelCommandForImportAnimations = 'file -import -type "atomImport" -ra true -namespace "' + mmExportImportFilename + '" -options ";;targetTime=3;option=insert;match=string;;template=' + mmATOMOriginalName + ';;selected=template;view=0;search=;replace=;prefix=' + mmATOMImportPrefix + ';suffix=' + mmATOMImportSuffix + ';mapFile=C:/Users/mmalley/Documents/maya/projects/default/data/;" "' + mmFullDirectoryPathFiletype + '";' #removing template mmCompileMelCommandForImportAnimations = 'file -import -type "atomImport" -ra true -namespace "' + mmExportImportFilename + '" -options ";;targetTime=3;option=insert;match=string;;selected=selectedOnly;search=;replace=;prefix=' + mmATOMImportPrefix + ';suffix=' + mmATOMImportSuffix + ';mapFile=C:/Users/mmalley/Documents/maya/projects/default/data/;" "' + mmFullDirectoryPathFiletype[0] + '";' #print mmCompileMelCommandForImportAnimations #Importing animations onto new Locator Rig mel.eval(mmCompileMelCommandForImportAnimations) mel.eval("fileCmdCallback;") #mel.eval('file -import -type "atomImport" -ra true -namespace "run" -options ";;targetTime=3;option=insert;match=string;;template=HumanMaleOriginal;;selected=template;search=;replace=;prefix=ReferencedAnimRig_Male:;suffix=_loc;mapFile=C:/Users/mmalley/Documents/maya/projects/default/data/;" "C:/Users/mmalley/Documents/Work/AnimationExports/run.atom";') #Trying to find python equivalent, Failing #cmds.file( import = True, type = "atomImport", ra = True, namespace = "idle_breathe", options = ";;targetTime=3;option=insert;match=string;selected=template;suffix='_loc';mapFile=C:/Users/mmalley/Documents/maya/projects/default/data/;" "C:/Users/mmalley/Documents/Work/AnimationExports/idle_breathe/idle_breathe.atom") ''' #Find out total number of frames #Store the original time before running the script mmOriginalTime = cmds.currentTime(query=True) #Find First Frame of Timeline mmFirstFrame = cmds.playbackOptions(minTime=1, query=True) #Find Last Frame of Timeline mmLastFrame = cmds.playbackOptions(maxTime=1, query=True) #mmLastFrame -= 1 #Find Total Frames mmTotalFrames = mmLastFrame - mmFirstFrame # #Set animation to first frame # mmCurrentTime = cmds.currentTime( mmFirstFrame, update=False ) #--------------------------------------------- #Copying from 'mmTransferAnimToDifferentRig' #Re-select the desired components #print "mmFullDirectoryPathFiletype", mmFullDirectoryPathFiletype #Should this be mmFullDirectoryPathFiletype[0]? - NOPE!?!?!! I dont know, it works now. mmImportAnimFilePath = mmFullDirectoryPathFiletype mmCompiledOptionsForImportAnimations = ";;targetTime=3;option=insert;match=string;;selected=selectedOnly;search=" + mmSearchName + ";replace=" + mmReplaceName + ";prefix=" + mmATOMImportPrefix + ";suffix=" + mmATOMImportSuffix + ";mapFile=C:/Users/mmalley/Documents/maya/projects/default/data/;" #Importing animations onto new Rig cmds.file(mmImportAnimFilePath, i=1, type="atomImport", ra=1, namespace="run", options=mmCompiledOptionsForImportAnimations) cmds.viewFit(all=True) #--------------------------------------------- #Try checking what the current frame is and how long has passed mmRunTheLoop = True mmLastFrame = mmOriginalTime while (mmRunTheLoop): time.sleep(.1) mmCurrentFrame = cmds.currentTime(query=True) if (mmCurrentFrame == mmLastFrame): time.sleep(.1) if (mmCurrentFrame == mmLastFrame): mmRunTheLoop = False mmLastFrame = mmCurrentFrame #--------------------------------------------- #Need to delete old 3dsmax Rig #Need to clear selection cmds.select(cl=1) #Take all the original bones and delete them - because we just brought in a replacement for objectCounter in mmOriginalBones: cmds.select(objectCounter, add=True) #Check for Parent Pads as well mmAreThereParents = cmds.listRelatives(objectCounter, p=1) if (mmAreThereParents): cmds.select(mmAreThereParents[0], add=True) cmds.delete() #Also need to delete the created temp locator rig for mmTempLoc in mmNewRigStoreArray: cmds.select(mmTempLoc[0], add=True) cmds.delete() #--------------------------------------------- #Clean Up #Reset time to original frame cmds.currentTime(mmOriginalTime) #--------------------------------------------- #Need to save out the file as .MA #Just place it in the "Animations" folder under where the rig was saved out. mmNewAnimFilenameAndFilepath = mmSavedDirectory + "animations/" + mmExportImportFilename + ".ma" cmds.file(rename=mmNewAnimFilenameAndFilepath) cmds.file(force=1, save=1, type='mayaAscii') #--------------------------------------------- #Export an animation as well mmEAAJ.main(False) #--------------------------------------------- # And ensure that the file is being saved. #Save the file cmds.file(save=1, force=1) #--------------------------------------------- #Need to check if we should call ourself or the end function if (len(mmExportedPathsList) == mmIterate + 1): #Then call the final function mmConvAndExportAllAnimsSequential_3(mmExportedPathsList) else: #call itself again with then next iterate loaded mmConvAndExportAllAnimsSequential_2(mmExportedPathsList, mmIterate + 1)
def mmExportAllAnims(*args): #First the user must manually transfer all the animations for the particular rig # from max to maya and save them in a folder called "max_animconversions" - mmSaveFileAs should help them do this. #Disable the viewport # Translation into python is easy, how to figure out the name of the panelayout is not #mel.eval("paneLayout -e -manage false $gMainPane") #cmds.refresh(suspend=True) #Works! #Find out the current file name mmRigFilepathAndFilename = cmds.file(q=1, loc=1) #print "mmRigFilepathAndFilename", mmRigFilepathAndFilename #Get the filepath mmMainFilepath = mmRFOF.main(str(mmRigFilepathAndFilename), 0) #print "mmMainFilepath", mmMainFilepath #Get the file name mmMainFilename = mmRFOF.main(str(mmRigFilepathAndFilename), 1) #print "mmMainFilepath", mmMainFilepath #Check if a folder called "max_animconversions" exists mmAnimFolderCheck = cmds.file(mmMainFilepath + "max_animconversions/", q=1, ex=1) #print "mmAnimFolderCheck", mmAnimFolderCheck #If the "max_animconversions" folder doesn't exist, stop - we have nothing to do. if (mmAnimFolderCheck == False): print "max_animconversions folder not found, canceling script" return else: mmExportedPathsList = [] mmExportedPaths = "" #If it does, we need to: # First export the skeleton. # Find out how many files are in the max_animconversions folder. # Load in every file which is in the folder (individually). # Run the transfer to referenced rig script - which also exports the animations. # And ensure that the file is being saved as the proper name in the proper location. #--------------------------------------------- # First export the skeleton. mmESAJ.main(False) mmExportedPaths = "rig: " + mmMainFilename + "\n" # Ensure that the file is being saved. #Save the file cmds.file(save=1, force=1) #--------------------------------------------- # Find out how many files are in the max_animconversions folder. for item in os.listdir(mmMainFilepath + "max_animconversions/"): #print "item", item mmAnimFilePath = mmMainFilepath + "max_animconversions/" + item #print "mmAnimFilePath", mmAnimFilePath #--------------------------------------------- # Load in every file which is in the folder (individually). #Open the file cmds.file(mmAnimFilePath, open=1) #Disable the viewport #mel.eval("paneLayout -e -manage false $gMainPane") #cmds.refresh(suspend=True) #--------------------------------------------- # Run the transfer to referenced rig script - which also exports the animations. #Run the anim transfer to rig script mmTATRR.main(str(mmRigFilepathAndFilename), str(mmAnimFilePath)) #--------------------------------------------- # And ensure that the file is being saved. #Save the file cmds.file(save=1, force=1) mmExportedPathsList.append(item) #--------------------------------------------- for mmPath in mmExportedPathsList: mmExportedPaths = mmExportedPaths + "anim: " + mmPath + "\n" #Open the file cmds.file(mmRigFilepathAndFilename, open=1) #--------------------------------------------- #display to the user that their export is complete, and what was exported. cmds.confirmDialog(title='Export Complete', message='File(s) Exported:\n' + mmExportedPaths + '\nFilepath exported to:\n' + mmMainFilepath + "animations/", button=['OK'], defaultButton='OK')
def mmTransferAndExportAllAnims(*args): #First the user must manually transfer all the animations for the particular rig # from max to maya and save them in a folder called "max_animconversions" - quicksavefileas should help them do this. #Need to ask the user what rig they want to transfer these animations onto. #Ask the user what Rig should be referenced in and have animation applied to. mmStartingDirectory = "C:/Radiant/stonehearth-assets/assets/models" mmDialogueCaption = "Please select the replacement Rig to Reference in and apply animation to." mmRigNamespace = "ReferencedAnimRig_Male" #Open a dialogue box where user can input information mmNewRigFilepathAndFilename = cmds.fileDialog2( cap=mmDialogueCaption, fm=1, fileFilter='MA (*.ma)', selectFileFilter='MA (*.ma)', dir=mmStartingDirectory) mmNewRigFilepath = mmRFOF.main(mmNewRigFilepathAndFilename, 0) mmNewRigFilename = mmRFOF.main(mmNewRigFilepathAndFilename, 1) #Find out the Old file name mmOldRigFilepathAndFilename = cmds.file(q=1, loc=1) #Get the filepath mmOldRigFilepath = mmRFOF.main(str(mmOldRigFilepathAndFilename), 0) #Get the file name mmOldRigFilename = mmRFOF.main(str(mmOldRigFilepathAndFilename), 1) #Check if a folder called "animations" exists for the Old folder structure mmOldRigAnimFolderCheck = cmds.file(mmOldRigFilepath + "animations/", q=1, ex=1) #If the "animations" folder doesn't exist, stop - we have nothing to do. if (mmOldRigAnimFolderCheck == False): print "No Animations folder to copy from, canceling script." return else: mmExportedPathsList = [] mmExportedPaths = "" #If it does, we need to: # Find out how many files are in the animations folder. # Load in every file which is in the folder (individually). # Run the transfer to referenced rig script - which also exports the animations. # And ensure that the file is being saved as the proper name in the proper location. #--------------------------------------------- # Find out how many files are in the max_animconversions folder. for item in os.listdir(mmOldRigFilepath + "animations/"): mmNameChecker = item.split(".") if (len(mmNameChecker) > 1 and mmNameChecker[1] == "ma"): mmOldAnimFilePath = mmOldRigFilepath + "animations/" + item #--------------------------------------------- # Load in every file which is in the folder (individually). #Open the file cmds.file(mmOldAnimFilePath, open=1) # Disable the viewport mel.eval("paneLayout -e -manage false $gMainPane") cmds.refresh(suspend=True) #--------------------------------------------- # Run the transfer to different rig script - which also exports the animations. #Run the anim transfer to rig script mmTATDR.main(mmNewRigFilepathAndFilename, mmOldAnimFilePath) #--------------------------------------------- # And ensure that the file is being saved. #Save the file cmds.file(save=1, force=1) mmExportedPathsList.append(item) #--------------------------------------------- for mmPath in mmExportedPathsList: mmExportedPaths = mmExportedPaths + "anim: " + mmPath + "\n" #Open the original file cmds.file(mmOldRigFilepathAndFilename, open=1) #--------------------------------------------- #display to the user that their export is complete, and what was exported. cmds.confirmDialog(title='Export Complete', message='File(s) Exported:\n' + mmExportedPaths + '\nFilepath exported to:\n' + mmOldRigFilepath + "animations/", button=['OK'], defaultButton='OK') #Re-enable the viewport # Translation into python is easy, how to figure out the name of the panelayout is not mel.eval("paneLayout -e -manage true $gMainPane") cmds.refresh(suspend=False)
def main(*args): #Ask user where the OBJ is that they want to import #Create default path mmImportObjFilePath = "C:/Radiant/stonehearth-assets/assets/models/entities/humans/male/voxels/civ.obj" mmStartingDirectory = "C:/Radiant/stonehearth-assets/assets/models/entities" mmDialogueCaption = "Please select a name and location for OBJ you would like to import." mmfileFilterName = 'OBJ' mmfileFilterType = '.obj' mmFilepathAndFilename = "" mmDesiredReturn = 0 #Open a dialogue box where user can input information mmImportObjFilePath = cmds.fileDialog2( cap=mmDialogueCaption, fm=1, fileFilter=mmfileFilterName + ' (*' + mmfileFilterType + ')', selectFileFilter=mmfileFilterName + ' (*' + mmfileFilterType + ')', dir=mmStartingDirectory) #------------------------------------------ #Hold on import so that we can find all the things to replace. #Find all the existing mesh pieces #Separate out only transform nodes #Clear Selection cmds.select(clear=True) #Separate out only Meshes mmSelectedMeshesInScene = cmds.ls(type="mesh") #Find the parent (which should always be the transforms) mmSelectedTransformsInScene = cmds.listRelatives(mmSelectedMeshesInScene, parent=True, fullPath=True) #Clear Selection cmds.select(clear=True) #------------------------------------------ #Store what the old meshes are currently parented to for replacing later. #Clear Selection cmds.select(clear=True) #Separate out only Meshes mmSelectedMeshesInScene = cmds.ls(type="mesh") #Find the parent (which should always be the transforms) mmSelectedTransformsInScene = cmds.listRelatives(mmSelectedMeshesInScene, parent=True, fullPath=True) #Clear Selection cmds.select(clear=True) #Create a list to store all the Constraint information mmStoredConstraintInfo = [] mmStoredParentInfo = [] mmTempList = [] mmExtraBool = False mmOriginalBool = False # print "mmSelectedTransformsInScene", mmSelectedTransformsInScene for mmTransformName in mmSelectedTransformsInScene: #Clear Selection cmds.select(clear=True) #Select the Transforms cmds.select(mmTransformName) #Remove the | from the name (not sure where it came from) mmTransformNameSplit = mmTransformName.split('|') #Check for a mesh inside the 'extra object' group, if you find it, ignore it, then reset checker for mmName in mmTransformNameSplit: if (mmName == "_Group_ExtraObject"): mmExtraBool = True if (mmExtraBool): # print "mmTransformName", mmTransformNameSplit # print "found extra object: " + mmTransformName mmExtraBool = False else: mmTransformNameLen = len(mmTransformNameSplit) - 1 mmTransformName = mmTransformNameSplit[mmTransformNameLen] mmParentName = cmds.listRelatives(p=1) ''' #This is old - back when things were parented individually, we had to remove parent and re-parent, but we aren't doing that anymore. #Now we need to simply store the parent (or recreate the name later), delete the old mesh and replace it with the new mesh. mmParentName = cmds.listRelatives( p = 1 ) cmds.select( mmParentName, r = 1 ) mmConstraintName = cmds.listRelatives( type = 'constraint') #print mmConstraintName[0] print "mmTransformName", mmTransformName print "mmConstraintName", mmConstraintName mmConstraintConnections = cmds.listConnections( mmConstraintName[0] + ".target" ) #print "unflattened constraints: " #print mmConstraintConnections #Need to find and remove duplicates of constraint names #Create a list of actual constraint names mmConstraintConnectionsFlattened = [] #Create external counter mmCounter = 0 #For every constraint name, compare it to previous unique names, if it is the same ignore it # if it is new, store it and compare it to future names. for mmConstraint in mmConstraintConnections: #print "for loop " + str(mmCounter) if (mmCounter != 0): #Check versus all other strings for mmChecker in mmConstraintConnectionsFlattened: if (mmChecker == mmConstraint): break else: mmConstraintConnectionsFlattened.append(mmConstraint) #print mmConstraintConnectionsFlattened #Otherwise this is the first iteration and simply append the constraint else: mmConstraintConnectionsFlattened.append(mmConstraint) #print "first time through" #Advance counter mmCounter += 1 #print "final flattened constraints: " #print mmConstraintConnectionsFlattened #Create a temp list with the order: Child, Parent, Type of Constraint #-----Assumes that there is only one constraint on each mesh. mmTempList = [mmTransformName] + mmConstraintConnectionsFlattened #print mmTempList #Store the temp list for each transform all in one place mmStoredConstraintInfo.append( mmTempList ) ''' mmTempList = [mmTransformName, mmParentName] #Store the temp list for each transform all in one place mmStoredParentInfo.append(mmTempList) #This code should work - seems designed for it in fact - but doesn't because it cannot think about strings and arrays #mmConstraintConnectionsFlattened = mel.eval("stringArrayRemoveDuplicates( " + mmConstraintConnections + " )") #print mmConstraintConnectionsFlattened #Clear Selection cmds.select(clear=True) #print mmStoredConstraintInfo #------------------------------------------ mmImportNamespace = mmRFOF.main(mmImportObjFilePath, 1) #Import in OBJ of user's choosing cmds.file(mmImportObjFilePath, i=True, type="OBJ", ignoreVersion=True, ra=True, mergeNamespacesOnClash=False, namespace=mmImportNamespace, options="mo=1;lo=0", pr=True) #------------------------------------------ #Store OBJ imported names #Store what the new meshes names are #Clear Selection cmds.select(clear=True) #Separate out only Meshes mmSelectedMeshesInScene = cmds.ls(type="mesh") #Find the parent (which should always be the transforms) mmSelectedTransformsInScene = cmds.listRelatives(mmSelectedMeshesInScene, parent=True, fullPath=True) #Clear Selection cmds.select(clear=True) #Create a list to store all the imported mesh names mmStoredImportedTransformNames = [] mmStoredModifiedTransformNames = [] mmNewTransformList = [] mmTempList = [] #Want to store the prefix we are removing mmPrefixRemoved = "" # print "mmSelectedTransformsInScene", mmSelectedTransformsInScene for mmTransformName in mmSelectedTransformsInScene: # print "" # print "starting loop" # print "mmTransformName", mmTransformName #Remove the | from the name (not sure where it came from) mmTransformNameSplit = mmTransformName.split('|') #Check for a mesh inside the '_Group_ExtraObject' group, if you find it, ignore it, then reset checker for mmName in mmTransformNameSplit: if (mmName == "_Group_ExtraObject"): mmExtraBool = True #Also need to check for an original mesh, which would be inside the '_Group_Geometry' group, if you find it, ignore it, then reset checker if (mmName == "_Group_Geometry"): mmOriginalBool = True if (mmExtraBool): # print "found extra object: " + mmTransformName mmExtraBool = False elif (mmOriginalBool): # print "found original object: " + mmTransformName mmOriginalBool = False else: #Clear Selection cmds.select(clear=True) #Select the Transforms cmds.select(mmTransformName) #Store name #mmStoredImportedTransformNames.append( mmTransformName ) #Remove the ':' from the name and take the second portion of it # This grabs only the newly imported meshes mmTransformName = mmTransformNameSplit[1] mmNewTransformList = mmTransformName.split(':') if (len(mmNewTransformList) > 1): mmPrefixRemoved = mmNewTransformList[0] mmNewTransformName = mmNewTransformList[1] #Store new name we want mmStoredModifiedTransformNames.append(mmNewTransformName) #Delete the old mesh #Need to find if old mesh exists # (it should, but don't want to rely on that) if (cmds.objExists(mmNewTransformName)): cmds.delete(mmNewTransformName) # print "mmNewTransformName", mmNewTransformName # print "mmTransformName", mmTransformName #Rename the imported mesh to what the original was named (we are taking off the pre-fix name of the file) cmds.rename(mmTransformName, mmNewTransformName) #Delete any unused nodes - otherwise more and more are created each time script is run # This is things like material nodes and what not mel.eval('MLdeleteUnused;') #------------------------------------------ #Want to brighten material's Ambient color so it looks like it is supposed to #setAttr "civ1:civ_simpletex1.ambientColor" -type double3 1 1 1 ; # print "" # print "Trying to fix the material brought in to be the proper ambient color." # print "mmPrefixRemoved", mmPrefixRemoved # print "mmImportNamespace", mmImportNamespace cmds.setAttr(mmPrefixRemoved + ":" + mmImportNamespace + "_simpletex1.ambientColor", 1, 1, 1, type="double3") #------------------------------------------ ''' #Parent constrain the newly renamed imported mesh to the same thing the original was #print mmStoredConstraintInfo #Check all stored names for mmStoredName in mmStoredModifiedTransformNames: #Compare stored names to all stored constraint names for mmToBeChecked in mmStoredConstraintInfo: if ( mmToBeChecked[0] == mmStoredName ): mmCreatedParentConstraint = cmds.parentConstraint( mmToBeChecked[1], mmToBeChecked[0], w=1.0, mo=1) ''' #No longer parent constrain the newly renamed imported mesh to the same thing the original was, now just parent. #print mmStoredConstraintInfo #Check all stored names for mmStoredName in mmStoredModifiedTransformNames: #Compare stored names to all stored constraint names for mmToBeChecked in mmStoredParentInfo: if (mmToBeChecked[0] == mmStoredName): cmds.parent(mmToBeChecked[0], mmToBeChecked[1]) #------------------------------------------ #Deselect everything cmds.select(cl=1) #------------------------------------------ #Save the file. #-----Disabling an auto-save, don't want to accidentally save something which is bad. #cmds.file( force = 1, save = 1, type = 'mayaAscii' ) #Yeah, not going to re-enable. This is a script which is attempting to fix something, # If it breaks everything instead, then the user is screwed. #------------------------------------------ #Do need to toggle geo lock, as this is disabling what was there.. should we check and then restore to what it was? # No, just disable. 99% of the time, we want geo manipulation disabled. mmCM2M.mmToggleGeoManipulation(1)