Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. elif(pm.getAttr(exportGroup.assetType) == "Animation"):
  2. print("Starting process of exporting Animation.")
  3.  
  4. assetName = GetAssetName()
  5. #e.g. Jerry
  6.  
  7. animationName = GetAnimationName()
  8. #e.g. Walk
  9.  
  10. fbxFilename = fbxExportFilepath + "@" + animationName
  11. #e.g. D:/UnityProject/Assets/Content/Characters/Jerry/Animations/Jerry@Walk
  12.  
  13. rigRefGroupName = assetName + "_Rig:" + "Export"
  14. #e.g. Jerry_Rig:Export
  15.  
  16. modelRefGroupName = assetName + "_Model:" + "Export"
  17. #e.g. Jerry_Model:Export
  18.  
  19. print("Starting process of importing rig reference: " + rigRefGroupName)
  20. ImportReference(rigRefGroupName,"Rig",removeNamespace=True)
  21.  
  22. #If there are blendshapes
  23. if(DoBlendshapesExist(modelRefGroupName) is True or DoKeyframesExist(modelRefGroupName) is True):
  24. ImportReference(modelRefGroupName,"Model",deleteContents=False,removeNamespace=True) #Don't delete the meshes because we want to keep blendshapes or bake keyframes.
  25. pm.parent("Model",exportGroup)
  26. else:
  27. ImportReference(modelRefGroupName,"Model",deleteContents=True,removeNamespace=True) #Delete the meshes because we don't need them in the animation.
  28.  
  29. #Bake animation, delete constraints, and parent skeleton under export group
  30. rigSkeletonName = "Rig|Skeleton"
  31. if(pm.objExists(rigSkeletonName)):
  32. try:
  33. joints = pm.listRelatives(rigSkeletonName,allDescendents=True,type='joint')
  34. if joints is not None:
  35. print("Found the following joints in skeleton: " + str(joints))
  36. rootJoint = joints[len(joints) - 1]
  37. if rootJoint is not None:
  38. print("Baking simulation below hierarchy of root joint: " + rootJoint)
  39. minTime = (pm.playbackOptions(query=True, minTime=True))
  40. maxTime = (pm.playbackOptions(query=True, maxTime=True))
  41. pm.bakeResults(str(rootJoint),hierarchy="below",simulation=True,time=(minTime,maxTime))
  42. DeleteConstraints(str(rootJoint))
  43. pm.lockNode(rigSkeletonName,lock=False)
  44. pm.parent(rigSkeletonName,exportGroup)
  45. else:
  46. pm.warning("No joints found. Checking for keys directly on model.")
  47.  
  48. except Exception as e:
  49. print e.message, e.args
  50. else:
  51. pm.error("Can't find " + rigSkeletonName + ". Cancelling animation export. Re-opening file.")
  52. pm.openFile(mayaFilePath, force=True)
  53. return
  54.  
  55. presetPath = localPath + '/UnityCharacterNoEmbed.fbxexportpreset' #Load FBX Preset for an animation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement