<?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 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='20 October 2019'/>
<meta name='descriptioncontent='A pair of filter scripts used to create a toggle on-off switch.'/>
<meta name='identifiercontent=' https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter30Scripts/Figure30_3ScriptSoundActivate.x3d '/>
<meta name='generatorcontent='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
<meta name='licensecontent=' ../../license.html'/>
</head>
<!--

to top <!-- Event Graph ROUTE Table shows event connections -->
 
<!-- Index for DEF nodes: Audio, TimeFilter, ToggleScript, Touch, TransparentAppearance

Index for Viewpoint nodes: Viewpoint_1, Viewpoint_2, Viewpoint_3, Viewpoint_4
-->
<Scene>
<WorldInfo title='Figure30_3ScriptSoundActivate.x3d'/>
<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>
<!-- ROUTE information for Touch node:  [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>
<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.println ('ToggleScript.state = ' + state + ', stateTurnedFalse = ' + true);
  }
  else
  {
	state  = true;
	stateTurnedTrue = true;
	Browser.println ('ToggleScript.state = ' + state + ', stateTurnedTrue = ' + true);
  }
}

      
]]>
</Script>
<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.println ('TimeFilter.setStart (' + value + '), startEventTime = ' + timeStamp);
	Browser.println (); // newline
}
function setStop  ( value, timeStamp ) {
	stopEventTime  = timeStamp;
	Browser.println ('TimeFilter.setStop  (' + value + '),  stopEventTime = ' + timeStamp);
	Browser.println (); // newline
}

      
]]>
</Script>
< ROUTE  fromNode=' Touch' fromField='isActive' toNode=' ToggleScript' toField='toggle'/>
< ROUTE  fromNode=' ToggleScript' fromField='stateTurnedTrue' toNode=' TimeFilter' toField='setStart'/>
< ROUTE  fromNode=' ToggleScript' fromField='stateTurnedFalse' toNode=' TimeFilter' toField='setStop'/>
< ROUTE  fromNode=' TimeFilter' fromField='startEventTime' toNode=' Audio' toField='set_startTime'/>
< ROUTE  fromNode=' TimeFilter' fromField='stopEventTime' toNode=' Audio' toField='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>
<!--

to top <!-- Event Graph ROUTE Table shows event connections -->
 
<!-- Index for DEF nodes: Audio, TimeFilter, ToggleScript, Touch, TransparentAppearance

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

Event Graph ROUTE Table entries with 5 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.

Touch
TouchSensor
isActive
SFBool

ROUTE
event to
(1)
ToggleScript
Script
toggle
SFBool

 
 
then
ToggleScript
Script
stateTurnedFalse
SFBool

ROUTE
event to
(2)
TimeFilter
Script
setStop
SFBool

 
 
then
TimeFilter
Script
startEventTime
SFTime

ROUTE
event to
(3)
Audio
AudioClip
set_startTime
SFTime
 
 
 
then
TimeFilter
Script
stopEventTime
SFTime

ROUTE
event to
(3)
Audio
AudioClip
set_stopTime
SFTime
 
 
 
then
ToggleScript
Script
stateTurnedTrue
SFBool

ROUTE
event to
(2)
TimeFilter
Script
setStart
SFBool

 
 
then
TimeFilter
Script
startEventTime
SFTime

ROUTE
event to
(3)
Audio
AudioClip
set_startTime
SFTime
 
 
 
then
TimeFilter
Script
stopEventTime
SFTime

ROUTE
event to
(3)
Audio
AudioClip
set_stopTime
SFTime



-->

<!-- Online at
https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter30Scripts/Figure30_3ScriptSoundActivateIndex.html -->
<!-- Version control at
https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter30Scripts/Figure30_3ScriptSoundActivate.x3d -->

<!-- Color legend: X3D terminology <X3dNode DEF='idName' field='value'/> matches XML terminology <XmlElement DEF='idName' attribute='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. -->