Python Reference Guide
 
Loading...
Searching...
No Matches
Tasks\MirrorPoseOverTime.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# Create a characterPoseMirror of a pose
8#
9# Topic: FBTake, FBCharacter, FBCharacterPose, FBPlayerControl, FBKeyControl, FBScene, FBProgress
10#
11
12from pyfbsdk import *
13import time
14
15#------------------------------------------------------------------
16def SwitchTake ( pTakeName ):
17 iDestName= pTakeName
18 for iTake in lSystem.Scene.Takes:
19 if iTake.Name == iDestName:
20 lSystem.CurrentTake = iTake
21
22#------------------------------------------------------------------
23
24# find the current character
25lApplication = FBApplication()
26lCharacter = lApplication.CurrentCharacter
27
28# find the Current take
29lSystem = FBSystem()
30lOriginalTake = lSystem.CurrentTake.Name
31
32# get the Player
33lPlayer = FBPlayerControl()
34
35# Set the endTime
36lEndTime = lSystem.CurrentTake.LocalTimeSpan.GetStop()
37lEndFrame = lSystem.CurrentTake.LocalTimeSpan.GetStop().GetFrame()
38lStartFrameTime = lSystem.CurrentTake.LocalTimeSpan.GetStart()
39lStartFrame = lSystem.CurrentTake.LocalTimeSpan.GetStart().GetFrame()
40
41# create a new take for new animation
42lAnimPoseTake = lOriginalTake + ' mirror ' + str( lSystem.SystemTime.GetTimeString() )
43lNewTake = FBTake(lAnimPoseTake)
44lNewTake = lNewTake.CopyTake(lAnimPoseTake)
45
46# set pose options
47poseOptions = FBCharacterPoseOptions()
48poseOptions.mCharacterPoseKeyingMode = FBCharacterPoseKeyingMode.kFBCharacterPoseKeyingModeFullBody
49poseOptions.SetFlag(FBCharacterPoseFlag.kFBCharacterPoseMirror, True)
50
51# set the character keying mode
52lCharacter.KeyingMode=FBCharacterKeyingMode.kFBCharacterKeyingFullBody
53
54# start the pose over time sequence
55lScene = lSystem.Scene
56lStop = int(lEndFrame)
57lRange = int(lEndFrame)+1
58lTime = lStartFrameTime
59lStart = int(lStartFrame)
60lProgress = lRange - lStart
61FBKeyControl().AutoKey = True
62
63# Create a FBProgress object and set default values for the caption and text.
64lFbp = FBProgress()
65lFbp.Caption = "Mirroring "
66lFbp.Text = "over time ..."
67lCount = 0.0
68
69for i in range(lRange):
70
71 timeout = False
72 lPlayer.Goto(lTime)
73 while not lPlayer.Goto(lTime)or timeout:
74 time.sleep(1)
75 lSystem.Scene.Evaluate()
76 if timeout>5:
77 print("Unable to Go to time "+lTime.GetTimeString())
78 break
79 timeout+=1
80
81 # copy pose
82 poseName = 'CharacterPose_'+str(i)
83 targetPose = FBCharacterPose(poseName)
84
85 lSystem.Scene.Evaluate()
86 targetPose.CopyPose(lCharacter)
87
88 # Switch to target Take
89 SwitchTake(lAnimPoseTake)
90 lSystem.Scene.Evaluate()
91 targetPose.PastePose(lCharacter, poseOptions )
92 lSystem.Scene.Evaluate()
93 lPlayer.Key()
94 lSystem.Scene.Evaluate()
95 # Switch to Original Take
96 SwitchTake(lOriginalTake)
97
98 #Delete the pose,
99 targetPose.FBDelete()
100
101 #step forward one frame
102 lTime.Set(lTime.Get() + FBTime(0,0,0,1).Get())
103
104 lCount += 1
105 lVal = lCount / lProgress * 100
106 lFbp.Percent = int(lVal)
107
108lFbp.FBDelete()
109SwitchTake(lAnimPoseTake)
110lSetTimeSpan = FBTimeSpan(FBTime(0,0,0,lStart),FBTime(0,0,0,lStop) )
111lSystem.CurrentTake.LocalTimeSpan = lSetTimeSpan
112
113FBKeyControl().AutoKey = False
114lPlayer.GotoStart()
115
116
117print('done')
FBApplication is used mainly to manage files.
Definition: pyfbsdk_generated.h:801
Used to work with character poses.
Definition: pyfbsdk_generated.h:4004
Stores options for operations on poses.
Definition: pyfbsdk_generated.h:4219
Key control.
Definition: pyfbsdk_generated.h:9640
Player control.
Definition: pyfbsdk_generated.h:13745
Progress bar.b>Property: Base property class.
Definition: pyfbsdk_generated.h:14666
Provides access to the underlying system, and the MotionBuilder scene.
Definition: pyfbsdk_generated.h:18771
A take is a container for animation in a scene.
Definition: pyfbsdk_generated.h:18994
Time data structure.
Definition: pyfbsdk_generated.h:19596
TimeSpan class.
Definition: pyfbsdk_generated.h:19843
Python built-in int class.
Definition: pyfbsdk.h:59
Python built-in string class.
Definition: pyfbsdk.h:77