Python Reference Guide
 
Loading...
Searching...
No Matches
Samples\FCurve\TimeWarp.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# Script description:
7# Show the usage of FBTimeWarpManager.
8# Create a model and its animation, create and merge a TimeWarp onto its animation node.
9# Topic: FBTimeWarpManager
10#
11
12from pyfbsdk import FBSystem, FBModelCube, FBTime, FBTimeWarpManager, FBVector3d, FBPlayerControl
13import copy
14
15sys = FBSystem()
16
17# Function to create rotation animation for a model
18def CreateAnimation(pNode):
19 if pNode.FCurve:
20 lFCurve = pNode.FCurve
21 lFCurve.KeyAdd(FBTime.Zero, 0)
22 lFCurve.KeyAdd(FBTime(0,0,6,0), 90)
23 if pNode.Nodes:
24 for lNode in pNode.Nodes:
25 CreateAnimation( lNode )
26
27# Create a Model
28lModel = FBModelCube("Cube TimeWarp")
29lModel.Show = True
30lModel.Visible = True
31lModel.Scaling = FBVector3d(10, 10, 10)
32lModel.Translation = FBVector3d(10,10,10)
33
34# Create its rotation animation
35lModel.Rotation.SetAnimated(True)
36CreateAnimation(lModel.Rotation.GetAnimationNode())
37
38# Copy a model for compared
39lModel2 = copy.copy(lModel)
40lModel2.LongName = "Cube Compared"
41lModel2.Translation = FBVector3d(100,10,10)
42
43# Instanced a FBTimeWarpManager and Create a TimeWarp
44lTimeWarpManager = FBTimeWarpManager()
45lTimeWarp = lTimeWarpManager.TimeWarpCreateNew( "lTimeWarpName" )
46
47# Init the current Take and add the TimeWarp to the Take
48lTimeWarpManager.TimeWarpInitTake( sys.CurrentTake )
49lTimeWarpManager.TimeWarpAddToTake( sys.CurrentTake, lTimeWarp )
50
51# Do some modification to the TimeWarp
52if lTimeWarp.FCurve:
53 lFCurve = lTimeWarp.FCurve
54 lKeys = lFCurve.Keys
55 lKeys[1].Value = lKeys[1].Value + 5
56
57# Apply and Merge the TimeWarp to the FCurve of the model rotation animation node
58lTimeWarpManager.ApplyTimeWarp( sys.CurrentTake, lModel.Rotation, lTimeWarp )
59lAnimationNode = lModel.Rotation.GetAnimationNode()
60lTimeWarpManager.TimeWarpMergeCurveNode( sys.CurrentTake, lModel.Rotation, lAnimationNode, lTimeWarp )
61
62# Playback the two animations
63lPlayer = FBPlayerControl()
64lPlayer.GotoStart()
65lPlayer.Play()
66
67# Clean-up
68del(FBSystem, FBModelCube, FBTime, FBTimeWarpManager, FBVector3d, FBPlayerControl )
Cube model class.
Definition: pyfbsdk_generated.h:11337
Player control.
Definition: pyfbsdk_generated.h:13745
Provides access to the underlying system, and the MotionBuilder scene.
Definition: pyfbsdk_generated.h:18771
Time data structure.
Definition: pyfbsdk_generated.h:19596
Time Warp Manager Interface to the Time Warp Manager.
Definition: pyfbsdk_generated.h:19891