home *** CD-ROM | disk | FTP | other *** search
/ Flash MX Savvy / FlashMX Savvy.iso / pc / MAC / Amapi3D / Amapi3DTrial_Edition / 3SPACE / BurnBehavior.js < prev    next >
Encoding:
Text File  |  2001-02-20  |  2.2 KB  |  102 lines  |  [AMAS/AMAP]

  1. // -* BurnBehavior.js *-
  2. //
  3. // Name: Burn behavior
  4. // Description: 
  5. // Author:
  6. // Version: $Id: BurnBehavior.js,v 1.8 2000/12/21 15:03:30 consumer Exp $
  7. //
  8.  
  9. // Keep an array of the solids using this behavior
  10. var burnSolids = new Array(1);
  11.  
  12. function BurnBehavior(solidName, textureFile, intensity)
  13. {
  14.   // Member methods of the behavior
  15.   this.start = BurnBehaviorStart;
  16.   this.stop = BurnBehaviorStop;
  17.  
  18.   // Make a new burn particle system
  19.   this.psId = TSMakeUniqID("Burn_" + solidName);
  20.  
  21.   MakeBurnParticleSystem(this.psId, textureFile, intensity, TSSolidGetLengthX(solidName)); 
  22.   TSAppendChild(solidName, this.psId);
  23.   TSUpdateNode(this.psId);
  24. }
  25.  
  26. function BurnBehaviorStart(solidName)
  27. {
  28.   TSUpdateNodeAttribute(this.psId, 'state', '1');
  29. }
  30.  
  31. function BurnBehaviorStop(solidName)
  32. {
  33.   TSUpdateNodeAttribute(this.psId, 'state', '0'); 
  34. }
  35.  
  36. //
  37. // Helper function
  38. //
  39.  
  40. function MakeBurnParticleSystem(id,
  41.                 textureFile,
  42.                 intensity,
  43.                 size)
  44. {
  45.   var factor = size * intensity;
  46.  
  47.   var yawVar = '0';
  48.   var pitchVar = '0';
  49.   var initialColor = '1 0.5 0';
  50.   var endColor = '1 1 1';
  51.   var initialSize = new String(0.2 * factor);
  52.   var endSize = new String(0.05 * factor);
  53.   var speed = new String(0.001 * factor);
  54.   var speedVariation = new String(0.0005 * factor);
  55.   var lifeSpan = '800';
  56.   var lifeSpanVariation = '200';
  57.   var position = '0 0 0';
  58.   var rotation = '0 0 0';
  59.  
  60.   TSMakeParticleSystem(id,
  61.                textureFile,
  62.                'geometry',
  63.                position,
  64.                rotation,
  65.                yawVar,
  66.                pitchVar,
  67.                initialColor,
  68.                endColor,
  69.                initialSize,
  70.                endSize,
  71.                speed,
  72.                speedVariation,
  73.                lifeSpan, 
  74.                lifeSpanVariation);
  75. }
  76.  
  77. //
  78. // Event functions
  79. //
  80.  
  81. function BurnBehaviorStartEvent(obj, event)
  82. {
  83.   if (burnSolids[obj] == null) {
  84.     var intensity   = TSGetExtraParam(event, 'intensity');
  85.     var textureFile = TSGetExtraParam(event, 'texture');
  86.     var targetSolid = TSGetExtraParam(event, 'targetSolid');
  87.  
  88.     if (targetSolid == "")
  89.       burnSolids[obj] = new BurnBehavior(obj, textureFile, intensity);
  90.     else
  91.       burnSolids[obj] = new BurnBehavior(targetSolid, textureFile, intensity);
  92.  
  93.   }
  94.  
  95.   burnSolids[obj].start();
  96. }
  97.  
  98. function BurnBehaviorStopEvent(obj, event)
  99. {
  100.   burnSolids[obj].stop();
  101. }
  102.