<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "http://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 =' http://www.web3d.org/specifications/x3d-3.0.xsd '>
<head>
<meta name='titlecontent='Figure30.3ScriptSoundActivate.x3d'/>
<meta name='creatorcontent='Figure 30.3, The VRML 2.0 Sourcebook, Copyright [1997] By Andrea L. Ames, David R. Nadeau, and John L. Moreland'/>
<meta name='referencecontent=' http://www.wiley.com/legacy/compbooks/vrml2sbk/ch30/30fig03.htm '/>
<meta name='translatorcontent='Don Brutzman'/>
<meta name='createdcontent='29 October 2000'/>
<meta name='modifiedcontent='7 October 2016'/>
<meta name='descriptioncontent='A pair of filter scripts used to create a toggle on-off switch.'/>
<meta name='identifiercontent=' http://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter30-Scripts/Figure30.3ScriptSoundActivate.x3d '/>
<meta name='generatorcontent='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
<meta name='licensecontent=' ../../license.html'/>
</head>
<!--

Index for DEF nodes : Audio, TimeFilter, ToggleScript, Touch, TransparentAppearance

Index for Viewpoint images : Viewpoint_1, Viewpoint_2, Viewpoint_3, Viewpoint_4
-->
<Scene>
<Viewpoint description='toggle sound by clicking ball'/>
<Viewpoint description='move left spatialize rightposition='-5 0 10'/>
<Viewpoint description='move right spatialize leftposition='5 0 10'/>
<Viewpoint description='outside maximum attenuation ellipsoidposition='0 0 30'/>
<NavigationInfo type='"NONE"'/>
<!-- Background nodes are usually best placed at the top of the scene since they have global effect and are bindable nodes. -->
<Background groundAngle='1.309 1.570796groundColor='0.1 0.1 0 0.5 0.25 0.2 0.6 0.6 0.2skyAngle='1.309 1.571skyColor='1 0 0 1 0.4 0 1 1 0'/>
<Group>
<!-- Touch ROUTE:  [from isActive to ToggleScript.toggle ] -->
<TouchSensor DEF='Touchdescription='touch to toggle audio'/>
<Shape>
<Sphere/>
<Appearance>
<Material diffuseColor='1 0.3 0.3'/>
</Appearance>
</Shape>
<Sound maxBack='15maxFront='15minBack='5minFront='5'> </Sound>
<!-- ToggleScript ROUTEs:  [from Touch.isActive to toggle ] [from stateTurnedTrue to TimeFilter.setStart ] [from stateTurnedFalse to TimeFilter.setStop ] -->
<Script DEF='ToggleScript'>
<field name='toggletype='SFBoolaccessType='inputOnly'/>
<field name='statetype='SFBoolvalue='trueaccessType='initializeOnly'/>
<field name='stateTurnedTruetype='SFBoolaccessType='outputOnly'/>
<field name='stateTurnedFalsetype='SFBoolaccessType='outputOnly'/>
<![CDATA[
        
ecmascript:

// setting the value of an eventOut variable also sends it as an event
// you can view the output of print statements in the VRML Console

function toggle ( value, ts ) {
  // only toggle on click (isActive true) not release (isActive false)
  if ( value == false ) return;
  if ( state == true )
  {
	state  = false;
	stateTurnedFalse = true;
	Browser.print ('ToggleScript.state = ' + state + ', stateTurnedFalse = ' + true);
  }
  else
  {
	state  = true;
	stateTurnedTrue = true;
	Browser.print ('ToggleScript.state = ' + state + ', stateTurnedTrue = ' + true);
  }
}

      
]]>
</Script>
<!-- TimeFilter ROUTEs:  [from ToggleScript.stateTurnedTrue to setStart ] [from ToggleScript.stateTurnedFalse to setStop ] [from startEventTime to Audio.set_startTime ] [from stopEventTime to Audio.set_stopTime ] -->
<Script DEF='TimeFilter'>
<field name='setStarttype='SFBoolaccessType='inputOnly'/>
<field name='setStoptype='SFBoolaccessType='inputOnly'/>
<field name='startEventTimetype='SFTimeaccessType='outputOnly'/>
<field name='stopEventTimetype='SFTimeaccessType='outputOnly'/>
<![CDATA[
        
ecmascript:

// setting the value of an eventOut variable also sends it as an event

function setStart ( value, timeStamp ) {
	startEventTime = timeStamp;
	Browser.print ('TimeFilter.setStart (' + value + '), startEventTime = ' + timeStamp);
	Browser.print ('\n'); // newline
}
function setStop  ( value, timeStamp ) {
	stopEventTime  = timeStamp;
	Browser.print ('TimeFilter.setStop  (' + value + '),  stopEventTime = ' + timeStamp);
	Browser.print ('\n'); // newline
}

      
]]>
</Script>
<ROUTE fromNode='TouchfromField='isActivetoNode='ToggleScripttoField='toggle'/>
<ROUTE fromNode='ToggleScriptfromField='stateTurnedTruetoNode='TimeFiltertoField='setStart'/>
<ROUTE fromNode='ToggleScriptfromField='stateTurnedFalsetoNode='TimeFiltertoField='setStop'/>
<ROUTE fromNode='TimeFilterfromField='startEventTimetoNode='AudiotoField='set_startTime'/>
<ROUTE fromNode='TimeFilterfromField='stopEventTimetoNode='AudiotoField='set_stopTime'/>
<!-- extra widget -->
<Transform translation='0 2.5 0'>
<!-- Selectable Text design pattern has transparent Box and TouchSensor description as a tooltip -->
<Shape>
<Text string='"toggle sound" "by clicking ball"'>
<FontStyle family='"SANS"justify='"MIDDLE" "MIDDLE"size='0.8style='BOLD'/>
</Text>
<Appearance>
<Material diffuseColor='0.9 0.9 0.9'/>
</Appearance>
</Shape>
</Transform>
</Group>
<!-- Semitransparent sphere matching maxFront-MaxBack attenuation ellipsoid -->
<Shape>
<Appearance DEF='TransparentAppearance'>
<Material diffuseColor='0.5 0 0transparency='0.7'/>
</Appearance>
<Sphere radius='15'/>
</Shape>
</Scene>
</X3D>
<!--

Index for DEF nodes : Audio, TimeFilter, ToggleScript, Touch, TransparentAppearance

Index for Viewpoint images : Viewpoint_1, Viewpoint_2, Viewpoint_3, Viewpoint_4
-->

<!-- Color key: <X3dNode DEF='idName' field='value'/> matches <XmlElement DEF='idName' attribute='value'/> -->

<!-- Additional help information about X3D scenes: X3D Resources, X3D Scene Authoring Hints and X3D Tooltips -->