Samples/FCurve/CopyAnimation.py

Samples/FCurve/CopyAnimation.py
1 # Copyright 2009 Autodesk, Inc. All rights reserved.
2 # Use of this software is subject to the terms of the Autodesk license agreement
3 # provided at the time of installation or download, or which otherwise accompanies
4 # this software in either electronic or hard copy form.
5 #
6 # Topic: FBAnimationNode, FBFindModelByLabelName
7 #
8 
9 from pyfbsdk import *
10 
11 # Find the animation node recurvesive by name.
12 def findAnimationNode( pName, pNode ):
13  lResult = None
14  lName = pName.split( '/' )
15  for lNode in pNode.Nodes:
16  if lNode.Name == lName[0]:
17  if len( lName ) > 1:
18  lResult = findAnimationNode( pName.replace( '%s/' % lName[0], '' ), lNode )
19  else:
20  lResult = lNode
21  return lResult
22 
23 # Copy Model's TR animation data
24 def copyAnimation(pSrc, pDst ):
25  for pName in [ 'Lcl Translation/X','Lcl Translation/Y','Lcl Translation/Z', 'Lcl Rotation/X','Lcl Rotation/Y','Lcl Rotation/Z']:
26  lSrcNode = findAnimationNode( pName, pSrc.AnimationNode )
27  lDstNode = findAnimationNode( pName, pDst.AnimationNode )
28 
29  if lSrcNode and lSrcNode.FCurve and lDstNode:
30  lDstNode.FCurve.KeyReplaceBy(lSrcNode.FCurve)
31 
32 lSrc = FBFindModelByLabelName( 'SRC' )
33 lDst = FBFindModelByLabelName( 'DST' )
34 
35 ## Ensure that TRS properties are animated
36 if lSrc:
37  lSrc.Translation.SetAnimated(True)
38  lSrc.Rotation.SetAnimated(True)
39  lSrc.Scaling.SetAnimated(True)
40 if lDst:
41  lDst.Translation.SetAnimated(True)
42  lDst.Rotation.SetAnimated(True)
43  lDst.Scaling.SetAnimated(True)
44 
45 if lSrc and lDst:
46  copyAnimation(lSrc, lDst)