X3D Model Documentation: ScriptEvents.x3d

  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='titlecontent='ScriptEvents.x3d'/>
  6            <meta name='descriptioncontent='A Script node drives the position and orientation of orbiting cones near the pump house.'/>
  7            <meta name='creatorcontent='Todd Gagnon and Mark A. Boyd'/>
  8            <meta name='translatorcontent='Xeena VRML importer, X3D-Edit 3.1, https://www.web3d.org/x3d/content/README.X3D-Edit.html'/>
  9            <meta name='createdcontent='8 June 1998'/>
 10            <meta name='translatedcontent='20 December 2002'/>
 11            <meta name='modifiedcontent='20 October 2019'/>
 12            <meta name='referencecontent='KelpTank.x3d'/>
 13            <meta name='referencecontent='https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/KelpForestExhibit/PumpHouse.x3d'/>
 14            <meta name='identifiercontent='https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter09EventUtilitiesScripting/ScriptEvents.x3d'/>
 15            <meta name='generatorcontent='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
 16            <meta name='generatorcontent='Vrml97ToX3dNist, http://ovrt.nist.gov/v2_x3d.html'/>
 17            <meta name='licensecontent='../license.html'/>
 18       </head>
<!--

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

<!-- to top Index for DEF nodes: AngleGenerator, b1, ControlScript, CylinderRod, GreenTransform, PistonClock, PistonPath, PistonTransform, PumpHouseAppearance, PumpTouched, RedTransform, Rocker1Path, Rocker1Rotation, Rocker2Path, Rocker2Rotation, RockerArm1, RockerArm2, SpinAngleTimer, ThreeCones, TouchFilter, TurquoiseTransform

