X3D Model Documentation: ElevationGridSimpleWaveAnimation.x3d

  1  <?xml version="1.0" encoding="UTF-8"?>
  2  <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN" "https://www.web3d.org/specifications/x3d-3.3.dtd">
  3  <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'>
  4       <head>
  5            <meta name='titlecontent='ElevationGridSimpleWaveAnimation.x3d'/>
  6            <meta name='descriptioncontent='Simple Javascript animation of ElevationGrid'/>
  7            <meta name='creatorcontent='Don Brutzman'/>
  8            <meta name='createdcontent='2 December 2012'/>
  9            <meta name='modifiedcontent='20 October 2019'/>
 10            <meta name='Imagecontent='ElevationGridSimpleWaveAnimation.png'/>
 11            <meta name='identifiercontent='https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter09EventUtilitiesScripting/ElevationGridSimpleWaveAnimation.x3d'/>
 12            <meta name='generatorcontent='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
 13            <meta name='licensecontent='../license.html'/>
 14       </head>
<!--

<!--
Event Graph ROUTE Table shows event connections.
-->

<!-- to top Index for DEF nodes: Clock, GridSurface, WaveGenerationScript

Index for Viewpoint node: Viewpoint_1
-->
 15       <Scene>
 16            <WorldInfo title='ElevationGridSimpleWaveAnimation.x3d'/>
 17            <Viewpoint description='Wave vieworientation='1 0 0 -0.358771position='0 3 8'/>
 18            <Background groundColor='1 1 1skyColor='1 1 1'/>
 19            <!-- Shift zero-based ElevationGrid to left, centering it -->
 20            <Transform translation='-4 0 0'>
 21                 <Shape>
 22 
                    <!-- 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'/>
 23                      <Appearance>
 24                           <Material diffuseColor='0 0.5 1'/>
 25                      </Appearance>
 26                 </Shape>
 27            </Transform>
 28 
          <!-- ROUTE information for Clock node:  [from fraction_changed to WaveGenerationScript.newInputValue ] -->
          <TimeSensor DEF='ClockcycleInterval='5loop='true'/>
 29 
          <!-- ROUTE information for WaveGenerationScript node:  [from Clock.fraction_changed to newInputValue ] [from gridOutput to GridSurface.set_height ] -->
          <Script DEF='WaveGenerationScript'>
 30                 <field name='newInputValuetype='SFFloataccessType='inputOnly'
                appinfo='provide value and trigger new computation'/>
 31                 <field name='gridOutputtype='MFFloataccessType='outputOnly'
                appinfo='provide values to ElevationGrid'/>
 32                 <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 );
}

    
]]>
 34            </Script>
 35            < ROUTE  fromNode='Clock' fromField='fraction_changed' toNode='WaveGenerationScript' toField='newInputValue'/>
 36            < ROUTE  fromNode='WaveGenerationScript' fromField='gridOutput' toNode='GridSurface' toField='set_height'/>
 37       </Scene>
 38  </X3D>
<!--

<!--
Event Graph ROUTE Table shows event connections.
-->

<!-- to top Index for DEF nodes: Clock, GridSurface, WaveGenerationScript

Index for Viewpoint node: Viewpoint_1
-->
X3D Tooltips element index: Appearance, Background, ElevationGrid, field, head, Material, meta, ROUTE, Scene, Script, Shape, TimeSensor, Transform, Viewpoint, WorldInfo, X3D, accessType and type, XML data types, field types

Event Graph ROUTE Table entries with 2 ROUTE connections total, showing X3D event-model relationships for this scene.

Each row shows an event cascade that may occur during a single timestamp interval between frame renderings, as part of the X3D execution model.

Clock
TimeSensor
fraction_changed
SFFloat

ROUTE
event to
(1)
WaveGenerationScript
Script
newInputValue
SFFloat
then
 
 
 
WaveGenerationScript
Script
gridOutput
MFFloat

ROUTE
event to
(2)
GridSurface
ElevationGrid
set_height
MFFloat

Additional guidance on X3D animation can be found in the 10-Step Animation Design Process and Event Tracing hint sheets. Have fun with X3D! 😀

-->
<!-- Online at
https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter09EventUtilitiesScripting/ElevationGridSimpleWaveAnimationIndex.html -->
<!-- Version control at
https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter09EventUtilitiesScripting/ElevationGridSimpleWaveAnimation.x3d -->

<!-- Color legend: X3D terminology <X3dNode  DEF='idNamefield='value'/> matches XML terminology <XmlElement  DEF='idNameattribute='value'/>
(Light-blue background: event-based behavior node or statement) (Grey background inside box: inserted documentation) (Magenta background: X3D Extensibility)
-->

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