ダイナミクス イベントをテストする
 
 
 

スクリプト作成: Rob Tesdahl、Jonathan Southard(Autodesk(旧 Alias)Santa Barbara Development Center)

以下のスクリプト dynTestEvent.mel は、パーティクルの機能とパーティクルのコリジョン イベントをテストします。傾斜したプレーン上に 2 つのエミッタを作成します。放射されたパーティクルが傾斜したプレーンに衝突する度合は、重力の大きさに左右されます。衝突時にパーティクルが分裂するか放射されるかは、そのパーティクルがどのエミッタから出ているかによります。

dynTestEvent.mel

// dynTestEvent.mel
//
// Alias Script File
// MODIFY THIS AT YOUR OWN RISK
//
//
// Creation Date: 4 September 1996; Modified 09 January 2000
// Author: robt, js
//
// Procedure Name:
// dynTestEvent
//
// Description:
// Test the basic functionality of collision events.
//
// Input Arguments:
// None.
//
// Return Value:
// Number of errors that occurred in the test.
//
//
//
// ========== dynTestEvent ==========
//
// SYNOPSIS
// Test the basic functionality of collision events.
//
global proc int dynTestEvent()
{
 // First delete anything that might be left over
 // from a previous test.
 //
 file -force -new;
 currentTime -e 1;
 int $errors = 0;
 // Create the planes to bounce off.
 //
 nurbsPlane -d 3 -p 0 0 0 -w 1.5cm -lr 1 -axis 0cm 0cm 0cm 
 -name table;
 scale 10 10 10;
 rotate -1.5708rad 0rad 0rad;
 move -os 0.5 0.5 0;
 move -r -5 0 5;
 rotate -r 10 0 0;
 // Create the particle shapes to do the bouncing and splitting.
 // Material assignments will be interesting only if the lighting is
 // set.
 //
 particle -inherit 1.0 -p 0 5 -3 -n blueParticles;
 addAttr -ln colorBlue -dv 1.0 -at double blueParticlesShape;
 particle -inherit 1.0 -p 0 5 -3.5 -n redParticles;
 addAttr -ln colorRed -dv 1.0 -at double redParticlesShape;
 particle -inherit 1.0 -p 0 5 -3.5 -n greenParticles;
 addAttr -ln colorGreen -dv 1.0 -at double redParticlesShape;
 gravity -pos 10 10 10 -m 20 -name gravityField;
 // Warning: Changing resilience will change the (hardcoded)
 // number of particles that this test expects to create.
 //
 collision -r 1.0 -f 0.01 table;
 connectDynamic -f gravityField -c table blueParticles redParticles
 greenParticles;
 event -split 2 -sp 0.2 blueParticles;
 event -emit 3 -die true -sp 0.2 redParticles;
 event -emit 1 greenParticles;
 // Set up the playback options.
 //
 float $frames = 55;
 playbackOptions -min 1 -max $frames -loop once;
 // Time how long it takes to play the scene and then determine the 
 // playback frame rate. Make sure when getting the frame rate
 // that no values are divided by zero.
 //
 float $startTime = `timerX`;
 play -wait;
 float $elapsed = `timerX -st $startTime`;
 float $fps = ($elapsed == 0.0 ? 0.0 : $frames/$elapsed);
 // Check whether any blue particles went through the boundary.
 //
 if ( `getAttr blueParticles.boundingBoxMinZ` 
 < `getAttr table.boundingBoxMinZ` )
 {
 print( "dynTestEvent: Failure: \"blueParticles\" particles "
 + "went through boundary.\n" );
 $errors += 1;
 }
 // Check whether any red particles went through the boundary.
 //
 if ( `getAttr redParticles.boundingBoxMinZ` 
 < `getAttr table.boundingBoxMinZ` )
 {
 print( "dynTestEvent: Failure: \"redParticles\" particles "
 + "went through boundary.\n" );
 $errors += 1;
 }
 // Make sure that the blue particle hit one Z wall, creating two 
 // particles that each hit the other Z wall to create four total particles.
 // This is visually apparent from the side and front views together.
 //
 int $blueParticles_i = `particle -count -q blueParticles`;
 if ( $blueParticles_i != 4 && ! $errors ) // Warning Magic#
 {
 print( "dynTestEvent: Failure: There are " + $blueParticles_i
 + " \"blueParticles\" particles instead of the correct "
 + "value, 4.\n" );
 $errors += 1;
 }
 // Test that the number of events resulting in a red particle
 // creation is correct.
 //
 int $redParticles_i = `particle -count -q redParticles`;
 if ( $redParticles_i != 9 && ! $errors ) // Warning Magic#
 {
 print( "dynTestEvent: Failure: There are " + $redParticles_i
 + " \"redParticles\" particles instead of the correct "
 + "value, 9.\n" );
 $errors += 1;
 }
 // Check the totalEventCount variable.
 //
 if ((`getAttr redParticles.totalEventCount` != 4) ||
 (`getAttr blueParticles.totalEventCount` != 3))
 {
 print( "dynTestEvent: Failure: Event count attributes had " +
 "incorrect value(s).\n" );
 $errors += 1;
 }
 // Check the event attribute on the green particles.
 //
 float $event[] = `particle -at event -order 0 -q greenParticlesShape`;
 if ($event[0] != 2)
 {
 print( "dynTestEvent: Failure: Event attribute had incorrect" +
 "value(s).\n" );
 $errors += 1;
 }
 // If there are no errors, the events passed this test.
 //
 if ( $errors == 0 )
 {
 print( "dynTestEvent: Passed. (" );
 }
 else
 {
 print( "dynTestEvent: Failed. (" );
 }
 // Print the frames per second (fps) in the form X.X.
 //
 print( (int)($fps * 10)/10.0 + " fps)\n" );
 // Reset the current time to zero so user can replay the test.
 //
 currentTime -e 1;
 return $errors;
} // dynTestEvent //