Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- elif(pm.getAttr(exportGroup.assetType) == "Animation"):
- print("Starting process of exporting Animation.")
- assetName = GetAssetName()
- #e.g. Jerry
- animationName = GetAnimationName()
- #e.g. Walk
- fbxFilename = fbxExportFilepath + "@" + animationName
- #e.g. D:/UnityProject/Assets/Content/Characters/Jerry/Animations/Jerry@Walk
- rigRefGroupName = assetName + "_Rig:" + "Export"
- #e.g. Jerry_Rig:Export
- modelRefGroupName = assetName + "_Model:" + "Export"
- #e.g. Jerry_Model:Export
- print("Starting process of importing rig reference: " + rigRefGroupName)
- ImportReference(rigRefGroupName,"Rig",removeNamespace=True)
- #If there are blendshapes
- if(DoBlendshapesExist(modelRefGroupName) is True or DoKeyframesExist(modelRefGroupName) is True):
- ImportReference(modelRefGroupName,"Model",deleteContents=False,removeNamespace=True) #Don't delete the meshes because we want to keep blendshapes or bake keyframes.
- pm.parent("Model",exportGroup)
- else:
- ImportReference(modelRefGroupName,"Model",deleteContents=True,removeNamespace=True) #Delete the meshes because we don't need them in the animation.
- #Bake animation, delete constraints, and parent skeleton under export group
- rigSkeletonName = "Rig|Skeleton"
- if(pm.objExists(rigSkeletonName)):
- try:
- joints = pm.listRelatives(rigSkeletonName,allDescendents=True,type='joint')
- if joints is not None:
- print("Found the following joints in skeleton: " + str(joints))
- rootJoint = joints[len(joints) - 1]
- if rootJoint is not None:
- print("Baking simulation below hierarchy of root joint: " + rootJoint)
- minTime = (pm.playbackOptions(query=True, minTime=True))
- maxTime = (pm.playbackOptions(query=True, maxTime=True))
- pm.bakeResults(str(rootJoint),hierarchy="below",simulation=True,time=(minTime,maxTime))
- DeleteConstraints(str(rootJoint))
- pm.lockNode(rigSkeletonName,lock=False)
- pm.parent(rigSkeletonName,exportGroup)
- else:
- pm.warning("No joints found. Checking for keys directly on model.")
- except Exception as e:
- print e.message, e.args
- else:
- pm.error("Can't find " + rigSkeletonName + ". Cancelling animation export. Re-opening file.")
- pm.openFile(mayaFilePath, force=True)
- return
- presetPath = localPath + '/UnityCharacterNoEmbed.fbxexportpreset' #Load FBX Preset for an animation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement