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='ScriptNodeEventOutControlEcmaScript.x3d'/> |
6 | <meta name='description' content='Script node interface between X3D and EcmaScript: this conformance example tests event-based X3D-EcmaScript functionality.'/> |
7 | <meta name='creator' content='Don Brutzman'/> |
8 | <meta name='created' content='30 November 1997'/> |
9 | <meta name='translated' content='13 May 2001'/> |
10 | <meta name='modified' content='20 October 2019'/> |
11 | <meta name='reference' content='https://www.web3d.org/x3d/content/examples/Basic/ScriptConformance/ScriptNodeEventOutControlEcmaScript.x3d'/> |
12 | <meta name='identifier' content='https://www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter09EventUtilitiesScripting/ScriptNodeEventOutControlEcmaScript.x3d'/> |
13 | <meta name='reference' content='VRML 97 Specification, Annex C, ECMAScript scripting reference'/> |
14 | <meta name='reference' content='https://www.web3d.org/technicalinfo/specifications/vrml97/part1/javascript.html'/> |
15 | <meta name='reference' content='https://www.web3d.org/technicalinfo/specifications/vrml97/part1/javascript.html#AccessingFields'/> |
16 | <meta name='reference' content='Makefile'/> |
17 | <meta name='reference' content='Makefile.out'/> |
18 | <meta name='reference' content='ScriptNodeEventOutControlEcmaScript-VrmlConsoleOutput.txt'/> |
19 | <meta name='reference' content='ScriptNodeEventOutControlEcmaScriptSnapshots.html'/> |
20 | <meta name='reference' content='ScriptNodeEventOutControl-Java.x3d'/> |
21 | <meta name='subject' content='VRML X3D EcmaScript Script conformance'/> |
22 | <meta name='generator' content='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/> |
23 | <meta name='license' content='../license.html'/> |
24 | </head> |
25 | <Scene> |
26 | <WorldInfo title='ScriptNodeEventOutControlEcmaScript.x3d'/> |
27 | <Viewpoint description='View test' position='0 0 12'/> |
28 | <Group> |
29 |
<!-- ROUTE information for ClickTextToTest node:
[from touchTime to InterfaceScriptNode.startTime
]
-->
<TouchSensor DEF='ClickTextToTest' description='Click text to test'/> |
30 |
<!-- ROUTE information for TextPosition node:
[from InterfaceScriptNode.changedPosition to set_translation
]
-->
<Transform DEF='TextPosition'> |
31 | <!-- TextPosition translation is modified by InterfaceScriptNode. --> |
32 | <Shape> |
33 | <!-- note "" means empty string, which skips a line and pushes the other text upwards by a line --> |
34 |
<!-- ROUTE information for MessageToUser node:
[from InterfaceScriptNode.changedText to set_string
]
-->
<Text DEF='MessageToUser' string='"Default text in X3D scene will be replaced by" "Java initialize() in Script using EventOut control." "This text appears first, if Java initialization fails." ""'> |
35 | <FontStyle justify='"MIDDLE" "MIDDLE"' size='0.8'/> |
36 | </Text> |
37 | <Appearance> |
38 |
<!-- ROUTE information for TextMaterial node:
[from InterfaceScriptNode.changedColor to set_diffuseColor
]
-->
<Material DEF='TextMaterial' diffuseColor='0.8 0.2 0.2' shininess='0.9'/> |
39 | </Appearance> |
40 | </Shape> |
41 | </Transform> |
42 |
<!-- ROUTE information for InterfaceScriptNode node:
[from ClickTextToTest.touchTime to startTime
]
[from changedText to MessageToUser.set_string
]
[from changedPosition to TextPosition.set_translation
]
[from changedColor to TextMaterial.set_diffuseColor
]
-->
<Script DEF='InterfaceScriptNode'> |
43 | <!-- No default values are allowed for eventIn or eventOut. --> |
44 | <field name='startTime' type='SFTime' accessType='inputOnly'/> |
45 | <field name='changedText' type='MFString' accessType='outputOnly'/> |
46 | <field name='changedPosition' type='SFVec3f' accessType='outputOnly'/> |
47 | <field name='changedColor' type='SFColor' accessType='outputOnly'/> |
<![CDATA[
ecmascript: function initialize () { DEBUG = true; mode = 1; if (DEBUG) Browser.println ('initialize ():'); changedText = new MFString ( 'EcmaScript initialize () with eventOut control', 'has reinitialized the changedText node.', '', 'Please click text for additional results.'); changedPosition = new SFVec3f ( 0, 3, 0 ); changedColor = new SFColor ( 0.8, 0.8, 0.2 ); if (DEBUG) Browser.println ('changedText =' + changedText); if (DEBUG) Browser.println ('changedPosition =' + changedPosition); if (DEBUG) Browser.println ('changedColor =' + changedColor); } function startTime (value, timestamp) { if (DEBUG) Browser.println ('=============================='); if (DEBUG) Browser.println ('touchEvent startTime =' + value); mode = (mode + 1) % 3; if (DEBUG) Browser.println ('mode =' + mode); switch (mode) { case 0: // pre-initialize error messsage changedText = new MFString ( 'Default text in X3D scene will be replaced by', 'EcmaScript initialize() in Script using EventOut control.', 'This text appears first, if EcmaScript initialization fails.', ''); changedPosition = new SFVec3f ( 0, 1, 0 ); changedColor = new SFColor ( 0.8, 0.2, 0.2 ); break; case 1: // post-initialize ready-to-click message initialize (); break; case 2: // post-click all-done message changedText = new MFString ( 'User click on text seen by EcmaScript', 'function via Script node eventIn.', 'Text & position successfully changed', 'via EventOut control. Test passed.'); changedPosition = new SFVec3f ( 0, -1, 0 ); changedColor = new SFColor ( 0.2, 0.8, 0.2 ); break; } if (mode != 1) { if (DEBUG) Browser.println ('changedText =' + changedText); if (DEBUG) Browser.println ('changedPosition =' + changedPosition); if (DEBUG) Browser.println ('changedColor =' + changedColor); if (DEBUG) Browser.println (); } } function shutdown() { if (DEBUG) Browser.println ('=============================='); if (DEBUG) Browser.println ('script shutdown.'); if (DEBUG) Browser.println ('=============================='); }
]]>
|
|
49 | </Script> |
50 | </Group> |
51 | < ROUTE fromNode='ClickTextToTest' fromField='touchTime' toNode='InterfaceScriptNode' toField='startTime'/> |
52 | < ROUTE fromNode='InterfaceScriptNode' fromField='changedText' toNode='MessageToUser' toField='set_string'/> |
53 | < ROUTE fromNode='InterfaceScriptNode' fromField='changedPosition' toNode='TextPosition' toField='set_translation'/> |
54 | < ROUTE fromNode='InterfaceScriptNode' fromField='changedColor' toNode='TextMaterial' toField='set_diffuseColor'/> |
55 | </Scene> |
56 | </X3D> |
Event Graph ROUTE Table entries with 4 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.
ClickTextToTest
TouchSensor touchTime SFTime |
InterfaceScriptNode
Script startTime SFTime |
then
|
InterfaceScriptNode
Script changedColor SFColor |
TextMaterial
Material set_diffuseColor SFColor |
||
then
|
InterfaceScriptNode
Script changedPosition SFVec3f |
TextPosition
Transform set_translation SFVec3f |
||||
then
|
InterfaceScriptNode
Script changedText MFString |
MessageToUser
Text set_string MFString |
InterfaceScriptNode
Script changedText MFString |
MessageToUser
Text set_string MFString |
|
InterfaceScriptNode
Script changedPosition SFVec3f |
TextPosition
Transform set_translation SFVec3f |
|
InterfaceScriptNode
Script changedColor SFColor |
TextMaterial
Material set_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. -->