<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "https://www.web3d.org/specifications/x3d-3.0.dtd">
<X3D profile='Immersive' version='3.0' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='https://www.web3d.org/specifications/x3d-3.0.xsd'>
  <head>
    <meta content='Example16.x3d' name='title'/>
    <meta content='X3D working group' name='creator'/>
    <meta content='Don Brutzman' name='creator'/>
    <meta content='26 June 2000' name='created'/>
    <meta content='28 October 2019' name='modified'/>
    <meta content='VRML 97 specification example: Chopper. Click chopper to toggle rotor spinning.' name='description'/>
    <meta content='originals/exampleD_16.wrl' name='reference'/>
    <meta content='VRML 97, ISO/IEC 14772-1, Part 1: Functional specification and UTF-8 encoding, D.16 Chopper' name='specificationSection'/>
    <meta content='https://www.web3d.org/documents/specifications/14772/V2.0/part1/examples.html#D.16' name='specificationUrl'/>
    <meta content='https://www.web3d.org/x3d/content/examples/Basic/Vrml97Specification/Example16.x3d' name='identifier'/>
    <meta content='X3D-Edit 3.3, https://www.web3d.org/x3d/tools/X3D-Edit' name='generator'/>
    <meta content='../license.html' name='license'/>
  </head>
  <Scene>
    <WorldInfo title='Example16.x3d'/>
    <ExternProtoDeclare appinfo='Rotor prototype to spin children geometry' name='Rotor' url='"Rotor.x3d#Rotor" "https://www.web3d.org/x3d/content/examples/Basic/Vrml97Specification/Rotor.x3d#Rotor" "Rotor.wrl#Rotor" "https://www.web3d.org/x3d/content/examples/Basic/Vrml97Specification/Rotor.wrl#Rotor"'>
      <field accessType='initializeOnly' appinfo='rotation rate' name='rate' type='SFTime'/>
      <field accessType='initializeOnly' appinfo='children geometry to spin' name='children' type='MFNode'/>
      <field accessType='inputOutput' appinfo='exposed TimeSensor field for animation' name='startTime' type='SFTime'/>
      <field accessType='inputOutput' appinfo='exposed TimeSensor field for animation' name='stopTime' type='SFTime'/>
    </ExternProtoDeclare>
    <ProtoDeclare name='Chopper'>
      <ProtoInterface>
        <field accessType='initializeOnly' name='rotorSpeed' type='SFTime' value='1'/>
      </ProtoInterface>
      <ProtoBody>
        <Group>
          <TouchSensor DEF='Touch' description='touch to start/stop spinning rotor'/>
          <Inline url='"ChopperBody.x3d" "https://www.web3d.org/x3d/content/examples/Basic/Vrml97Specification/ChopperBody.x3d" "ChopperBody.wrl" "https://www.web3d.org/x3d/content/examples/Basic/Vrml97Specification/ChopperBody.wrl"'/>
          <ProtoInstance DEF='Top' name='Rotor'>
            <fieldValue name='stopTime' value='1'/>
            <fieldValue name='children'>
              <Inline url='"ChopperRotor.x3d" "https://www.web3d.org/x3d/content/examples/Basic/Vrml97Specification/ChopperRotor.x3d" "ChopperRotor.wrl" "https://www.web3d.org/x3d/content/examples/Basic/Vrml97Specification/ChopperRotor.wrl"'/>
            </fieldValue>
            <IS>
              <connect nodeField='rate' protoField='rotorSpeed'/>
            </IS>
          </ProtoInstance>
        </Group>
        <!-- Warning: VRML97-style scripting, not X3D Scene Authoring Interface (SAI) -->
        <Script DEF='RotorScript'>
          <field accessType='inputOnly' name='startOrStopEngine' type='SFTime'/>
          <field accessType='outputOnly' name='startEngine' type='SFTime'/>
          <field accessType='outputOnly' name='stopEngine' type='SFTime'/>
          <field accessType='initializeOnly' name='engineStarted' type='SFBool' value='false'/>
          <![CDATA[
ecmascript:

function startOrStopEngine(value) {
	// start or stop engine:
	if (!engineStarted) {
		startEngine = value;
		engineStarted = true;
	}
	else
	{
		stopEngine = value;
		engineStarted = false;
	}
}
]]>
        </Script>
        <ROUTE fromField='touchTime' fromNode='Touch' toField='startOrStopEngine' toNode='RotorScript'/>
        <ROUTE fromField='startEngine' fromNode='RotorScript' toField='startTime' toNode='Top'/>
        <ROUTE fromField='stopEngine' fromNode='RotorScript' toField='stopTime' toNode='Top'/>
      </ProtoBody>
    </ProtoDeclare>
    <!-- ==================== -->
    <Viewpoint description='Example 16' position='0 0 5'/>
    <Group>
      <ProtoInstance DEF='MikesChopper' name='Chopper'/>
    </Group>
  </Scene>
</X3D>