Index for Viewpoint nodes: Viewpoint_1, Viewpoint_2
-->
 19       <Scene>
 20            <WorldInfo title='ScriptEvents.x3d'/>
 21            <Background skyColor='1 1 1'/>
 22            <Viewpoint description='click pump house to spin conesposition='3 1 7'/>
 23            <Viewpoint description='Book Vieworientation='-0.969 0.239 0.056 0.13position='1.66 1.34 5.95'/>
 24            <Group>
 25                 <Transform scale='0.91 0.6 0.3translation='0.8 -0.65 0.5'>
 26                      <Shape>
 27                           <Appearance>
 28                                <Material diffuseColor='0.749 0.694 0.651'/>
 29                           </Appearance>
 30                           <Cylinder bottom='falsetop='false'/>
 31                      </Shape>
 32                 </Transform>
 33                 <Group>
 34                      <Shape>
 35 
                         <!-- Appearance PumpHouseAppearance is a DEF node that has 6 USE nodes: USE_1, USE_2, USE_3, USE_4, USE_5, USE_6 -->
                         <Appearance DEF='PumpHouseAppearance'>
 36                                <Material diffuseColor='0.82 0.78 0.74'/>
 37                           </Appearance>
 38                           <IndexedFaceSet coordIndex='0 1 5 4 -1 5 1 2 6 -1 6 2 3 7 -1 3 0 4 7 -1 1 12 13 2 -1 2 13 14 -1 12 15 16 13 -1 15 0 3 16 -1 16 3 17 -1 9 5 6 10 -1 8 9 10 11 -1 4 8 11 7 -1 4 5 9 8 -1 11 10 6 7 -1 3 2 14 17 -1 13 16 17 14 -1'>
 39                                <Coordinate point='0.0 0.0 0.0 2.0 0.0 0.0 2.0 1.75 0.0 0.0 1.75 0.0 0.625 0.75 0.0 1.0 0.75 0.0 1.0 1.6 0.0 0.625 1.6 0.0 0.625 0.75 -0.65 1.0 0.75 -0.65 1.0 1.6 -0.65 0.625 1.6 -0.65 2.0 0.0 -2.7 2.0 1.75 -2.7 2.0 2.5 -1.0 0.0 0.0 -2.7 0.0 1.75 -2.7 0.0 2.5 -1.0'/>
 40                           </IndexedFaceSet>
 41                      </Shape>
 42 
                    <!-- ROUTE information for PumpTouched node:  [from isActive to TouchFilter.set_boolean ] -->
                    <TouchSensor DEF='PumpToucheddescription='touch to activate'/>
 43                 </Group>
 44            </Group>
 45            <Group>
 46                 <Transform scale='0.5 0.5 0.5translation='1.0 1.1 -1.5'>
 47 
                    <!-- ROUTE information for PistonTransform node:  [from PistonPath.value_changed to set_translation ] -->
                    <Transform DEF='PistonTransform'>
 48                           <Transform scale='1.8 1.2 0.6translation='0.0 -0.2 0.0'>
 49                                <Shape>
 50                                     <Appearance>
 51                                          <Material diffuseColor='0.427 0.427 0.42'/>
 52                                     </Appearance>
 53                                     <Cylinder height='1.0radius='0.98'/>
 54                                </Shape>
 55                           </Transform>
 56 
                         <!-- Transform CylinderRod is a DEF node that has 1 USE node: USE_1 -->
                         <Transform DEF='CylinderRodrotation='0.0 0.0 -1.0 0.523599translation='-0.25 0.75 0.0'>
 57                                <Shape>
 58                                     <Appearance USE='PumpHouseAppearance'/>
 59                                     <Cylinder height='1.0radius='0.1'/>
 60                                </Shape>
 61                           </Transform>
 62                           <Transform rotation='0.0 0.0 1.0 1.047198translation='1.0 0.6 0.0'>
 63                                <Transform USE='CylinderRod'/>
 64                           </Transform>
 65                           <Transform translation='0.0 1.2 0.0'>
 66                                <Shape>
 67                                     <Appearance USE='PumpHouseAppearance'/>
 68                                     <Sphere radius='0.15'/>
 69                                </Shape>
 70                           </Transform>
 71 
                         <!-- ROUTE information for RockerArm1 node:  [from Rocker1Path.value_changed to set_translation ] [from Rocker1Rotation.value_changed to set_rotation ] -->
                         <Transform DEF='RockerArm1center='0.0 -0.4 0.0'>
 72                                <Shape>
 73                                     <Appearance USE='PumpHouseAppearance'/>
 74                                     <Cylinder height='1.8radius='0.1'/>
 75                                </Shape>
 76                                <Transform translation='0.0 0.95 0.0'>
 77                                     <Shape>
 78                                          <Appearance USE='PumpHouseAppearance'/>
 79                                          <Sphere radius='0.15'/>
 80                                     </Shape>
 81                                </Transform>
 82 
                              <!-- ROUTE information for Rocker1Path node:  [from PistonClock.fraction_changed to set_fraction ] [from value_changed to RockerArm1.set_translation ] -->
                              <PositionInterpolator DEF='Rocker1Pathkey='0.0 0.3 0.32 0.5 0.75 1.0keyValue='0.0 2.0 -0.25 0.0 1.8 -0.35 0.0 1.8 -0.35 0.0 2.0 -0.25 0.0 2.0 -0.12 0.0 2.0 -0.25'/>
 83 
                              <!-- ROUTE information for Rocker1Rotation node:  [from PistonClock.fraction_changed to set_fraction ] [from value_changed to RockerArm1.set_rotation ] -->
                              <OrientationInterpolator DEF='Rocker1Rotationkey='0.0 0.3 0.32 0.5 0.75 1.0keyValue='-1.0 0.0 0.0 0.523599 -1.0 0.0 0.0 1.0471976 -1.0 0.0 0.0 1.0471976 -1.0 0.0 0.0 0.523599 -1.0 0.0 0.0 0.2617994 -1.0 0.0 0.0 0.523599'/>
 84                           </Transform>
 85 
                         <!-- ROUTE information for RockerArm2 node:  [from Rocker2Path.value_changed to set_translation ] [from Rocker2Rotation.value_changed to set_rotation ] -->
                         <Transform DEF='RockerArm2center='0.0 0.7 0.0'>
 86                                <Shape>
 87                                     <Appearance USE='PumpHouseAppearance'/>
 88                                     <Cylinder height='1.8radius='0.1'/>
 89                                </Shape>
 90                                <Transform translation='0.0 -0.95 0.0'>
 91                                     <Shape>
 92                                          <Appearance USE='PumpHouseAppearance'/>
 93                                          <Sphere radius='0.15'/>
 94                                     </Shape>
 95                                </Transform>
 96 
                              <!-- ROUTE information for Rocker2Path node:  [from PistonClock.fraction_changed to set_fraction ] [from value_changed to RockerArm2.set_translation ] -->
                              <PositionInterpolator DEF='Rocker2Pathkey='0.0 0.3 0.32 0.5 0.75 1.0keyValue='0.0 1.95 -1.0 0.0 1.2 -1.6 0.0 1.2 -1.6 0.0 1.95 -1.0 0.0 2.2 -0.65 0.0 1.95 -1.0'/>
 97 
                              <!-- ROUTE information for Rocker2Rotation node:  [from PistonClock.fraction_changed to set_fraction ] [from value_changed to RockerArm2.set_rotation ] -->
                              <OrientationInterpolator DEF='Rocker2Rotationkey='0.0 0.3 0.32 0.5 0.75 1.0keyValue='1.0 0.0 0.0 0.523599 1.0 0.0 0.0 0.4 1.0 0.0 0.0 0.4 1.0 0.0 0.0 0.523599 1.0 0.0 0.0 1.570796 1.0 0.0 0.0 0.523599'/>
 98                           </Transform>
 99                      </Transform>
