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

  1. // -* LoadGeometryBehavior.js *-
  2. //
  3. // Name: LoadGeometry behavior
  4. // Description: 
  5. // Author:
  6. // Version: $Id: LoadGeometryBehavior.js,v 1.4 2000/12/15 15:54:47 consumer Exp $
  7. //
  8.  
  9. // Keep an array of the solids using this behavior
  10. var loadGeometrySolids = new Array(1);
  11.  
  12. function LoadGeometryBehavior(geomName, position)
  13. {
  14.   // Member methods of the behavior
  15.   this.start = LoadGeometryBehaviorStart;
  16.   this.stop = LoadGeometryBehaviorStop;
  17.  
  18.   // Member variables of the behavior
  19.   this.url = url;
  20.   this.scale = TSMakeStringFromPoint(TSMakePoint(scale, scale, scale));
  21.   this.fixed = fixed;
  22.   this.collidable = collidable;
  23.   this.position = position;
  24.   this.mass = mass;
  25.   this.roughness = roughness;
  26.   this.stiffness = stiffness;
  27. }
  28.  
  29. function LoadGeometryBehaviorStart()
  30. {
  31.   // Make a new solid and a new geometry
  32.   this.solidId = TSMakeUniqID("Solid");
  33.   this.geomId = TSMakeUniqID("Geom");
  34.  
  35.   TSMakeSolid(this.solidId, this.fixed, this.position);
  36.   TSSetAttribute(this.solidId, 'mass', this.mass);
  37.   TSSetAttribute(this.solidId, 'roughness', this.roughness);
  38.   TSSetAttribute(this.solidId, 'stiffness', this.stiffness);
  39.   TSAppendChild(TSGetSceneId(), this.solidId);
  40.  
  41.   TSMakeGeomURL(this.geomId, this.url);
  42.   TSSetAttribute(this.geomId, 'scale', this.scale);
  43.   TSAppendChild(this.solidId, this.geomId);
  44.  
  45.   // Make an optional collision volume
  46.   if (this.collidable != '0') {
  47.     this.volId = TSMakeUniqID("Vol_");
  48.     TSMakeVolBounding(this.volId, "bbox");
  49.     TSAppendChild(this.solidId, this.volId);
  50.   }
  51.  
  52.   TSUpdateNode(this.solidId);
  53. }
  54.  
  55. function LoadGeometryBehaviorStop()
  56. {
  57.   // Remove the lastest solid
  58.   TSRemoveNode(this.solidId);
  59. }
  60.  
  61. //
  62. // Event functions
  63. //
  64.  
  65. function LoadGeometryBehaviorStartEvent(obj, event)
  66. {
  67.   if (loadGeometrySolids[obj] == null) {
  68.     var url = TSGetExtraParam(event, 'url');
  69.     var scale = TSGetExtraParam(event, 'scale');
  70.     var fixed = TSGetExtraParam(event, 'fixed');
  71.     var collidable = TSGetExtraParam(event, 'collidable');
  72.     var position = TSGetExtraParam(event, 'position');
  73.     var mass = TSGetExtraParam(event, 'mass');
  74.     var roughness = TSGetExtraParam(event, 'roughness');
  75.     var stiffness = TSGetExtraParam(event, 'stiffness');
  76.  
  77.     loadGeometrySolids[obj] = new LoadGeometryBehavior(url, scale, fixed,
  78.                                                        collidable, position,
  79.                                                        mass, roughness,
  80.                                                        stiffness);
  81.   }
  82.  
  83.   loadGeometrySolids[obj].start();
  84. }
  85.  
  86. function LoadGeometryBehaviorStopEvent(obj, event)
  87. {
  88.   loadGeometrySolids[obj].stop();
  89. }
  90.