<?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_2ScriptBackgroundSelect.x3d'/>
<meta name='creatorcontent='Figure 30.2, 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/30fig02.htm '/>
<meta name='translatorcontent='Don Brutzman'/>
<meta name='createdcontent='2 September 2000'/>
<meta name='modifiedcontent='20 October 2019'/>
<meta name='descriptioncontent='Click on a geometric Shape to change the scene Background. A Script node controls the state changes.'/>
<meta name='identifiercontent=' https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter30Scripts/Figure30_2ScriptBackgroundSelect.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: BackgroundBluish, BackgroundCyan-ish, BackgroundReddish, Default, Filter1, Filter2, Filter3, SensorButton1, SensorButton2, SensorButton3

Index for Viewpoint node: Viewpoint_1
-->
<Scene>
<WorldInfo title='Figure30_2ScriptBackgroundSelect.x3d'/>
<Viewpoint description='Background selectorientation='1 0 0 -0.2position='0 2 10'/>
<!-- Background nodes are usually best placed at the top of the scene since they have global effect and are bindable nodes. -->
<!-- Bindable Backgrounds (cyan, red, blue) -->
<Background DEF='Default'/>
<!-- ROUTE information for BackgroundCyan-ish node:  [from Filter1.activated to set_bind ] -->
<Background DEF='BackgroundCyan-ishgroundAngle='1.309 1.570796groundColor='0.1 0.1 0 0.4 0.25 0.2 0.6 0.6 0.6skyAngle='1.309 1.571skyColor='0 0.2 0.7 0.0 0.5 1 1 1 1'/>

<!-- ROUTE information for BackgroundReddish node:  [from Filter2.activated to set_bind ] -->
<Background DEF='BackgroundReddishgroundAngle='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'/>

<!-- ROUTE information for BackgroundBluish node:  [from Filter3.activated to set_bind ] -->
<Background DEF='BackgroundBluishgroundAngle='1.309 1.570796groundColor='0 0 0.1 0 0.1 0.3 0.3 0.3 0.6skyAngle='1.309 1.571skyColor='1 0 0.8 0.5 0 0.8 0 0 0.8'/>

<Group>
<Transform translation='-3 0 0'>
<Shape>
<Box/>
<Appearance>
<Material diffuseColor='0 0.5 0.8'/>
</Appearance>
</Shape>
<!-- ROUTE information for SensorButton1 node:  [from isActive to Filter1.set_boolean ] -->
<TouchSensor DEF='SensorButton1description='Cyan background'/>
</Transform>
<!-- ROUTE information for Filter1 node:  [from SensorButton1.isActive to set_boolean ] [from activated to BackgroundCyan-ish.set_bind ] -->
<Script DEF='Filter1'>
<field name='set_booleantype='SFBoolaccessType='inputOnly'
 appinfo='filter input value' />

<field name='activatedtype='SFBoolaccessType='outputOnly'
 appinfo='activated provides a persistent binding value otherwise isActive events will toggle Background binding on/off.' />

<field name='counttype='SFInt32value='1accessType='initializeOnly'
 appinfo='count is only used locally so it is declared as an interface for persistence' />

<![CDATA[
        
ecmascript:

function initialize () {
  Browser.println (' '); // skip line
  Browser.println ('Click shapes to select a background...');
  Browser.println (' '); // skip line
}

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

function set_boolean ( value, eventTime ) {
  // only trigger on true values so that Background stays bound
  if ( value == true ) {  
	activated = value;
	Browser.println ('Cyan background ' + count);
  }
  else count++;  // received isActive value = false
}

      
]]>
</Script>
< ROUTE  fromNode=' SensorButton1' fromField='isActive' toNode=' Filter1' toField='set_boolean'/>
< ROUTE  fromNode=' Filter1' fromField='activated' toNode=' BackgroundCyan-ish' toField='set_bind'/>
<Group>
<Shape>
<Sphere/>
<Appearance>
<Material diffuseColor='1 0.3 0.3'/>
</Appearance>
</Shape>
<!-- ROUTE information for SensorButton2 node:  [from isActive to Filter2.set_boolean ] -->
<TouchSensor DEF='SensorButton2description='Red background'/>
</Group>
<!-- ROUTE information for Filter2 node:  [from SensorButton2.isActive to set_boolean ] [from activated to BackgroundReddish.set_bind ] -->
<Script DEF='Filter2'>
<field name='set_booleantype='SFBoolaccessType='inputOnly'
 appinfo='filter input value' />

