<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN" "https://www.web3d.org/specifications/x3d-3.3.dtd">
<X3D profile='Immersive' version='3.3 xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation =' https://www.web3d.org/specifications/x3d-3.3.xsd '>
<head>
<meta name='titlecontent='ScriptEvents.x3d'/>
<meta name='descriptioncontent='A Script node drives the position and orientation of orbiting cones near the pump house.'/>
<meta name='creatorcontent='Todd Gagnon and Mark A. Boyd'/>
<meta name='translatorcontent=' Xeena VRML importer, X3D-Edit 3.1, https://www.web3d.org/x3d/content/README.X3D-Edit.html '/>
<meta name='createdcontent='8 June 1998'/>
<meta name='translatedcontent='20 December 2002'/>
<meta name='modifiedcontent='20 October 2019'/>
<meta name='referencecontent='KelpTank.x3d'/>
<meta name='referencecontent=' https://X3dGraphics.com/examples/X3dForWebAuthors/KelpForestExhibit/PumpHouse.x3d '/>
<meta name='identifiercontent=' https://X3dGraphics.com/examples/X3dForWebAuthors/Chapter09EventUtilitiesScripting/ScriptEvents.x3d '/>
<meta name='generatorcontent='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
<meta name='generatorcontent='Vrml97ToX3dNist, http://ovrt.nist.gov/v2_x3d.html'/>
<meta name='licensecontent=' ../license.html'/>
</head>
<!-- -->
<Scene>
<WorldInfo title='ScriptEvents.x3d'/>
<Background skyColor='1 1 1'/>
<Viewpoint description='click pump house to spin conesposition='3 1 7'/>
<Viewpoint description='Book Vieworientation='-0.969 0.239 0.056 0.13position='1.66 1.34 5.95'/>
<Group>
<Transform scale='0.91 0.6 0.3translation='0.8 -0.65 0.5'>
<Shape>
<Appearance>
<Material diffuseColor='0.749 0.694 0.651'/>
</Appearance>
<Cylinder bottom='falsetop='false'/>
</Shape>
</Transform>
<Group>
<Shape>
<Appearance DEF='PumpHouseAppearance'>
<Material diffuseColor='0.82 0.78 0.74'/>
</Appearance>
<IndexedFaceSet coordIndex='0 1 5 4 -1 5 1 2 6 -1 6 2 3 7 -1 3 0 4 7 -1 1 12 13 2 -1 2 13 14 -1 12 15 16 13 -1 15 0 3 16 -1 16 3 17 -1 9 5 6 10 -1 8 9 10 11 -1 4 8 11 7 -1 4 5 9 8 -1 11 10 6 7 -1 3 2 14 17 -1 13 16 17 14 -1'>
<Coordinate point='0.0 0.0 0.0 2.0 0.0 0.0 2.0 1.75 0.0 0.0 1.75 0.0 0.625 0.75 0.0 1.0 0.75 0.0 1.0 1.6 0.0 0.625 1.6 0.0 0.625 0.75 -0.65 1.0 0.75 -0.65 1.0 1.6 -0.65 0.625 1.6 -0.65 2.0 0.0 -2.7 2.0 1.75 -2.7 2.0 2.5 -1.0 0.0 0.0 -2.7 0.0 1.75 -2.7 0.0 2.5 -1.0'/>
</IndexedFaceSet>
</Shape>
<!-- ROUTE information for PumpTouched node:  [from isActive to TouchFilter.set_boolean ] -->
<TouchSensor DEF='PumpToucheddescription='touch to activate'/>
</Group>
</Group>
<Group>
<Transform scale='0.5 0.5 0.5translation='1.0 1.1 -1.5'>
<!-- ROUTE information for PistonTransform node:  [from PistonPath.value_changed to set_translation ] -->
<Transform DEF='PistonTransform'>
<Transform scale='1.8 1.2 0.6translation='0.0 -0.2 0.0'>
<Shape>
<Appearance>
<Material diffuseColor='0.427 0.427 0.42'/>
</Appearance>
<Cylinder height='1.0radius='0.98'/>
</Shape>
</Transform>
<Transform DEF='CylinderRodrotation='0.0 0.0 -1.0 0.523599translation='-0.25 0.75 0.0'>
<Shape>
<Appearance USE='PumpHouseAppearance'/>
<Cylinder height='1.0radius='0.1'/>
</Shape>
</Transform>
<Transform rotation='0.0 0.0 1.0 1.047198translation='1.0 0.6 0.0'>
<Transform USE='CylinderRod'/>
</Transform>
<Transform translation='0.0 1.2 0.0'>
<Shape>
<Appearance USE='PumpHouseAppearance'/>
<Sphere radius='0.15'/>
</Shape>
</Transform>
<!-- ROUTE information for RockerArm1 node:  [from Rocker1Path.value_changed to set_translation ] [from Rocker1Rotation.value_changed to set_rotation ] -->
<Transform DEF='RockerArm1center='0.0 -0.4 0.0'>
<Shape>
<Appearance USE='PumpHouseAppearance'/>
<Cylinder height='1.8radius='0.1'/>
</Shape>
<Transform translation='0.0 0.95 0.0'>
<Shape>
<Appearance USE='PumpHouseAppearance'/>
<Sphere radius='0.15'/>
</Shape>
</Transform>
<!-- ROUTE information for Rocker1Path node:  [from PistonClock.fraction_changed to set_fraction ] [from value_changed to RockerArm1.set_translation ] -->
<PositionInterpolator DEF='Rocker1Pathkey='0.0 0.3 0.32 0.5 0.75 1.0keyValue='0.0 2.0 -0.25 0.0 1.8 -0.35 0.0 1.8 -0.35 0.0 2.0 -0.25 0.0 2.0 -0.12 0.0 2.0 -0.25'/>
<!-- ROUTE information for Rocker1Rotation node:  [from PistonClock.fraction_changed to set_fraction ] [from value_changed to RockerArm1.set_rotation ] -->
<OrientationInterpolator DEF='Rocker1Rotationkey='0.0 0.3 0.32 0.5 0.75 1.0keyValue='-1.0 0.0 0.0 0.523599 -1.0 0.0 0.0 1.0471976 -1.0 0.0 0.0 1.0471976 -1.0 0.0 0.0 0.523599 -1.0 0.0 0.0 0.2617994 -1.0 0.0 0.0 0.523599'/>
</Transform>
<!-- ROUTE information for RockerArm2 node:  [from Rocker2Path.value_changed to set_translation ] [from Rocker2Rotation.value_changed to set_rotation ] -->
<Transform DEF='RockerArm2center='0.0 0.7 0.0'>
<Shape>
<Appearance USE='PumpHouseAppearance'/>
<Cylinder height='1.8radius='0.1'/>
</Shape>
<Transform translation='0.0 -0.95 0.0'>
<Shape>
<Appearance USE='PumpHouseAppearance'/>
<Sphere radius='0.15'/>
</Shape>
</Transform>
<!-- ROUTE information for Rocker2Path node:  [from PistonClock.fraction_changed to set_fraction ] [from value_changed to RockerArm2.set_translation ] -->
<PositionInterpolator DEF='Rocker2Pathkey='0.0 0.3 0.32 0.5 0.75 1.0keyValue='0.0 1.95 -1.0 0.0 1.2 -1.6 0.0 1.2 -1.6 0.0 1.95 -1.0 0.0 2.2 -0.65 0.0 1.95 -1.0'/>
<!-- ROUTE information for Rocker2Rotation node:  [from PistonClock.fraction_changed to set_fraction ] [from value_changed to RockerArm2.set_rotation ] -->
<OrientationInterpolator DEF='Rocker2Rotationkey='0.0 0.3 0.32 0.5 0.75 1.0keyValue='1.0 0.0 0.0 0.523599 1.0 0.0 0.0 0.4 1.0 0.0 0.0 0.4 1.0 0.0 0.0 0.523599 1.0 0.0 0.0 1.570796 1.0 0.0 0.0 0.523599'/>
</Transform>
</Transform>
<!-- ROUTE information for PistonClock node:  [from TouchFilter.inputFalse to enabled ] [from fraction_changed to PistonPath.set_fraction ] [from fraction_changed to Rocker1Path.set_fraction ] [from fraction_changed to Rocker1Rotation.set_fraction ] [from fraction_changed to Rocker2Path.set_fraction ] [from fraction_changed to Rocker2Rotation.set_fraction ] -->
<TimeSensor DEF='PistonClockcycleInterval='5.5loop='true'/>
<!-- ROUTE information for PistonPath node:  [from PistonClock.fraction_changed to set_fraction ] [from value_changed to PistonTransform.set_translation ] -->
<PositionInterpolator DEF='PistonPathkey='0.0 0.3 0.32 0.5 0.75 1.0keyValue='-0.4 -2.3 4.0 -0.4 -1.5 4.0 -0.4 -1.5 4.0 -0.4 -2.3 4.0 -0.4 -3.3 4.0 -0.4 -2.3 4.0'/>
<Transform translation='3 2 4'>
<Transform DEF='ThreeCones'>
<!-- ROUTE information for RedTransform node:  [from ControlScript.positionRed to translation ] [from ControlScript.orientationRed to rotation ] -->
<Transform DEF='RedTransformrotation='0 0 1 3.14translation='0 -1.5 .5'>
<Shape>
<Appearance>
<Material diffuseColor='1 0 0'/>
</Appearance>
<Cone DEF='b1bottomRadius='.5height='1'/>
</Shape>
</Transform>
<!-- ROUTE information for GreenTransform node:  [from ControlScript.positionGreen to translation ] [from ControlScript.orientationGreen to rotation ] -->
<Transform DEF='GreenTransformrotation='0 0 1 -1.05translation='1.3 .75 0'>
<Shape>
<Appearance>
<Material diffuseColor='0 1 1'/>
</Appearance>
<Cone USE='b1'/>
</Shape>
</Transform>
<!-- ROUTE information for TurquoiseTransform node:  [from ControlScript.positionTurquoise to translation ] [from ControlScript.orientationTurquoise to rotation ] -->
<Transform DEF='TurquoiseTransformrotation='0 0 1 1.05translation='-1.3 .75 -.5'>
<Shape>
<Appearance>
<Material diffuseColor='1 1 0'/>
</Appearance>
<Cone USE='b1'/>
</Shape>
</Transform>
</Transform>
</Transform>
<!-- ROUTE information for ControlScript node:  [from AngleGenerator.value_changed to angle ] [from positionRed to RedTransform.translation ] [from positionGreen to GreenTransform.translation ] [from positionTurquoise to TurquoiseTransform.translation ] [from orientationRed to RedTransform.rotation ] [from orientationGreen to GreenTransform.rotation ] [from orientationTurquoise to TurquoiseTransform.rotation ] -->
<Script DEF='ControlScript'>
<field name='angletype='SFFloataccessType='inputOnly'/>
<field name='positionRedtype='SFVec3faccessType='outputOnly'/>
<field name='positionGreentype='SFVec3faccessType='outputOnly'/>
<field name='positionTurquoisetype='SFVec3faccessType='outputOnly'/>
<field name='orientationRedtype='SFRotationaccessType='outputOnly'/>
<field name='orientationGreentype='SFRotationaccessType='outputOnly'/>
<field name='orientationTurquoisetype='SFRotationaccessType='outputOnly'/>
<![CDATA[
          
ecmascript:

//  this input function receives the currently interpolated rotation angle value,
//  and then computes the position and orientation of each of the cones.

function angle (value)
{
  positionRed       = new SFVec3f (Math.cos (value), 1.5 * Math.sin(value), 0.5);
  positionGreen     = new SFVec3f (Math.cos (value+2.094), 1.5 * Math.sin(value+2.094),    0);
  positionTurquoise = new SFVec3f (Math.cos (value+4.189), 1.5 * Math.sin(value+4.189), -0.5);

  // The values 2.094 and 4.189 are 1/3 and 2/3 of 2*pi radians.
  orientationRed       = new SFRotation (0, 0, 1, -2*value);
  orientationGreen     = new SFRotation (0, 0, 1, -2*(value+2.094));
  orientationTurquoise = new SFRotation (0, 0, 1, -2*(value+4.189));
}

        
]]>
</Script>
</Transform>
</Group>
<!-- Drive the Script inputs -->
<!-- ROUTE information for AngleGenerator node:  [from SpinAngleTimer.fraction_changed to set_fraction ] [from value_changed to ControlScript.angle ] -->
<ScalarInterpolator DEF='AngleGeneratorkey='0 1keyValue='0 6.28319'/>
<ROUTE fromNode='AngleGeneratorfromField='value_changedtoNode='ControlScripttoField='angle'/>
<!-- ROUTE information for SpinAngleTimer node:  [from TouchFilter.inputTrue to enabled ] [from fraction_changed to AngleGenerator.set_fraction ] -->
<TimeSensor DEF='SpinAngleTimercycleInterval='2enabled='falseloop='truestartTime='1'/>
<ROUTE fromNode='SpinAngleTimerfromField='fraction_changedtoNode='AngleGeneratortoField='set_fraction'/>
<!-- ROUTE information for TouchFilter node:  [from PumpTouched.isActive to set_boolean ] [from inputTrue to SpinAngleTimer.enabled ] [from inputFalse to PistonClock.enabled ] -->
<BooleanFilter DEF='TouchFiltercontainerField='children'/>
<ROUTE fromNode='PumpTouchedfromField='isActivetoNode='TouchFiltertoField='set_boolean'/>
<ROUTE fromNode='TouchFilterfromField='inputTruetoNode='SpinAngleTimertoField='enabled'/>
<!-- Script output converts angle timer into positions, orientations for spinning cones -->
<ROUTE fromNode='ControlScriptfromField='positionRedtoNode='RedTransformtoField='translation'/>
<ROUTE fromNode='ControlScriptfromField='positionGreentoNode='GreenTransformtoField='translation'/>
<ROUTE fromNode='ControlScriptfromField='positionTurquoisetoNode='TurquoiseTransformtoField='translation'/>
<ROUTE fromNode='ControlScriptfromField='orientationRedtoNode='RedTransformtoField='rotation'/>
<ROUTE fromNode='ControlScriptfromField='orientationGreentoNode='GreenTransformtoField='rotation'/>
<ROUTE fromNode='ControlScriptfromField='orientationTurquoisetoNode='TurquoiseTransformtoField='rotation'/>
<!-- Regular piston engine -->
<ROUTE fromNode='TouchFilterfromField='inputFalsetoNode='PistonClocktoField='enabled'/>
<ROUTE fromNode='PistonClockfromField='fraction_changedtoNode='PistonPathtoField='set_fraction'/>
<ROUTE fromNode='PistonPathfromField='value_changedtoNode='PistonTransformtoField='set_translation'/>
<ROUTE fromNode='PistonClockfromField='fraction_changedtoNode='Rocker1PathtoField='set_fraction'/>
<ROUTE fromNode='Rocker1PathfromField='value_changedtoNode='RockerArm1toField='set_translation'/>
<ROUTE fromNode='PistonClockfromField='fraction_changedtoNode='Rocker1RotationtoField='set_fraction'/>
<ROUTE fromNode='Rocker1RotationfromField='value_changedtoNode='RockerArm1toField='set_rotation'/>
<ROUTE fromNode='PistonClockfromField='fraction_changedtoNode='Rocker2PathtoField='set_fraction'/>
<ROUTE fromNode='Rocker2PathfromField='value_changedtoNode='RockerArm2toField='set_translation'/>
<ROUTE fromNode='PistonClockfromField='fraction_changedtoNode='Rocker2RotationtoField='set_fraction'/>
<ROUTE fromNode='Rocker2RotationfromField='value_changedtoNode='RockerArm2toField='set_rotation'/>
</Scene>
</X3D>
<!--

Index for DEF nodes : AngleGenerator, b1, ControlScript, CylinderRod, GreenTransform, PistonClock, PistonPath, PistonTransform, PumpHouseAppearance, PumpTouched, RedTransform, Rocker1Path, Rocker1Rotation, Rocker2Path, Rocker2Rotation, RockerArm1, RockerArm2, SpinAngleTimer, ThreeCones, TouchFilter, TurquoiseTransform

Index for Viewpoint images : Viewpoint_1, Viewpoint_2
-->

<!-- Color key: <X3dNode DEF='idName' field='value'/> matches <XmlElement DEF='idName' attribute='value'/>
(Light blue background: behavior node) (Grey background: inserted documentation) (Magenta background: X3D Extensibility)
-->

<!-- For additional help information about X3D scenes, please see X3D Tooltips, X3D Resources and X3D Scene Authoring Hints. -->