Skip to content

Instantly share code, notes, and snippets.

@hmasato
Last active December 26, 2015 20:28
Show Gist options
  • Select an option

  • Save hmasato/7208493 to your computer and use it in GitHub Desktop.

Select an option

Save hmasato/7208493 to your computer and use it in GitHub Desktop.
[Motionbuilder, python] _mobuTest01 Re: Looking for animation sandbox solution. http://forums.autodesk.com/t5/MotionBuilder-General/Looking-for-animation-sandbox-solution/m-p/4527329
#------------------------------------------------
# Re: Looking for animation sandbox solution. - Autodesk Discussion Groups
# http://forums.autodesk.com/t5/MotionBuilder-General/Looking-for-animation-sandbox-solution/m-p/4527329
#------------------------------------------------
#------------------------------------------------
# just experiment ;)
# step1: cleanup code
#
# takeName2takeID={"Walking":0, "Idle2Walk":1, "Kicking":2, "Standing":3, "Walk2Idle":4, "Seated":5}
# cmd2takeName={0:"Standing", 1:"Walking", 2:"Idle", 3:"Kicking", 4:"Seated"}
# == > cmd2takeID={0:3, 1:0, 2:4, 3:2, 4:5}
# speed={"x0.4":3, "x0.5":4, "x1.0":5, "x2.0":7}
#------------------------------------------------
from pyfbsdk import *
s = FBSystem()
pc = FBPlayerControl()
tk = s.Scene.Takes
data = ... # some UDP packets are received here
t = {0:tk[3], 1:tk[0], 2:tk[4], 3:tk[2], 4:tk[5], }.get(data[1], s.CurrentTake)
v = {-1:4, 0:5, 1:7, }.get(data[2], 5)
l = {"Walking":True, }.get(t.Name, False)
s.CurrentTake = t
pc.SetPlaySpeed(FBTransportPlaySpeed(v))
pc.LoopActive = l
pc.GotoStart()
pc.Play()
#------------------------------------------------
# original
#------------------------------------------------
'''
from pyfbsdk import *
import pyfbsdk as fb
## VARS
lSystem = FBSystem()
lPlayer = FBPlayerControl()
foundComponents = FBComponentList()
SPEED_0_3X = 2
SPEED_0_4X = 3
SPEED_0_5X = 4
SPEED_1X = 5
SPEED_2X = 7
## INIT
## Get Handles on takes
i = 0
for myTake in FBSystem().Scene.Takes:
## There should be a more elegant way to do it this
## Carefull if you change the order of animation this will be wrong!!
if (i == 0):
Walking = myTake
if (i == 1):
Idle2Walk = myTake
if (i == 2):
Kicking = myTake
if (i == 3):
Standing = myTake
if (i == 4):
Walk2Idle = myTake
if (i == 5):
Seated = myTake
if (i == 6):
print "!!!! there is a changing in the number of takes, this code will be all wrong!"
i = i + 1
# UDP COMM : GET COMMAND
data = ... # some UDP packets are received here
lTrigger = data [0]
lCommande = data [1]
lSpeed = data [2]
print lCommande
print lSpeed
# CURRENT TAKE AND NEXT TAKE TO PLAY
# the take that is being played right now
lCurrentTake = lSystem.CurrentTake
# Next take
# * 0 = Standing
# * 1 = Walking
# * 2 = Idle
# * 3 = Kicking
# * 4 = Seated
# Default take is same as present
lNextTake = lCurrentTake
if (lCommande == 0):
lNextTake = Standing
if (lCommande == 1):
lNextTake = Walking
if (lCommande == 2):
lNextTake = Walk2Idle
if (lCommande == 3):
lNextTake = Kicking
if (lCommande == 4):
lNextTake = Seated
# Default speed is cst
lCurrentSpeed = 0
if (lSpeed == -1):
lCurrentSpeed = SPEED_0_5X
if (lSpeed == 0):
lCurrentSpeed = SPEED_1X
if (lSpeed == 1):
lCurrentSpeed = SPEED_2X
lPlayer.SetPlaySpeed(FBTransportPlaySpeed(lCurrentSpeed))
# depending of last animation is finished or not we need to wait or not
isPlaying = lPlayer.IsPlaying
print "is Playing? "
print isPlaying
print "-- "
## UPDATE CURRENT PROPRITIES
doLoop = False
if (lNextTake.Name == "Walking"):
doLoop = True
lPlayer.LoopActive = doLoop
currentTakeDuration = lCurrentTake.LocalTimeSpan.GetDuration().GetFrame()
print "current take Duration = "
print currentTakeDuration
print "-- "
## WAIT AND PLAY
# wait end of last take
if isPlaying :
localTime = FBSystem().LocalTime.GetFrame()
print "localTime = "
print localTime
print "-- "
# this fails badely...MB freezes
#while localTime < currentTakeDuration:
# localTime = FBSystem().LocalTime.GetFrame()
# play next one
lSystem.CurrentTake = lNextTake
lPlayer.GotoStart()
lPlayer.Play()
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment