<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 4.0//EN" "https://www.web3d.org/specifications/x3d-4.0.dtd">
<X3D profile='Immersive' version='4.0' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-4.0.xsd'>
  <head>
    <meta content='EventGraphLoopTest.x3d' name='title'/>
    <meta content='Diagnostic scene for tools to test event-graph loop detection' name='description'/>
    <meta content='Don Brutzman' name='creator'/>
    <meta content='4 February 2024' name='created'/>
    <meta content='4 May 2024' name='modified'/>
    <meta content='includes intentional event loop' name='warning'/>
    <meta content='https://www.web3d.org/x3d/stylesheets/X3dToXhtml.xslt' name='reference'/>
    <meta content='EventGraphLoopTestConsoleLog.txt' name='reference'/>
    <meta content='EventGraphLoopTestIndex.html' name='reference'/>
    <meta content='X3D 4.0 Architecture, ISO/IEC 19775-1:2023, 4 Concepts, 4.4.8.4 Loops' name='specificationSection'/>
    <meta content='https://www.web3d.org/specifications/X3Dv4/ISO-IEC19775-1v4-IS/Part01/concepts.html#Loops' name='specificationUrl'/>
    <meta content='X3D event graph loop detection' name='subject'/>
    <meta content='https://www.web3d.org/x3d/content/examples/X3dForAdvancedModeling/Animation/EventGraphLoopTest.x3d' name='identifier'/>
    <meta content='X3D-Edit 4.0, https://www.web3d.org/x3d/tools/X3D-Edit' name='generator'/>
    <meta content='../license.html' name='license'/>
  </head>
  <Scene>
    <WorldInfo title='EventGraphLoopTest.x3d'/>
    <Background skyColor='1 1 0.858824'/>
    <TimeSensor DEF='Clock1' cycleInterval='8' loop='true'/>
    <TimeSensor DEF='Clock2' cycleInterval='2'/>
    <TimeSensor DEF='Clock3' cycleInterval='2'/>
    <ROUTE fromField='cycleTime' fromNode='Clock1' toField='startTime' toNode='Clock2'/>
    <ROUTE fromField='cycleTime' fromNode='Clock2' toField='startTime' toNode='Clock3'/>
    <ROUTE fromField='cycleTime' fromNode='Clock3' toField='startTime' toNode='Clock1'/>
    <Script DEF='ClockReporter'>
      <field accessType='inputOutput' name='clockStart1' type='SFTime' value='-1'/>
      <field accessType='inputOutput' name='clockStart2' type='SFTime' value='-1'/>
      <field accessType='inputOutput' name='clockStart3' type='SFTime' value='-1'/>
      <field accessType='inputOutput' appinfo='enable indirect contol of node by this Script' name='handleClock1' type='SFNode'>
        <TimeSensor USE='Clock1'/>
      </field>
      <field accessType='inputOutput' appinfo='loop count' name='loopCounter' type='SFInt32' value='0'/>
      <field accessType='outputOnly' appinfo='display latest loop count' name='loopCounterString' type='MFString'/>
      <![CDATA[
ecmascript:


function initialize()
{
    Browser.println ('[Script ClockReporter] initialize()');
}

function clockStart1 (eventValue)
{
    // input eventValue received for inputOutput field
    clockStart1 = eventValue;
    Browser.println ('[Script ClockReporter] clockStart1(' + eventValue + ')');
}

function clockStart2 (eventValue)
{
    // input eventValue received for inputOutput field
    clockStart2 = eventValue;
    Browser.println ('[Script ClockReporter] clockStart2(' + eventValue + ')');
}

function clockStart3 (eventValue)
{
    // input eventValue received for inputOutput field
    clockStart3 = eventValue;
    loopCounter++;
    // send single-line MFString output event to Text node's string field
    loopCounterString = new MFString('loop ' + loopCounter);
    Browser.println ('[Script ClockReporter] clockStart3(' + eventValue + ') received event to start text spinning');
}
]]>
    </Script>
    <ROUTE fromField='cycleTime' fromNode='Clock3' toField='clockStart3' toNode='ClockReporter'/>
    <!-- debug <ROUTE fromField='cycleTime' fromNode='Clock1' toField='clockStart1' toNode='ClockReporter'/> <ROUTE fromField='cycleTime' fromNode='Clock2' toField='clockStart2' toNode='ClockReporter'/> -->
    <Transform DEF='RotatingTransform' translation='0 1 0'>
      <Shape DEF='SpinnableTextShape'>
        <Text solid='false' string='"EventGraphLoopTest" "includes a" "three-ROUTE event loop"'>
          <FontStyle DEF='BoldFontStyle' family='"SANS"' justify='"MIDDLE" "MIDDLE"' size='0.8' style='BOLD'/>
        </Text>
        <Appearance DEF='TextAppearance'>
          <Material diffuseColor='1 0.4 0.2'/>
        </Appearance>
      </Shape>
    </Transform>
    <Transform DEF='LoopCounterTransform' scale='0.8 0.8 0.8' translation='0 -1.5 0'>
      <Shape DEF='LoopCounterTextShape'>
        <Text DEF='LoopCounterText' solid='false' string='"loop 0"'>
          <FontStyle USE='BoldFontStyle'/>
        </Text>
        <Appearance USE='TextAppearance'/>
      </Shape>
    </Transform>
    <ROUTE fromField='loopCounterString' fromNode='ClockReporter' toField='string' toNode='LoopCounterText'/>
    <OrientationInterpolator DEF='Spinner' key='0 0.3333 0.6667 1' keyValue='0 1 0 0 0 1 0 2.094395 0 1 0 4.18879 0 1 0 0'/>
    <ROUTE fromField='fraction_changed' fromNode='Clock3' toField='set_fraction' toNode='Spinner'/>
    <ROUTE fromField='value_changed' fromNode='Spinner' toField='rotation' toNode='RotatingTransform'/>
  </Scene>
</X3D>