100 
101 
                    <!-- ROUTE information for PistonPath node:  [from PistonClock.fraction_changed to set_fraction ] [from value_changed to PistonTransform.set_translation ] -->
                    <PositionInterpolator DEF='PistonPathkey='0.0 0.3 0.32 0.5 0.75 1.0keyValue='-0.4 -2.3 4.0 -0.4 -1.5 4.0 -0.4 -1.5 4.0 -0.4 -2.3 4.0 -0.4 -3.3 4.0 -0.4 -2.3 4.0'/>
102                      <Transform translation='3 2 4'>
103                           <Transform DEF='ThreeCones'>
104 
                              <!-- ROUTE information for RedTransform node:  [from ControlScript.positionRed to translation ] [from ControlScript.orientationRed to rotation ] -->
                              <Transform DEF='RedTransformrotation='0 0 1 3.14translation='0 -1.5 .5'>
105                                     <Shape>
106                                          <Appearance>
107                                               <Material diffuseColor='1 0 0'/>
108                                          </Appearance>
109 
                                        <!-- Cone b1 is a DEF node that has 2 USE nodes: USE_1, USE_2 -->
                                        <Cone DEF='b1bottomRadius='.5height='1'/>
110                                     </Shape>
111                                </Transform>
112 
                              <!-- ROUTE information for GreenTransform node:  [from ControlScript.positionGreen to translation ] [from ControlScript.orientationGreen to rotation ] -->
                              <Transform DEF='GreenTransformrotation='0 0 1 -1.05translation='1.3 .75 0'>
113                                     <Shape>
114                                          <Appearance>
115                                               <Material diffuseColor='0 1 1'/>
116                                          </Appearance>
117                                          <Cone USE='b1'/>
118                                     </Shape>
119                                </Transform>
120 
                              <!-- ROUTE information for TurquoiseTransform node:  [from ControlScript.positionTurquoise to translation ] [from ControlScript.orientationTurquoise to rotation ] -->
                              <Transform DEF='TurquoiseTransformrotation='0 0 1 1.05translation='-1.3 .75 -.5'>
121                                     <Shape>
122                                          <Appearance>
123                                               <Material diffuseColor='1 1 0'/>
124                                          </Appearance>
125                                          <Cone USE='b1'/>
126                                     </Shape>
127                                </Transform>
128                           </Transform>
129                      </Transform>
130 
131                           <field name='angletype='SFFloataccessType='inputOnly'/>
132                           <field name='positionRedtype='SFVec3faccessType='outputOnly'/>
133                           <field name='positionGreentype='SFVec3faccessType='outputOnly'/>
134                           <field name='positionTurquoisetype='SFVec3faccessType='outputOnly'/>
135                           <field name='orientationRedtype='SFRotationaccessType='outputOnly'/>
136                           <field name='orientationGreentype='SFRotationaccessType='outputOnly'/>
137                           <field name='orientationTurquoisetype='SFRotationaccessType='outputOnly'/>
  <![CDATA[
          
ecmascript:

//  this input function receives the currently interpolated rotation angle value,
//  and then computes the position and orientation of each of the cones.

function angle (value)
{
  positionRed       = new SFVec3f (Math.cos (value), 1.5 * Math.sin(value), 0.5);
  positionGreen     = new SFVec3f (Math.cos (value+2.094), 1.5 * Math.sin(value+2.094),    0);
  positionTurquoise = new SFVec3f (Math.cos (value+4.189), 1.5 * Math.sin(value+4.189), -0.5);

  // The values 2.094 and 4.189 are 1/3 and 2/3 of 2*pi radians.
  orientationRed       = new SFRotation (0, 0, 1, -2*value);
  orientationGreen     = new SFRotation (0, 0, 1, -2*(value+2.094));
  orientationTurquoise = new SFRotation (0, 0, 1, -2*(value+4.189));
}

        
]]>
139                      </Script>
140                 </Transform>
141            </Group>
142            <!-- Drive the Script inputs -->
143 
          <!-- ROUTE information for AngleGenerator node:  [from SpinAngleTimer.fraction_changed to set_fraction ] [from value_changed to ControlScript.angle ] -->
          <ScalarInterpolator DEF='AngleGeneratorkey='0 1keyValue='0 6.28319'/>
