X3D Model Documentation: Figure30_3ScriptSoundActivate.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_3ScriptSoundActivate.x3d'/>
  6            <meta name='creatorcontent='Figure 30.3, 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/30fig03.htm'/>
  8            <meta name='translatorcontent='Don Brutzman'/>
  9            <meta name='createdcontent='29 October 2000'/>
 10            <meta name='modifiedcontent='20 October 2019'/>
 11            <meta name='descriptioncontent='A pair of filter scripts used to create a toggle on-off switch.'/>
 12            <meta name='identifiercontent='https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter30Scripts/Figure30_3ScriptSoundActivate.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: Audio, TimeFilter, ToggleScript, Touch, TransparentAppearance

Index for Viewpoint nodes: Viewpoint_1, Viewpoint_2, Viewpoint_3, Viewpoint_4
-->
 16       <Scene>
 17            <WorldInfo title='Figure30_3ScriptSoundActivate.x3d'/>
 18            <Viewpoint description='toggle sound by clicking ball'/>
 19            <Viewpoint description='move left spatialize rightposition='-5 0 10'/>
 20            <Viewpoint description='move right spatialize leftposition='5 0 10'/>
 21            <Viewpoint description='outside maximum attenuation ellipsoidposition='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.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'/>
 25            <Group>
 26 
               <!-- ROUTE information for Touch node:  [from isActive to ToggleScript.toggle ] -->
               <TouchSensor DEF='Touchdescription='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='15maxFront='15minBack='5minFront='5'>
 34 
                    <!-- ROUTE information for Audio node:  [from TimeFilter.startEventTime to set_startTime ] [from TimeFilter.stopEventTime to set_stopTime ] -->
                    <AudioClip DEF='Audiodescription='willow1loop='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='toggletype='SFBoolaccessType='inputOnly'/>
 38                      <field name='statetype='SFBoolvalue='trueaccessType='initializeOnly'/>
 39                      <field name='stateTurnedTruetype='SFBoolaccessType='outputOnly'/>
 40                      <field name='stateTurnedFalsetype='SFBoolaccessType='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 
 44                      <field name='setStarttype='SFBoolaccessType='inputOnly'/>
 45                      <field name='setStoptype='SFBoolaccessType='inputOnly'/>
 46                      <field name='startEventTimetype='SFTimeaccessType='outputOnly'/>
 47                      <field name='stopEventTimetype='SFTimeaccessType='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.8style='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 0transparency='0.7'/>
 72                 </Appearance>
 73                 <Sphere radius='15'/>
 74            </Shape>
 75       </Scene>
 76  </X3D>
<!--

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

<!-- to top Index for DEF nodes: Audio, TimeFilter, ToggleScript, Touch, TransparentAppearance

Index for Viewpoint nodes: Viewpoint_1, Viewpoint_2, Viewpoint_3, Viewpoint_4
-->
X3D Tooltips element index: Appearance, AudioClip, Background, field, FontStyle, Group, head, Material, meta, NavigationInfo, ROUTE, Scene, Script, Shape, Sound, Sphere, Text, TouchSensor, Transform, Viewpoint, WorldInfo, X3D, accessType and type, XML data types, field types

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

ROUTE
event to
(1)
ToggleScript
Script
toggle
SFBool
then
 
 
 
ToggleScript
Script
stateTurnedFalse
SFBool

ROUTE
event to
(2)
TimeFilter
Script
setStop
SFBool
then
 
 
 
TimeFilter
Script
startEventTime
SFTime

ROUTE
event to
(3)
Audio
AudioClip
set_startTime
SFTime
  then
 
 
 
TimeFilter
Script
stopEventTime
SFTime

ROUTE
event to
(3)
Audio
AudioClip
set_stopTime
SFTime
  then
 
 
 
ToggleScript
Script
stateTurnedTrue
SFBool

ROUTE
event to
(2)
TimeFilter
Script
setStart
SFBool
then
 
 
 
TimeFilter
Script
startEventTime
SFTime

ROUTE
event to
(3)
Audio
AudioClip
set_startTime
SFTime
  then
 
 
 
TimeFilter
Script
stopEventTime
SFTime

ROUTE
event to
(3)
Audio
AudioClip
set_stopTime
SFTime

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