Samples/FCurve/TimeWarp.py

# Copyright 2009 Autodesk, Inc.  All rights reserved.
# Use of this software is subject to the terms of the Autodesk license agreement 
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
#
# Script description:
# Show the usage of FBTimeWarpManager.
# Create a model and its animation, create and merge a TimeWarp onto its animation node.
# Topic: FBTimeWarpManager 
#

from pyfbsdk import FBSystem, FBModelCube, FBTime, FBTimeWarpManager, FBVector3d, FBPlayerControl
import copy

sys = FBSystem()

# Function to create rotation animation for a model
def CreateAnimation(pNode):
    if pNode.FCurve:
        lFCurve = pNode.FCurve
        lFCurve.KeyAdd(FBTime.Zero, 0)
        lFCurve.KeyAdd(FBTime(0,0,6,0), 90)
    if pNode.Nodes:
        for lNode in pNode.Nodes:
            CreateAnimation( lNode )

# Create a Model
lModel = FBModelCube("Cube TimeWarp")
lModel.Show = True
lModel.Visible = True
lModel.Scaling = FBVector3d(10, 10, 10)
lModel.Translation = FBVector3d(10,10,10)

# Create its rotation animation
lModel.Rotation.SetAnimated(True)
CreateAnimation(lModel.Rotation.GetAnimationNode())

# Copy a model for compared
lModel2 = copy.copy(lModel)
lModel2.LongName = "Cube Compared"
lModel2.Translation = FBVector3d(100,10,10)

# Instanced a FBTimeWarpManager and Create a TimeWarp
lTimeWarpManager = FBTimeWarpManager()
lTimeWarp = lTimeWarpManager.TimeWarpCreateNew( "lTimeWarpName" )

# Init the current Take and add the TimeWarp to the Take
lTimeWarpManager.TimeWarpInitTake( sys.CurrentTake )
lTimeWarpManager.TimeWarpAddToTake( sys.CurrentTake, lTimeWarp )

# Do some modification to the TimeWarp
if lTimeWarp.FCurve:
    lFCurve = lTimeWarp.FCurve
    lKeys = lFCurve.Keys
    lKeys[1].Value = lKeys[1].Value + 5
    
# Apply and Merge the TimeWarp to the FCurve of the model rotation animation node
lTimeWarpManager.ApplyTimeWarp( sys.CurrentTake, lModel.Rotation, lTimeWarp )
lAnimationNode = lModel.Rotation.GetAnimationNode()
lTimeWarpManager.TimeWarpMergeCurveNode( sys.CurrentTake, lModel.Rotation, lAnimationNode, lTimeWarp )

# Playback the two animations
lPlayer = FBPlayerControl()
lPlayer.GotoStart()
lPlayer.Play()

# Clean-up
del(FBSystem, FBModelCube, FBTime, FBTimeWarpManager, FBVector3d, FBPlayerControl )