<?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='ElevationGridSimpleWaveAnimation.x3d'/>
<meta name='descriptioncontent='Simple Javascript animation of ElevationGrid'/>
<meta name='creatorcontent='Don Brutzman'/>
<meta name='createdcontent='2 December 2012'/>
<meta name='modifiedcontent='20 October 2019'/>
<meta name='Imagecontent='ElevationGridSimpleWaveAnimation.png'/>
<meta name='identifiercontent=' https://X3dGraphics.com/examples/X3dForWebAuthors/Chapter09EventUtilitiesScripting/ElevationGridSimpleWaveAnimation.x3d '/>
<meta name='generatorcontent='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
<meta name='licensecontent=' ../license.html'/>
</head>
<!--

Index for DEF nodes : Clock, GridSurface, WaveGenerationScript

Index for Viewpoint image : Viewpoint_1
-->
<Scene>
<WorldInfo title='ElevationGridSimpleWaveAnimation.x3d'/>
<Viewpoint description='Wave vieworientation='1 0 0 -0.358771position='0 3 8'/>
<Background groundColor='1 1 1skyColor='1 1 1'/>
<!-- Shift zero-based ElevationGrid to left, centering it -->
<Transform translation='-4 0 0'>
<Shape>
<!-- ROUTE information for GridSurface node:  [from WaveGenerationScript.gridOutput to set_height ] -->
<ElevationGrid DEF='GridSurfacesolid='falsexDimension='9zDimension='3height='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'/>
<Appearance>
<Material diffuseColor='0 0.5 1'/>
</Appearance>
</Shape>
</Transform>
<!-- ROUTE information for Clock node:  [from fraction_changed to WaveGenerationScript.newInputValue ] -->
<TimeSensor DEF='ClockcycleInterval='5loop='true'/>
<!-- ROUTE information for WaveGenerationScript node:  [from Clock.fraction_changed to newInputValue ] [from gridOutput to GridSurface.set_height ] -->
<Script DEF='WaveGenerationScript'>
<field name='newInputValuetype='SFFloataccessType='inputOnly'
 appinfo='provide value and trigger new computation'/>

<field name='gridOutputtype='MFFloataccessType='outputOnly'
 appinfo='provide values to ElevationGrid'/>

<field name='waveSteptype='SFTimevalue='0.1accessType='initializeOnly'
 appinfo='wave variation'/>

<![CDATA[
      
ecmascript:

function newInputValue (eventValue)
{
   fraction = eventValue; // connected by ROUTE, receives values from TimeSensor Clock fraction_changed
   
   value0 = 0.2 * Math.sin (2 * Math.PI * (fraction - 4*waveStep));
   value1 = 0.2 * Math.sin (2 * Math.PI * (fraction - 3*waveStep));
   value2 = 0.2 * Math.sin (2 * Math.PI * (fraction - 2*waveStep));
   value3 = 0.2 * Math.sin (2 * Math.PI * (fraction -   waveStep));
   value4 = 0.2 * Math.sin (2 * Math.PI * (fraction             ));
   value5 = 0.2 * Math.sin (2 * Math.PI * (fraction +   waveStep));
   value6 = 0.2 * Math.sin (2 * Math.PI * (fraction + 2*waveStep));
   value7 = 0.2 * Math.sin (2 * Math.PI * (fraction + 3*waveStep));
   value8 = 0.2 * Math.sin (2 * Math.PI * (fraction + 4*waveStep));
   
   // setting the gridOutput value creates an output event that is connected via ROUTE to the ElevationGrid set_height field.
   // note that types match (MFFloat) and accessTypes also match (output_only connects to inputOnly).
   gridOutput = new MFFloat (
		value0, value1, value2, value3, value4, value5, value6, value7, value8,
		value0, value1, value2, value3, value4, value5, value6, value7, value8,
		value0, value1, value2, value3, value4, value5, value6, value7, value8 );
}

    
]]>
</Script>
<ROUTE fromNode='ClockfromField='fraction_changedtoNode='WaveGenerationScripttoField='newInputValue'/>
<ROUTE fromNode='WaveGenerationScriptfromField='gridOutputtoNode='GridSurfacetoField='set_height'/>
</Scene>
</X3D>
<!--

Index for DEF nodes : Clock, GridSurface, WaveGenerationScript

Index for Viewpoint image : Viewpoint_1
-->

<!-- 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. -->