144            < ROUTE  fromNode='AngleGenerator' fromField='value_changed' toNode='ControlScript' toField='angle'/>
145 
          <!-- ROUTE information for SpinAngleTimer node:  [from TouchFilter.inputTrue to enabled ] [from fraction_changed to AngleGenerator.set_fraction ] -->
          <TimeSensor DEF='SpinAngleTimercycleInterval='2enabled='falseloop='truestartTime='1'/>
146            < ROUTE  fromNode='SpinAngleTimer' fromField='fraction_changed' toNode='AngleGenerator' toField='set_fraction'/>
147 
          <!-- ROUTE information for TouchFilter node:  [from PumpTouched.isActive to set_boolean ] [from inputTrue to SpinAngleTimer.enabled ] [from inputFalse to PistonClock.enabled ] -->
          <BooleanFilter DEF='TouchFilter'/>
148            < ROUTE  fromNode='PumpTouched' fromField='isActive' toNode='TouchFilter' toField='set_boolean'/>
149            < ROUTE  fromNode='TouchFilter' fromField='inputTrue' toNode='SpinAngleTimer' toField='enabled'/>
150            <!-- Script output converts angle timer into positions, orientations for spinning cones -->
151            < ROUTE  fromNode='ControlScript' fromField='positionRed' toNode='RedTransform' toField='translation'/>
152            < ROUTE  fromNode='ControlScript' fromField='positionGreen' toNode='GreenTransform' toField='translation'/>
153            < ROUTE  fromNode='ControlScript' fromField='positionTurquoise' toNode='TurquoiseTransform' toField='translation'/>
154            < ROUTE  fromNode='ControlScript' fromField='orientationRed' toNode='RedTransform' toField='rotation'/>
155            < ROUTE  fromNode='ControlScript' fromField='orientationGreen' toNode='GreenTransform' toField='rotation'/>
156            < ROUTE  fromNode='ControlScript' fromField='orientationTurquoise' toNode='TurquoiseTransform' toField='rotation'/>
157            <!-- Regular piston engine -->
158            < ROUTE  fromNode='TouchFilter' fromField='inputFalse' toNode='PistonClock' toField='enabled'/>
159            < ROUTE  fromNode='PistonClock' fromField='fraction_changed' toNode='PistonPath' toField='set_fraction'/>
160            < ROUTE  fromNode='PistonPath' fromField='value_changed' toNode='PistonTransform' toField='set_translation'/>
161            < ROUTE  fromNode='PistonClock' fromField='fraction_changed' toNode='Rocker1Path' toField='set_fraction'/>
162            < ROUTE  fromNode='Rocker1Path' fromField='value_changed' toNode='RockerArm1' toField='set_translation'/>
163            < ROUTE  fromNode='PistonClock' fromField='fraction_changed' toNode='Rocker1Rotation' toField='set_fraction'/>
164            < ROUTE  fromNode='Rocker1Rotation' fromField='value_changed' toNode='RockerArm1' toField='set_rotation'/>
165            < ROUTE  fromNode='PistonClock' fromField='fraction_changed' toNode='Rocker2Path' toField='set_fraction'/>
166            < ROUTE  fromNode='Rocker2Path' fromField='value_changed' toNode='RockerArm2' toField='set_translation'/>
167            < ROUTE  fromNode='PistonClock' fromField='fraction_changed' toNode='Rocker2Rotation' toField='set_fraction'/>
168            < ROUTE  fromNode='Rocker2Rotation' fromField='value_changed' toNode='RockerArm2' toField='set_rotation'/>
169       </Scene>
170  </X3D>
<!--

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

<!-- to top Index for DEF nodes: AngleGenerator, b1, ControlScript, CylinderRod, GreenTransform, PistonClock, PistonPath, PistonTransform, PumpHouseAppearance, PumpTouched, RedTransform, Rocker1Path, Rocker1Rotation, Rocker2Path, Rocker2Rotation, RockerArm1, RockerArm2, SpinAngleTimer, ThreeCones, TouchFilter, TurquoiseTransform

