X3D Model Documentation: Figure30_2ScriptBackgroundSelect.x3d

  1  <?xml version="1.0" encoding="UTF-8"?>
  2 
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "https://www.web3d.org/specifications/x3d-3.0.dtd">
  3  <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'>
  4       <head>
  5            <meta name='titlecontent='Figure30_2ScriptBackgroundSelect.x3d'/>
  6            <meta name='creatorcontent='Figure 30.2, The VRML 2.0 Sourcebook, Copyright [1997] By Andrea L. Ames, David R. Nadeau, and John L. Moreland'/>
  7            <meta name='referencecontent='http://www.wiley.com/legacy/compbooks/vrml2sbk/ch30/30fig02.htm'/>
  8            <meta name='translatorcontent='Don Brutzman'/>
  9            <meta name='createdcontent='2 September 2000'/>
 10            <meta name='modifiedcontent='20 October 2019'/>
 11            <meta name='descriptioncontent='Click on a geometric Shape to change the scene Background. A Script node controls the state changes.'/>
 12            <meta name='identifiercontent='https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter30Scripts/Figure30_2ScriptBackgroundSelect.x3d'/>
 13            <meta name='generatorcontent='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
 14            <meta name='licensecontent='../../license.html'/>
 15       </head>
<!--

<!--
Event Graph ROUTE Table shows event connections.
-->

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

Index for Viewpoint node: Viewpoint_1
-->
 16       <Scene>
 17            <WorldInfo title='Figure30_2ScriptBackgroundSelect.x3d'/>
 18            <Viewpoint description='Background selectorientation='1 0 0 -0.2position='0 2 10'/>
 19            <!-- Background nodes are usually best placed at the top of the scene since they have global effect and are bindable nodes. -->
 20            <!-- Bindable Backgrounds (cyan, red, blue) -->
 21            <Background DEF='Default'/>
 22 
          <!-- 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'/>
 23 
          <!-- 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'/>
 24 
          <!-- 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'/>
 25            <Group>
 26                 <Transform translation='-3 0 0'>
 27                      <Shape>
 28                           <Box/>
 29                           <Appearance>
 30                                <Material diffuseColor='0 0.5 0.8'/>
 31                           </Appearance>
 32                      </Shape>
 33 
                    <!-- ROUTE information for SensorButton1 node:  [from isActive to Filter1.set_boolean ] -->
                    <TouchSensor DEF='SensorButton1description='Cyan background'/>
 34                 </Transform>
 35 
               <!-- ROUTE information for Filter1 node:  [from SensorButton1.isActive to set_boolean ] [from activated to BackgroundCyan-ish.set_bind ] -->
               <Script DEF='Filter1'>
 36                      <field name='set_booleantype='SFBoolaccessType='inputOnly'
                     appinfo='filter input value'/>
 37                      <field name='activatedtype='SFBoolaccessType='outputOnly'
                     appinfo='activated provides a persistent binding value otherwise isActive events will toggle Background binding on/off.'/>
 38                      <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
}

      
]]>
 40                 </Script>
 41                 < ROUTE  fromNode='SensorButton1' fromField='isActive' toNode='Filter1' toField='set_boolean'/>
 42                 < ROUTE  fromNode='Filter1' fromField='activated' toNode='BackgroundCyan-ish' toField='set_bind'/>
 43                 <Group>
 44                      <Shape>
 45                           <Sphere/>
 46                           <Appearance>
 47                                <Material diffuseColor='1 0.3 0.3'/>
 48                           </Appearance>
 49                      </Shape>
 50 
                    <!-- ROUTE information for SensorButton2 node:  [from isActive to Filter2.set_boolean ] -->
                    <TouchSensor DEF='SensorButton2description='Red background'/>
 51                 </Group>
 52 
               <!-- ROUTE information for Filter2 node:  [from SensorButton2.isActive to set_boolean ] [from activated to BackgroundReddish.set_bind ] -->
               <Script DEF='Filter2'>
 53                      <field name='set_booleantype='SFBoolaccessType='inputOnly'
                     appinfo='filter input value'/>
 54                      <field name='activatedtype='SFBoolaccessType='outputOnly'
                     appinfo='activated provides a persistent binding value otherwise isActive events will toggle Background binding on/off.'/>
 55                      <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
}

      
]]>
 57                 </Script>
 58                 < ROUTE  fromNode='SensorButton2' fromField='isActive' toNode='Filter2' toField='set_boolean'/>
 59                 < ROUTE  fromNode='Filter2' fromField='activated' toNode='BackgroundReddish' toField='set_bind'/>
 60                 <Transform translation='3 0 0'>
 61                      <Shape>
 62                           <Cone/>
 63                           <Appearance>
 64                                <Material diffuseColor='0.2 0.2 0.8'/>
 65                           </Appearance>
 66                      </Shape>
 67 
                    <!-- ROUTE information for SensorButton3 node:  [from isActive to Filter3.set_boolean ] -->
                    <TouchSensor DEF='SensorButton3description='Blue background'/>
 68                 </Transform>
 69 
               <!-- ROUTE information for Filter3 node:  [from SensorButton3.isActive to set_boolean ] [from activated to BackgroundBluish.set_bind ] -->
               <Script DEF='Filter3'>
 70                      <field name='set_booleantype='SFBoolaccessType='inputOnly'
                     appinfo='filter input value'/>
 71                      <field name='activatedtype='SFBoolaccessType='outputOnly'
                     appinfo='activated provides a persistent binding value otherwise isActive events will toggle Background binding on/off.'/>
 72                      <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
}

      
]]>
 74                 </Script>
 75                 < ROUTE  fromNode='SensorButton3' fromField='isActive' toNode='Filter3' toField='set_boolean'/>
 76                 < ROUTE  fromNode='Filter3' fromField='activated' toNode='BackgroundBluish' toField='set_bind'/>
 77                 <Transform translation='0 -3 0'>
 78                      <Shape>
 79                           <Text string='"Click on a Shape to change a Background," "Open player console to see trace statements."'>
 80                                <FontStyle justify='"MIDDLE" "MIDDLE"size='0.6'/>
 81                           </Text>
 82                           <Appearance>
 83                                <Material diffuseColor='0.7 0.7 0.7'/>
 84                           </Appearance>
 85                      </Shape>
 86                 </Transform>
 87            </Group>
 88       </Scene>
 89  </X3D>
<!--

<!--
Event Graph ROUTE Table shows event connections.
-->

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

Index for Viewpoint node: Viewpoint_1
-->
X3D Tooltips element index: Appearance, Background, Box, Cone, field, FontStyle, Group, head, Material, meta, ROUTE, Scene, Script, Shape, Sphere, Text, TouchSensor, Transform, Viewpoint, WorldInfo, X3D, accessType and type, XML data types, field types

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

Additional guidance on X3D animation can be found in the 10-Step Animation Design Process and Event Tracing hint sheets. Have fun with X3D! 😀

-->
<!-- 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. -->