<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN" "https://www.web3d.org/specifications/x3d-3.3.dtd">
<X3D profile='Immersive'  version='3.3 xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation =' https://www.web3d.org/specifications/x3d-3.3.xsd ' >
<head>
<meta name='titlecontent=' ScriptComplexStateEvents.x3d '/>
<meta name='descriptioncontent='A lamp with 4 intensities (off low medium high) and a push-button switcher, all controlled by a Script node.'/>
<meta name='creatorcontent='Leonard Daly and Don Brutzman'/>
<meta name='createdcontent='10 June 2006'/>
<meta name='modifiedcontent='20 October 2019'/>
<meta name='referencecontent=' https://X3dGraphics.com '/>
<meta name='referencecontent=' https://www.web3d.org/x3d/content/examples/X3dResources.html '/>
<meta name='rightscontent='Copyright 2006, Daly Realism and Don Brutzman'/>
<meta name='subjectcontent=' X3D book, X3D graphics, X3D-Edit, http://www.x3dGraphics.com '/>
<meta name='identifiercontent=' https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter09EventUtilitiesScripting/ScriptComplexStateEvents.x3d '/>
<meta name='generatorcontent='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
<meta name='licensecontent=' ../license.html'/>
</head>
<!-- -->
<Scene>
<WorldInfo title='ScriptComplexStateEvents.x3d'/>
<Background skyColor='1 1 1'/>
<Viewpoint description='Control 3-way lamporientation='-0.993 0.101 -0.063 1.06position='0.06 3.63 2.29'/>
<Transform DEF='PushBoxtranslation='-2 0 0'>
<Transform DEF='ControlBox'>
<Shape>
<Appearance>
<Material diffuseColor='0 .8 0'/>
</Appearance>
<Box size='1 .5 1'/>
</Shape>
</Transform>
<!-- ROUTE information for ControlButton node:  [from ButtonMover.value_changed to translation ] -->
<Transform DEF='ControlButtontranslation='0 .25 0'>
<!-- ROUTE information for ButtonTouch node:  [from touchTime to ButtonTimer.startTime ] -->
<TouchSensor DEF='ButtonTouchdescription='Push button to change state'/>

<Shape>
<Appearance>
<Material diffuseColor='1 0 0'/>
</Appearance>
<Cylinder DEF='Buttonbottom='falseheight='.5radius='.25'/>
</Shape>
<!-- ROUTE information for ButtonMover node:  [from ButtonTimer.fraction_changed to set_fraction ] [from value_changed to ControlButton.translation ] -->
<PositionInterpolator DEF='ButtonMoverkey='0 .5 1keyValue='0 .25 0 0 .05 0 0 .25 0'/>

<!-- ROUTE information for ButtonTimer node:  [from ButtonTouch.touchTime to startTime ] [from fraction_changed to ButtonMover.set_fraction ] [from isActive to ControlScript.buttonMotionDone ] -->
<TimeSensor DEF='ButtonTimercycleInterval='.3stopTime='1'/>

< ROUTE  fromNode=' ButtonTouch' fromField='touchTime' toNode=' ButtonTimer' toField='startTime'/>
< ROUTE  fromNode=' ButtonTimer' fromField='fraction_changed' toNode=' ButtonMover' toField='set_fraction'/>
< ROUTE  fromNode=' ButtonMover' fromField='value_changed' toNode=' ControlButton' toField='translation'/>
</Transform>
</Transform>
<Transform DEF='Lamptranslation='1 0 0'>
<Transform DEF='Base'>
<Shape>
<Appearance>
<Material/>
</Appearance>
<Cylinder height='.5radius='.25'/>
</Shape>
</Transform>
<Transform DEF='Bulbtranslation='0 .5 0'>
<Shape>
<Appearance>
<!-- be sure to match initial color of script so that toggling is smooth and predictable -->
<!-- ROUTE information for LightBulbMaterial node:  [from ControlScript.lightBulbColor to diffuseColor ] -->
<Material DEF='LightBulbMaterialdiffuseColor='0.2 0.2 0.2'/>
</Appearance>
<Sphere radius='.5'/>
</Shape>
</Transform>
</Transform>
<field name='buttonMotionDonetype='SFBoolaccessType='inputOnly'/>
<field name='buttonPushCounttype='SFInt32value='0accessType='inputOutput'
 appinfo='the buttonPushCount value toggles 0..1..2..3 to represent four states, off/low/medium/high' />

<field name='lightBulbColortype='SFColoraccessType='outputOnly'
 appinfo='color of lightBulb indicates off/low/medium/high' />
</Script>
< ROUTE  fromNode=' ButtonTimer' fromField='isActive' toNode=' ControlScript' toField='buttonMotionDone'/>
< ROUTE  fromNode=' ControlScript' fromField='lightBulbColor' toNode=' LightBulbMaterial' toField='diffuseColor'/>
<Transform translation='-1 -2 0'>
<Billboard axisOfRotation='0 0 0'>
<!-- ROUTE information for TextSwitch node:  [from ControlScript.buttonPushCount to whichChoice ] -->
<Switch DEF='TextSwitchwhichChoice='0'>
<!-- States: 0=Off, 1=Low, 2=Medium, 3=High -->
<Shape>
<Text string='"Off"'>
<FontStyle DEF='TextStylefamily='"SANS"justify='"BEGIN" "MIDDLE"style='BOLD'/>
</Text>
<Appearance DEF='OffAppearance'>
<Material diffuseColor='0.6 0.6 0.6'/>
</Appearance>
</Shape>
<Shape>
<Text string='"Low"'>
<FontStyle USE=' TextStyle'/>
</Text>
<Appearance DEF='LowAppearance'>
<Material diffuseColor='1 0.6 0.6'/>
</Appearance>
</Shape>
<Shape>
<Text string='"Medium"'>
<FontStyle USE=' TextStyle'/>
</Text>
<Appearance DEF='MediumAppearance'>
<Material diffuseColor='0.6 1 0.6'/>
</Appearance>
</Shape>
<Shape>
<Text string='"High"'>
<FontStyle USE=' TextStyle'/>
</Text>
<Appearance DEF='HighAppearance'>
<Material diffuseColor='0.6 0.6 1'/>
</Appearance>
</Shape>
</Switch>
</Billboard>
</Transform>
< ROUTE  fromNode=' ControlScript' fromField='buttonPushCount' toNode=' TextSwitch' toField='whichChoice'/>
</Scene>
</X3D>
<!--

to top <!-- Event Graph ROUTE Table shows event connections -->
 
<!-- Index for DEF nodes: Base, Bulb, Button, ButtonMover, ButtonTimer, ButtonTouch, ControlBox, ControlButton, ControlScript, HighAppearance, Lamp, LightBulbMaterial, LowAppearance, MediumAppearance, OffAppearance, PushBox, TextStyle, TextSwitch

Index for Viewpoint node: Viewpoint_1
-->

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.

ButtonTouch
TouchSensor
touchTime
SFTime

ROUTE
event to
(1)
ButtonTimer
TimeSensor
startTime
SFTime

 
 
then
ButtonTimer
TimeSensor
fraction_changed
SFFloat

ROUTE
event to
(2)
ButtonMover
PositionInterpolator
set_fraction
SFFloat

 
 
then
ButtonMover
PositionInterpolator
value_changed
SFVec3f

ROUTE
event to
(3)
ControlButton
Transform
translation
SFVec3f
 
 
 
then
ButtonTimer
TimeSensor
isActive
SFBool

ROUTE
event to
(2)
ControlScript
Script
buttonMotionDone
SFBool

 
 
then
ControlScript
Script
buttonPushCount
SFInt32

ROUTE
event to
(3)
TextSwitch
Switch
whichChoice
SFInt32
 
 
 
then
ControlScript
Script
lightBulbColor
SFColor

ROUTE
event to
(3)
LightBulbMaterial
Material
diffuseColor
SFColor



-->

<!-- Online at
https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter09EventUtilitiesScripting/ScriptComplexStateEventsIndex.html -->
<!-- Version control at
https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter09EventUtilitiesScripting/ScriptComplexStateEvents.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. -->