Index for Viewpoint nodes: Viewpoint_1, Viewpoint_2
-->
X3D Tooltips element index: Appearance, Background, BooleanFilter, Cone, Coordinate, Cylinder, field, Group, head, IndexedFaceSet, Material, meta, OrientationInterpolator, PositionInterpolator, ROUTE, ScalarInterpolator, Scene, Script, Shape, Sphere, TimeSensor, TouchSensor, Transform, Viewpoint, WorldInfo, X3D, accessType and type, XML data types, field types

Event Graph ROUTE Table entries with 21 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.

PumpTouched
TouchSensor
isActive
SFBool

ROUTE
event to
(1)
TouchFilter
BooleanFilter
set_boolean
SFBool
then
 
 
 
TouchFilter
BooleanFilter
inputFalse
SFBool

ROUTE
event to
(2)
PistonClock
TimeSensor
enabled
SFBool
then
 
 
 
PistonClock
TimeSensor
fraction_changed
SFFloat

ROUTE
event to
(3)
PistonPath
PositionInterpolator
set_fraction
SFFloat
then
 
 
 
PistonPath
PositionInterpolator
value_changed
SFVec3f

ROUTE
event to
(4)
PistonTransform
Transform
set_translation
SFVec3f
  then
 
 
 
PistonClock
TimeSensor
fraction_changed
SFFloat

ROUTE
event to
(3)
Rocker1Path
PositionInterpolator
set_fraction
SFFloat
then
 
 
 
Rocker1Path
PositionInterpolator
value_changed
SFVec3f

ROUTE
event to
(4)
RockerArm1
Transform
set_translation
SFVec3f
  then
 
 
 
PistonClock
TimeSensor
fraction_changed
SFFloat

ROUTE
event to
(3)
Rocker1Rotation
OrientationInterpolator
set_fraction
SFFloat
then
 
 
 
Rocker1Rotation
OrientationInterpolator
value_changed
SFRotation

ROUTE
event to
(4)
RockerArm1
Transform
set_rotation
SFRotation
  then
 
 
 
PistonClock
TimeSensor
fraction_changed
SFFloat

ROUTE
event to
(3)
Rocker2Path
PositionInterpolator
set_fraction
SFFloat
then
 
 
 
Rocker2Path
PositionInterpolator
value_changed
SFVec3f

ROUTE
event to
(4)
RockerArm2
Transform
set_translation
SFVec3f
  then
 
 
 
PistonClock
TimeSensor
fraction_changed
SFFloat

ROUTE
event to
(3)
Rocker2Rotation
OrientationInterpolator
set_fraction
SFFloat
then
 
 
 
Rocker2Rotation
OrientationInterpolator
value_changed
SFRotation

ROUTE
event to
(4)
RockerArm2
Transform
set_rotation
SFRotation
  then
 
 
 
TouchFilter
BooleanFilter
inputTrue
SFBool

ROUTE
event to
(2)
SpinAngleTimer
TimeSensor
enabled
SFBool
then
 
 
 
SpinAngleTimer
TimeSensor
fraction_changed
SFFloat

ROUTE
event to
(3)
AngleGenerator
ScalarInterpolator
set_fraction
SFFloat
then
 
 
 
AngleGenerator
ScalarInterpolator
value_changed
SFFloat

ROUTE
event to
(4)
ControlScript
Script
angle
SFFloat
then
 
 
 
ControlScript
Script
orientationGreen
SFRotation

ROUTE
event to
(5)
GreenTransform
Transform
rotation
SFRotation
  then
 
 
 
ControlScript
Script
orientationRed
SFRotation

ROUTE
event to
(5)
RedTransform
Transform
rotation
SFRotation
  then
 
 
 
ControlScript
Script
orientationTurquoise
SFRotation

ROUTE
event to
(5)
TurquoiseTransform
Transform
rotation
SFRotation
  then
 
 
 
ControlScript
Script
positionGreen
SFVec3f

ROUTE
event to
(5)
GreenTransform
Transform
translation
SFVec3f
  then
 
 
 
ControlScript
Script
positionRed
SFVec3f

ROUTE
event to
(5)
RedTransform
Transform
translation
SFVec3f
  then
 
 
 
ControlScript
Script
positionTurquoise
SFVec3f

ROUTE
event to
(5)
TurquoiseTransform
Transform
translation
SFVec3f

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