<field name='activatedtype='SFBoolaccessType='outputOnly'
 appinfo='activated provides a persistent binding value otherwise isActive events will toggle Background binding on/off.' />

<field name='counttype='SFInt32value='1accessType='initializeOnly'
 appinfo='count is only used locally so it is declared as an interface for persistence' />

<![CDATA[
        
ecmascript:

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

function set_boolean ( value, eventTime ) {
  // only trigger on true values so that Background stays bound
  if ( value == true ) {
	activated = value;
	Browser.println ('Red background ' + count);
  }
  else count++;  // received isActive value = false
}

      
]]>
</Script>
< ROUTE  fromNode=' SensorButton2' fromField='isActive' toNode=' Filter2' toField='set_boolean'/>
< ROUTE  fromNode=' Filter2' fromField='activated' toNode=' BackgroundReddish' toField='set_bind'/>
<Transform translation='3 0 0'>
<Shape>
<Cone/>
<Appearance>
<Material diffuseColor='0.2 0.2 0.8'/>
</Appearance>
</Shape>
<!-- ROUTE information for SensorButton3 node:  [from isActive to Filter3.set_boolean ] -->
<TouchSensor DEF='SensorButton3description='Blue background'/>
</Transform>
<!-- ROUTE information for Filter3 node:  [from SensorButton3.isActive to set_boolean ] [from activated to BackgroundBluish.set_bind ] -->
<Script DEF='Filter3'>
<field name='set_booleantype='SFBoolaccessType='inputOnly'
 appinfo='filter input value' />

<field name='activatedtype='SFBoolaccessType='outputOnly'
 appinfo='activated provides a persistent binding value otherwise isActive events will toggle Background binding on/off.' />

<field name='counttype='SFInt32value='1accessType='initializeOnly'
 appinfo='count is only used locally so it is declared as an interface for persistence' />

<![CDATA[
        
ecmascript:

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

function set_boolean ( value, eventTime ) {
  // only trigger on true values so that Background stays bound
  if ( value == true ) {
	activated = value;
	Browser.println ('Blue background ' + count);
  }
  else count++;  // received isActive value = false
}

      
]]>
</Script>
< ROUTE  fromNode=' SensorButton3' fromField='isActive' toNode=' Filter3' toField='set_boolean'/>
< ROUTE  fromNode=' Filter3' fromField='activated' toNode=' BackgroundBluish' toField='set_bind'/>
<Transform translation='0 -3 0'>
<Shape>
<Text string='"Click on a Shape to change a Background," "Open player console to see trace statements."'>
<FontStyle justify='"MIDDLE" "MIDDLE"size='0.6'/>
</Text>
<Appearance>
<Material diffuseColor='0.7 0.7 0.7'/>
</Appearance>
</Shape>
</Transform>
</Group>
</Scene>
</X3D>
<!--

to top <!-- Event Graph ROUTE Table shows event connections -->
 
<!-- Index for DEF nodes: BackgroundBluish, BackgroundCyan-ish, BackgroundReddish, Default, Filter1, Filter2, Filter3, SensorButton1, SensorButton2, SensorButton3

Index for Viewpoint node: Viewpoint_1
-->

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

SensorButton1
TouchSensor
isActive
SFBool

ROUTE
event to
(1)
Filter1
Script
set_boolean
SFBool

 
 
then
Filter1
Script
activated
SFBool

ROUTE
event to
(2)
BackgroundCyan-ish
Background
set_bind
SFBool


SensorButton2
TouchSensor
isActive
SFBool

ROUTE
event to
(1)
Filter2
Script
set_boolean
SFBool

 
 
then
Filter2
Script
activated
SFBool

ROUTE
event to
(2)
BackgroundReddish
Background
set_bind
SFBool


SensorButton3
TouchSensor
isActive
SFBool

ROUTE
event to
(1)
Filter3
Script
set_boolean
SFBool

 
 
then
Filter3
Script
activated
SFBool

ROUTE
event to
(2)
BackgroundBluish
Background
set_bind
SFBool


      Filter1
Script
activated
SFBool

ROUTE
event to
(1)
BackgroundCyan-ish
Background
set_bind
SFBool



-->

<!-- Online at
https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter30Scripts/Figure30_2ScriptBackgroundSelectIndex.html -->
<!-- Version control at
https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter30Scripts/Figure30_2ScriptBackgroundSelect.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. -->