Stumbling Toward 'Awesomeness'

A Technical Art Blog

Friday, May 2, 2008

Code Execution Time on Per-Frame Functions in MotionBuilder

This is a follow-up to my post about per-frame operations in MotionBuilder. For some reason they take forever. I will show you an example, and compare the MB Python implementation to other scripting implementations by executing the same code in another Autodesk product (3dsMax).

Time Stamping

First, lets find a way to see how long it takes to execute a block of code. In the example below, the script will

from pyfbsdk import *
import time
 
#get the time
t1 = time.time()
 
#get selected items
selectedModels = FBModelList()
FBGetSelectedModels(selectedModels,None,True)
 
#print each items position
for item in selectedModels: print item.Translation
 
#tell us how long that took (time start - time finish)
print ('Process took ' + str((time.time() - t1)) + ' seconds')

I can run this on some selected models and it reports: Process took 0.0 seconds. Now if you run this on, say, 60 markers, the output window has no scrollbar, and unless you have a large screen, you will not see the last output telling you how long the process took. So we can replace the print with a messagebox:

duration = str((time.time() - t1))
FBMessageBox('Process Info:',('Process took ' + duration + ' seconds'),'ok')

Testing a Function That Loops Through Keys

Let’s take our example from before, where we go through every frame and print the position of an object in MB. Alter that code by inserting the code from above. Add the ‘import time‘ at the top, and then set t1 before you run posEveryFrame(selectedModels[0]). Now after that function, add your line that generates a messagebox.

When I run this on a single object across 1369 frames I get the messagebox above: it takes almost 10 seconds! Remember, we are just printing a position of an object here. I wrote the same code in Maxscript and it took 0.703 seconds. This is 13 times faster than MotionBuilder, a program that prides itself on dealing with keyframe data!

I think this is because MotionBuilder is actually moving the timeslider itself, even though the UI is not updating! This must be the case, because it is just unbelievably slow. So next we will research whether or not we can grab scene info at a certain time.

posted by Chris at 12:42 AM  

2 Comments »

  1. Good for people to know.

    Comment by Candide — 2008/10/28 @ 5:10 PM

  2. Nice post u have here 😀 Added to my RSS reader

    Comment by RYErnest — 2008/11/30 @ 1:06 PM

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress