1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN" "https://www.web3d.org/specifications/x3d-3.3.dtd">
|
3 | <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'> |
4 | <head> |
5 | <meta name='title' content='ScriptComplexStateEvents.x3d'/> |
6 | <meta name='description' content='A lamp with 4 intensities (off low medium high) and a push-button switcher, all controlled by a Script node.'/> |
7 | <meta name='creator' content='Leonard Daly and Don Brutzman'/> |
8 | <meta name='created' content='10 June 2006'/> |
9 | <meta name='modified' content='20 October 2019'/> |
10 | <meta name='reference' content='https://X3dGraphics.com'/> |
11 | <meta name='reference' content='https://www.web3d.org/x3d/content/examples/X3dResources.html'/> |
12 | <meta name='rights' content='Copyright 2006, Daly Realism and Don Brutzman'/> |
13 | <meta name='subject' content='X3D book, X3D graphics, X3D-Edit, http://www.x3dGraphics.com'/> |
14 | <meta name='identifier' content='https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter09EventUtilitiesScripting/ScriptComplexStateEvents.x3d'/> |
15 | <meta name='generator' content='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/> |
16 | <meta name='license' content='../license.html'/> |
17 | </head> |
18 | <Scene> |
19 | <WorldInfo title='ScriptComplexStateEvents.x3d'/> |
20 | <Background skyColor='1 1 1'/> |
21 | <Viewpoint description='Control 3-way lamp' orientation='-0.993 0.101 -0.063 1.06' position='0.06 3.63 2.29'/> |
22 | <Transform DEF='PushBox' translation='-2 0 0'> |
23 | <Transform DEF='ControlBox'> |
24 | <Shape> |
25 | <Appearance> |
26 | <Material diffuseColor='0 .8 0'/> |
27 | </Appearance> |
28 | <Box size='1 .5 1'/> |
29 | </Shape> |
30 | </Transform> |
31 |
<!-- ROUTE information for ControlButton node:
[from ButtonMover.value_changed to translation
]
-->
<Transform DEF='ControlButton' translation='0 .25 0'> |
32 |
<!-- ROUTE information for ButtonTouch node:
[from touchTime to ButtonTimer.startTime
]
-->
<TouchSensor DEF='ButtonTouch' description='Push button to change state'/> |
33 | <Shape> |
34 | <Appearance> |
35 | <Material diffuseColor='1 0 0'/> |
36 | </Appearance> |
37 | <Cylinder DEF='Button' bottom='false' height='.5' radius='.25'/> |
38 | </Shape> |
39 |
<!-- ROUTE information for ButtonMover node:
[from ButtonTimer.fraction_changed to set_fraction
]
[from value_changed to ControlButton.translation
]
-->
<PositionInterpolator DEF='ButtonMover' key='0 .5 1' keyValue='0 .25 0 0 .05 0 0 .25 0'/> |
40 |
<!-- ROUTE information for ButtonTimer node:
[from ButtonTouch.touchTime to startTime
]
[from fraction_changed to ButtonMover.set_fraction
]
[from isActive to ControlScript.buttonMotionDone
]
-->
<TimeSensor DEF='ButtonTimer' cycleInterval='.3' stopTime='1'/> |
41 | < ROUTE fromNode='ButtonTouch' fromField='touchTime' toNode='ButtonTimer' toField='startTime'/> |
42 | < ROUTE fromNode='ButtonTimer' fromField='fraction_changed' toNode='ButtonMover' toField='set_fraction'/> |
43 | < ROUTE fromNode='ButtonMover' fromField='value_changed' toNode='ControlButton' toField='translation'/> |
44 | </Transform> |
45 | </Transform> |
46 | <Transform DEF='Lamp' translation='1 0 0'> |
47 | <Transform DEF='Base'> |
48 | <Shape> |
49 | <Appearance> |
50 | <Material/> |
51 | </Appearance> |
52 | <Cylinder height='.5' radius='.25'/> |
53 | </Shape> |
54 | </Transform> |
55 | <Transform DEF='Bulb' translation='0 .5 0'> |
56 | <Shape> |
57 | <Appearance> |
58 | <!-- be sure to match initial color of script so that toggling is smooth and predictable --> |
59 |
<!-- ROUTE information for LightBulbMaterial node:
[from ControlScript.lightBulbColor to diffuseColor
]
-->
<Material DEF='LightBulbMaterial' diffuseColor='0.2 0.2 0.2'/> |
60 | </Appearance> |
61 | <Sphere radius='.5'/> |
62 | </Shape> |
63 | </Transform> |
64 | </Transform> |
65 |
<!-- ROUTE information for ControlScript node:
[from ButtonTimer.isActive to buttonMotionDone
]
[from lightBulbColor to LightBulbMaterial.diffuseColor
]
[from buttonPushCount to TextSwitch.whichChoice
]
-->
<Script DEF='ControlScript' url=' "ScriptComplexStateEvents.js" "https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter09EventUtilitiesScripting/ScriptComplexStateEvents.js" '> |
66 | <field name='buttonMotionDone' type='SFBool' accessType='inputOnly'/> |
67 |
<field name='buttonPushCount' type='SFInt32' value='0' accessType='inputOutput'
appinfo='the buttonPushCount value toggles 0..1..2..3 to represent four states, off/low/medium/high'/> |
68 |
<field name='lightBulbColor' type='SFColor' accessType='outputOnly'
appinfo='color of lightBulb indicates off/low/medium/high'/> |
69 | </Script> |
70 | < ROUTE fromNode='ButtonTimer' fromField='isActive' toNode='ControlScript' toField='buttonMotionDone'/> |
71 | < ROUTE fromNode='ControlScript' fromField='lightBulbColor' toNode='LightBulbMaterial' toField='diffuseColor'/> |
72 | <Transform translation='-1 -2 0'> |
73 | <Billboard axisOfRotation='0 0 0'> |
74 |
<!-- ROUTE information for TextSwitch node:
[from ControlScript.buttonPushCount to whichChoice
]
-->
<Switch DEF='TextSwitch' whichChoice='0'> |
75 | <!-- States: 0=Off, 1=Low, 2=Medium, 3=High --> |
76 | <Shape> |
77 | <Text string='"Off"'> |
78 | |
79 | </Text> |
80 | <Appearance DEF='OffAppearance'> |
81 | <Material diffuseColor='0.6 0.6 0.6'/> |
82 | </Appearance> |
83 | </Shape> |
84 | <Shape> |
85 | <Text string='"Low"'> |
86 | <FontStyle USE='TextStyle'/> |
87 | </Text> |
88 | <Appearance DEF='LowAppearance'> |
89 | <Material diffuseColor='1 0.6 0.6'/> |
90 | </Appearance> |
91 | </Shape> |
92 | <Shape> |
93 | <Text string='"Medium"'> |
94 | <FontStyle USE='TextStyle'/> |
95 | </Text> |
96 | <Appearance DEF='MediumAppearance'> |
97 | <Material diffuseColor='0.6 1 0.6'/> |
98 | </Appearance> |
99 | </Shape> |
100 | <Shape> |
101 | <Text string='"High"'> |
102 | <FontStyle USE='TextStyle'/> |
103 | </Text> |
104 | <Appearance DEF='HighAppearance'> |
105 | <Material diffuseColor='0.6 0.6 1'/> |
106 | </Appearance> |
107 | </Shape> |
108 | </Switch> |
109 | </Billboard> |
110 | </Transform> |
111 | < ROUTE fromNode='ControlScript' fromField='buttonPushCount' toNode='TextSwitch' toField='whichChoice'/> |
112 | </Scene> |
113 | </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.
ButtonTouch
TouchSensor touchTime SFTime |
ButtonTimer
TimeSensor startTime SFTime |
then
|
ButtonTimer
TimeSensor fraction_changed SFFloat |
ButtonMover
PositionInterpolator set_fraction SFFloat |
then
|
ButtonMover
PositionInterpolator value_changed SFVec3f |
ControlButton
Transform translation SFVec3f |
|||
then
|
ButtonTimer
TimeSensor isActive SFBool |
ControlScript
Script buttonMotionDone SFBool |
then
|
ControlScript
Script buttonPushCount SFInt32 |
TextSwitch
Switch whichChoice SFInt32 |
|||||
then
|
ControlScript
Script lightBulbColor SFColor |
LightBulbMaterial
Material diffuseColor SFColor |
<!--
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)
-->
<!-- For additional help information about X3D scenes, please see X3D Tooltips, X3D Resources, and X3D Scene Authoring Hints. -->