| 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='title' content=' Figure30_2ScriptBackgroundSelect.x3d '/> |
| 6 | <meta name='creator' content='Figure 30.2, The VRML 2.0 Sourcebook, Copyright [1997] By Andrea L. Ames, David R. Nadeau, and John L. Moreland'/> |
| 7 | <meta name='reference' content=' http://www.wiley.com/legacy/compbooks/vrml2sbk/ch30/30fig02.htm '/> |
| 8 | <meta name='translator' content='Don Brutzman'/> |
| 9 | <meta name='created' content='2 September 2000'/> |
| 10 | <meta name='modified' content='20 October 2019'/> |
| 11 | <meta name='description' content='Click on a geometric Shape to change the scene Background. A Script node controls the state changes.'/> |
| 12 | <meta name='identifier' content=' https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter30Scripts/Figure30_2ScriptBackgroundSelect.x3d '/> |
| 13 | <meta name='generator' content='X3D-Edit 3.3, https://www.web3d.org/x3d/tools/X3D-Edit'/> |
| 14 | <meta name='license' content='../../license.html'/> |
| 15 | </head> |
| 16 | <Scene> |
| 17 | <WorldInfo title='Figure30_2ScriptBackgroundSelect.x3d'/> |
| 18 | <Viewpoint description='Background select' orientation='1 0 0 -0.2' position='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-ish' groundAngle='1.309 1.570796' groundColor='0.1 0.1 0 0.4 0.25 0.2 0.6 0.6 0.6' skyAngle='1.309 1.571' skyColor='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='BackgroundReddish' groundAngle='1.309 1.570796' groundColor='0.1 0.1 0 0.5 0.25 0.2 0.6 0.6 0.2' skyAngle='1.309 1.571' skyColor='1 0 0 1 0.4 0 1 1 0'/> |
| 24 |
<!-- ROUTE information for BackgroundBluish node:
[from Filter3.activated to set_bind
]
-->
<Background DEF='BackgroundBluish' groundAngle='1.309 1.570796' groundColor='0 0 0.1 0 0.1 0.3 0.3 0.3 0.6' skyAngle='1.309 1.571' skyColor='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='SensorButton1' description='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_boolean' type='SFBool' accessType='inputOnly'
appinfo='filter input value'/> |
| 37 |
<field name='activated' type='SFBool' accessType='outputOnly'
appinfo='activated provides a persistent binding value otherwise isActive events will toggle Background binding on/off.'/> |
| 38 |
<field name='count' type='SFInt32' value='1' accessType='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='SensorButton2' description='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_boolean' type='SFBool' accessType='inputOnly'
appinfo='filter input value'/> |
| 54 |
<field name='activated' type='SFBool' accessType='outputOnly'
appinfo='activated provides a persistent binding value otherwise isActive events will toggle Background binding on/off.'/> |
| 55 |
<field name='count' type='SFInt32' value='1' accessType='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='SensorButton3' description='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_boolean' type='SFBool' accessType='inputOnly'
appinfo='filter input value'/> |
| 71 |
<field name='activated' type='SFBool' accessType='outputOnly'
appinfo='activated provides a persistent binding value otherwise isActive events will toggle Background binding on/off.'/> |
| 72 |
<field name='count' type='SFInt32' value='1' accessType='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 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 |
Filter1
Script set_boolean SFBool |
then
|
Filter1
Script activated SFBool |
BackgroundCyan-ish
Background set_bind SFBool |
|
SensorButton2
TouchSensor isActive SFBool |
Filter2
Script set_boolean SFBool |
then
|
Filter2
Script activated SFBool |
BackgroundReddish
Background set_bind SFBool |
|
SensorButton3
TouchSensor isActive SFBool |
Filter3
Script set_boolean SFBool |
then
|
Filter3
Script activated SFBool |
BackgroundBluish
Background set_bind SFBool |
|
Filter1
Script activated SFBool |
BackgroundCyan-ish
Background set_bind SFBool |
<!--
Color-coding 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)
-->
<!--
For additional help information about X3D scenes, please see X3D Tooltips, X3D Resources, and X3D Scene Authoring Hints.
-->