Samples/AnimationLayer/MergeAnimationLayers.py

Samples/AnimationLayer/MergeAnimationLayers.py
1 # Copyright 2010 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 how to create new animation layers and how to animate a cube on different layers.
8 # Also, we speficy some options for the animation layers.
9 #
10 # Topic: FBAnimationLayer
11 #
12 
13 from pyfbsdk import *
14 
15 #--
16 
17 ##Create the cube taht will be animated
18 lCube = FBModelCube("Cube")
19 lCube.Translation.SetAnimated(True)
20 lCube.Rotation.SetAnimated(True)
21 lCube.Show = True;
22 
23 ##Create a new layer
24 lSystem = FBSystem()
25 lSystem.CurrentTake.CreateNewLayer()
26 lCount = lSystem.CurrentTake.GetLayerCount()
27 lSystem.CurrentTake.GetLayer(lCount-1).Name= "PythonLayer1"
28 
29 ##Modify the options on this new layer
30 lSystem.CurrentTake.GetLayerByName("PythonLayer1").Weight = 50;
31 lSystem.CurrentTake.GetLayerByName("PythonLayer1").LayerMode = FBLayerMode.kFBLayerModeOverride;
32 
33 ##Set the new layer as the current one (Keys will be added to that layer)
34 lSystem.CurrentTake.SetCurrentLayer(lCount-1)
35 
36 ##Animate the cube on the layer
37 Node = lCube.AnimationNode.Nodes[0]
38 
39 for lNode in Node.Nodes:
40  lNode.FCurve.KeyAdd(FBTime(0,0,0,0), 0)
41 lCube.Translation.GetAnimationNode().KeyAdd(FBTime(0,0,0,10), [20, 20, 20])
42 lCube.Translation.GetAnimationNode().SetCandidate([10, 10, 10])
43 lCube.Translation.GetAnimationNode().KeyCandidate()
44 
45 
46 ##Create another layer
47 lSystem.CurrentTake.CreateNewLayer()
48 lCount = lSystem.CurrentTake.GetLayerCount()
49 lSystem.CurrentTake.GetLayer(lCount-1).Name= "PythonLayer2"
50 
51 ##Set the new layer as the current one
52 lSystem.CurrentTake.SetCurrentLayer(lCount-1)
53 
54 ##Animate cube on second layer
55 for lNode in Node.Nodes:
56  lNode.FCurve.KeyAdd(FBTime(0,0,0,20), 15)
57  del( lNode )
58 lCube.Translation.GetAnimationNode().KeyAdd(FBTime(0,0,0,20), [11, 11, 11])
59 lCube.Translation.GetAnimationNode().SetCandidate([30, 30, 30])
60 lCube.Translation.GetAnimationNode().KeyCandidate()
61 
62 ##Create a third layer, this one will be the child of PythonLayer2
63 lSystem.CurrentTake.CreateNewLayer()
64 lCount = lSystem.CurrentTake.GetLayerCount()
65 ParentLayer = lSystem.CurrentTake.GetLayer(lCount-2)
66 NewChildLayer = lSystem.CurrentTake.GetLayer(lCount-1)
67 NewChildLayer.Name= "child of PythonLayer2"
68 
69 ##Parent the layer
70 ParentLayer.AddChildLayer(NewChildLayer)
71 
72 ##Print the number of child layer
73 print(ParentLayer.GetChildCount())
74 
75 ##Select layer PythonLayer1 and PythonLayer2
76 ##The BaseAnimation layer is already selected, so all the animation will go this layer
77 lSystem.CurrentTake.GetLayerByName("PythonLayer1").SelectLayer(True, False)
78 lSystem.CurrentTake.GetLayerByName("PythonLayer2").SelectLayer(True, False)
79 
80 ##Merge all object in the scene to the BaseAnimation layer, delete the source layers if they are empty
81 lSystem.CurrentTake.MergeLayers(FBAnimationLayerMergeOptions.kFBAnimLayerMerge_SelectedLayer_CompleteScene, True, FBMergeLayerMode.kFBMergeLayerModeAutomatic)