| 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_3ScriptSoundActivate.x3d '/> |
| 6 | <meta name='creator' content='Figure 30.3, 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/30fig03.htm '/> |
| 8 | <meta name='translator' content='Don Brutzman'/> |
| 9 | <meta name='created' content='29 October 2000'/> |
| 10 | <meta name='modified' content='20 October 2019'/> |
| 11 | <meta name='description' content='A pair of filter scripts used to create a toggle on-off switch.'/> |
| 12 | <meta name='identifier' content=' https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter30Scripts/Figure30_3ScriptSoundActivate.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_3ScriptSoundActivate.x3d'/> |
| 18 | <Viewpoint description='toggle sound by clicking ball'/> |
| 19 | <Viewpoint description='move left spatialize right' position='-5 0 10'/> |
| 20 | <Viewpoint description='move right spatialize left' position='5 0 10'/> |
| 21 | <Viewpoint description='outside maximum attenuation ellipsoid' position='0 0 30'/> |
| 22 | <NavigationInfo type='"NONE"'/> |
| 23 | <!-- Background nodes are usually best placed at the top of the scene since they have global effect and are bindable nodes. --> |
| 24 | <Background 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'/> |
| 25 | <Group> |
| 26 |
<!-- ROUTE information for Touch node:
[from isActive to ToggleScript.toggle
]
-->
<TouchSensor DEF='Touch' description='touch to toggle audio'/> |
| 27 | <Shape> |
| 28 | <Sphere/> |
| 29 | <Appearance> |
| 30 | <Material diffuseColor='1 0.3 0.3'/> |
| 31 | </Appearance> |
| 32 | </Shape> |
| 33 | <Sound maxBack='15' maxFront='15' minBack='5' minFront='5'> |
| 34 |
<!-- ROUTE information for Audio node:
[from TimeFilter.startEventTime to set_startTime
]
[from TimeFilter.stopEventTime to set_stopTime
]
-->
<AudioClip DEF='Audio' description='willow1' loop='true' url=' "../Chapter24Sound/willow1.wav" "https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter24Sound/willow1.wav" '/> |
| 35 | </Sound> |
| 36 |
<!-- ROUTE information for ToggleScript node:
[from Touch.isActive to toggle
]
[from stateTurnedTrue to TimeFilter.setStart
]
[from stateTurnedFalse to TimeFilter.setStop
]
-->
<Script DEF='ToggleScript'> |
| 37 | <field name='toggle' type='SFBool' accessType='inputOnly'/> |
| 38 | <field name='state' type='SFBool' value='true' accessType='initializeOnly'/> |
| 39 | <field name='stateTurnedTrue' type='SFBool' accessType='outputOnly'/> |
| 40 | <field name='stateTurnedFalse' type='SFBool' accessType='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);
}
}
]]>
|
|
| 42 | </Script> |
| 43 |
<!-- ROUTE information for TimeFilter node:
[from ToggleScript.stateTurnedTrue to setStart
]
[from ToggleScript.stateTurnedFalse to setStop
]
[from startEventTime to Audio.set_startTime
]
[from stopEventTime to Audio.set_stopTime
]
-->
<Script DEF='TimeFilter'> |
| 44 | <field name='setStart' type='SFBool' accessType='inputOnly'/> |
| 45 | <field name='setStop' type='SFBool' accessType='inputOnly'/> |
| 46 | <field name='startEventTime' type='SFTime' accessType='outputOnly'/> |
| 47 | <field name='stopEventTime' type='SFTime' accessType='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
}
]]>
|
|
| 49 | </Script> |
| 50 | < ROUTE fromNode='Touch' fromField='isActive' toNode='ToggleScript' toField='toggle'/> |
| 51 | < ROUTE fromNode='ToggleScript' fromField='stateTurnedTrue' toNode='TimeFilter' toField='setStart'/> |
| 52 | < ROUTE fromNode='ToggleScript' fromField='stateTurnedFalse' toNode='TimeFilter' toField='setStop'/> |
| 53 | < ROUTE fromNode='TimeFilter' fromField='startEventTime' toNode='Audio' toField='set_startTime'/> |
| 54 | < ROUTE fromNode='TimeFilter' fromField='stopEventTime' toNode='Audio' toField='set_stopTime'/> |
| 55 | <!-- extra widget --> |
| 56 | <Transform translation='0 2.5 0'> |
| 57 | <!-- Selectable Text design pattern has transparent Box and TouchSensor description as a tooltip --> |
| 58 | <Shape> |
| 59 | <Text string='"toggle sound" "by clicking ball"'> |
| 60 | <FontStyle family='"SANS"' justify='"MIDDLE" "MIDDLE"' size='0.8' style='BOLD'/> |
| 61 | </Text> |
| 62 | <Appearance> |
| 63 | <Material diffuseColor='0.9 0.9 0.9'/> |
| 64 | </Appearance> |
| 65 | </Shape> |
| 66 | </Transform> |
| 67 | </Group> |
| 68 | <!-- Semitransparent sphere matching maxFront-MaxBack attenuation ellipsoid --> |
| 69 | <Shape> |
| 70 | <Appearance DEF='TransparentAppearance'> |
| 71 | <Material diffuseColor='0.5 0 0' transparency='0.7'/> |
| 72 | </Appearance> |
| 73 | <Sphere radius='15'/> |
| 74 | </Shape> |
| 75 | </Scene> |
| 76 | </X3D> |
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 |
ToggleScript
Script toggle SFBool |
then
|
ToggleScript
Script stateTurnedFalse SFBool |
TimeFilter
Script setStop SFBool |
then
|
TimeFilter
Script startEventTime SFTime |
Audio
AudioClip set_startTime SFTime |
|||
|
then
|
TimeFilter
Script stopEventTime SFTime |
Audio
AudioClip set_stopTime SFTime |
||||||||
|
then
|
ToggleScript
Script stateTurnedTrue SFBool |
TimeFilter
Script setStart SFBool |
then
|
TimeFilter
Script startEventTime SFTime |
Audio
AudioClip set_startTime SFTime |
|||||
|
then
|
TimeFilter
Script stopEventTime SFTime |
Audio
AudioClip set_stopTime SFTime |
||||||||
<!--
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.
-->