<?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>
<!-- -->
<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.print (' '); // skip line
  Browser.print ('Click shapes to select a background...');
  Browser.print (' '); // 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.print ('Cyan background ' + count);
  }
  else count++;  // received isActive value = false
}

      
]]>
</Script>
<ROUTE fromNode='SensorButton1fromField='isActivetoNode='Filter1toField='set_boolean'/>
<ROUTE fromNode='Filter1fromField='activatedtoNode='BackgroundCyan-ishtoField='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.print ('Red background ' + count);
  }
  else count++;  // received isActive value = false
}

      
]]>
</Script>
<ROUTE fromNode='SensorButton2fromField='isActivetoNode='Filter2toField='set_boolean'/>
<ROUTE fromNode='Filter2fromField='activatedtoNode='BackgroundReddishtoField='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.print ('Blue background ' + count);
  }
  else count++;  // received isActive value = false
}

      
]]>
</Script>
<ROUTE fromNode='SensorButton3fromField='isActivetoNode='Filter3toField='set_boolean'/>
<ROUTE fromNode='Filter3fromField='activatedtoNode='BackgroundBluishtoField='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>
<!--

Index for DEF nodes : BackgroundBluish, BackgroundCyan-ish, BackgroundReddish, Default, Filter1, Filter2, Filter3, SensorButton1, SensorButton2, SensorButton3

Index for Viewpoint image : Viewpoint_1
-->

<!-- Color key: <X3dNode DEF='idName' field='value'/> matches <XmlElement DEF='idName' attribute='value'/>
(Light blue background: behavior node) (Grey background: inserted documentation) (Magenta background: X3D Extensibility)
-->

<!-- For additional help information about X3D scenes, please see X3D Tooltips, X3D Resources and X3D Scene Authoring Hints. -->