home *** CD-ROM | disk | FTP | other *** search
Text File | 2001-02-20 | 2.4 KB | 90 lines | [AMAS/AMAP] |
- // -* LoadGeometryBehavior.js *-
- //
- // Name: LoadGeometry behavior
- // Description:
- // Author:
- // Version: $Id: LoadGeometryBehavior.js,v 1.4 2000/12/15 15:54:47 consumer Exp $
- //
-
- // Keep an array of the solids using this behavior
- var loadGeometrySolids = new Array(1);
-
- function LoadGeometryBehavior(geomName, position)
- {
- // Member methods of the behavior
- this.start = LoadGeometryBehaviorStart;
- this.stop = LoadGeometryBehaviorStop;
-
- // Member variables of the behavior
- this.url = url;
- this.scale = TSMakeStringFromPoint(TSMakePoint(scale, scale, scale));
- this.fixed = fixed;
- this.collidable = collidable;
- this.position = position;
- this.mass = mass;
- this.roughness = roughness;
- this.stiffness = stiffness;
- }
-
- function LoadGeometryBehaviorStart()
- {
- // Make a new solid and a new geometry
- this.solidId = TSMakeUniqID("Solid");
- this.geomId = TSMakeUniqID("Geom");
-
- TSMakeSolid(this.solidId, this.fixed, this.position);
- TSSetAttribute(this.solidId, 'mass', this.mass);
- TSSetAttribute(this.solidId, 'roughness', this.roughness);
- TSSetAttribute(this.solidId, 'stiffness', this.stiffness);
- TSAppendChild(TSGetSceneId(), this.solidId);
-
- TSMakeGeomURL(this.geomId, this.url);
- TSSetAttribute(this.geomId, 'scale', this.scale);
- TSAppendChild(this.solidId, this.geomId);
-
- // Make an optional collision volume
- if (this.collidable != '0') {
- this.volId = TSMakeUniqID("Vol_");
- TSMakeVolBounding(this.volId, "bbox");
- TSAppendChild(this.solidId, this.volId);
- }
-
- TSUpdateNode(this.solidId);
- }
-
- function LoadGeometryBehaviorStop()
- {
- // Remove the lastest solid
- TSRemoveNode(this.solidId);
- }
-
- //
- // Event functions
- //
-
- function LoadGeometryBehaviorStartEvent(obj, event)
- {
- if (loadGeometrySolids[obj] == null) {
- var url = TSGetExtraParam(event, 'url');
- var scale = TSGetExtraParam(event, 'scale');
- var fixed = TSGetExtraParam(event, 'fixed');
- var collidable = TSGetExtraParam(event, 'collidable');
- var position = TSGetExtraParam(event, 'position');
- var mass = TSGetExtraParam(event, 'mass');
- var roughness = TSGetExtraParam(event, 'roughness');
- var stiffness = TSGetExtraParam(event, 'stiffness');
-
- loadGeometrySolids[obj] = new LoadGeometryBehavior(url, scale, fixed,
- collidable, position,
- mass, roughness,
- stiffness);
- }
-
- loadGeometrySolids[obj].start();
- }
-
- function LoadGeometryBehaviorStopEvent(obj, event)
- {
- loadGeometrySolids[obj].stop();
- }
-