Skip to content

Instantly share code, notes, and snippets.

@leestuartx
Created June 15, 2015 16:14
Show Gist options
  • Save leestuartx/088ad81d9a8a9c9b7ded to your computer and use it in GitHub Desktop.
Save leestuartx/088ad81d9a8a9c9b7ded to your computer and use it in GitHub Desktop.
Standard Anim to Root motion
#a script for moving translations from the hip joint to root joint for root motion animations
from pyfbsdk import *
import os.path, os, inspect, sys
# Find the animation node recurvesive by name.
def findAnimationNode( pName, pNode ):
lResult = None
lName = pName.split( '/' )
for lNode in pNode.Nodes:
if lNode.Name == lName[0]:
if len( lName ) > 1:
lResult = findAnimationNode( pName.replace( '%s/' % lName[0], '' ), lNode )
else:
lResult = lNode
return lResult
# Copy Model's TR animation data
def copyRootMotionAnimation(pSrc, pDst ):
for pName in [ 'Lcl Translation/X', 'Lcl Translation/Z' ]:
lSrcNode = findAnimationNode( pName, pSrc.AnimationNode )
lDstNode = findAnimationNode( pName, pDst.AnimationNode )
if lSrcNode and lSrcNode.FCurve and lDstNode:
lDstNode.FCurve.KeyReplaceBy(lSrcNode.FCurve)
# Copy Model's TR animation data
def clearUnusedKeys(pSrc):
for pName in [ 'Lcl Translation/X', 'Lcl Translation/Z' ]:
lSrcNode = findAnimationNode( pName, pSrc.AnimationNode )
if lSrcNode and lSrcNode.FCurve:
lSrcNode.FCurve.EditClear()
#find a joint
jointsList = FBComponentList()
FBFindObjectsByName('Character1_Reference', jointsList, False, True)
rootJoint = jointsList[0];
jointsList2 = FBComponentList()
FBFindObjectsByName('Character1_Hips', jointsList2, False, True)
hipsJoint = jointsList2[0];
#lSrc = FBFindObjectsByName( 'Character1_Hips' )
#lDst = FBFindObjectsByName( 'Character1_Reference' )
rootJoint.Translation.SetAnimated(True)
rootJoint.Rotation.SetAnimated(True)
rootJoint.Show = True;
## Ensure that TRS properties are animated
if hipsJoint:
hipsJoint.Translation.SetAnimated(True)
hipsJoint.Rotation.SetAnimated(True)
hipsJoint.Scaling.SetAnimated(True)
if rootJoint:
rootJoint.Translation.SetAnimated(True)
rootJoint.Rotation.SetAnimated(True)
rootJoint.Scaling.SetAnimated(True)
if hipsJoint and rootJoint:
copyRootMotionAnimation(hipsJoint, rootJoint)
if hipsJoint and rootJoint:
clearUnusedKeys(hipsJoint)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment