Dynamics Time Playback

 
 
 

By Ramsey Harris, Autodesk (formerly Alias) Santa Barbara Development Center.

This script, dynTimePlayback.mel, determines the dynamics playback rate in frames/second from frame 0 to a frame you specify.

dynTimePlayback.mel

//
// Alias Script File
// MODIFY THIS AT YOUR OWN RISK
//
// Creation Date: 8 May 1996
// Author: rh
//
// Description:
// Playback from frame 0 to frame <n> and return the
// 		the playback rate in frames/sec. If a negative frame
// count is given, this indicates silent mode. In silent
// mode, no output is printed.
//
// This version is intended for use in batch tests of dynamics.
// It requests particle and rigid body positions every frame.
//
// RETURN
// Frame rate in frames/sec
//
global proc float dynTimePlayback( float $frames )
{
 int $silent;
 // Get the list of particle shapes.
 //
 string $particleObjects[] = `ls -type particle`;
 int $particleCount = size( $particleObjects );
 // Get the list of transforms.
 // This will include rigid bodies.
 //
 string $transforms[] = `ls -tr`;
 int $trCount = size( $transforms );
 	// Check for negative $frames. This indicates
 // $silent mode.
 //
 if ($frames < 0)
 {
 $silent = 1;
 $frames = -$frames;
 }
 else
 {
 $silent = 0;
 }
 // Setup the playback options.
 //
 playbackOptions -min 1 -max $frames -loop "once";
 currentTime -edit 0;
 // Playback the animation using the timerX command
 // to compute the $elapsed time.
 //
 float $startTime, $elapsed;
 $startTime = `timerX`;
// play -wait;
 int $i;
 for ($i = 1; $i < $frames; $i++ )
 {
 // Set time
 //
 currentTime -e $i;
 int $obj;
 // Request count for every particle object.
 //
 for ($obj = 0; $obj < $particleCount; $obj++)
 {
			string $cmd = "getAttr " + $particleObjects[$obj]+".count";
 eval( $cmd );
 }
 // Request position for every transform 
		// (includes every rigid body).
 //
 for ($obj = 0; $obj < $trCount; $obj++)
 {
 string $cmd = "getAttr " + $transforms[$obj]+".translate";
 eval ($cmd);
 }
 }
 $elapsed = `timerX -st $startTime`;
 // Compute the playback frame $rate. Print results.
 //
 float $rate = ($elapsed == 0 ? 0.0 : $frames / $elapsed) ;
 if ( ! $silent) 
 {
 print( "Playback time: " + $elapsed + " secs\n" );
 print( "Playback $rate: " + $rate + " $frames/sec\n" );
 }
 return ( $rate );
} // timePlayback //