<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "https://www.web3d.org/specifications/x3d-3.0.dtd">
<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 ' >
<head>
<meta name='titlecontent=' ScriptNodeEventOutControl_EcmaScript.x3d '/>
<meta name='descriptioncontent='Script node interface between VRML and EcmaScript: this conformance example tests event-based VRML-EcmaScript functionality.'/>
<meta name='creatorcontent='Don Brutzman'/>
<meta name='createdcontent='30 November 1997'/>
<meta name='translatedcontent='13 May 2001'/>
<meta name='modifiedcontent='20 October 2019'/>
<meta name='identifiercontent=' https://www.web3d.org/x3d/content/examples/Basic/ScriptConformance/ScriptNodeEventOutControl_EcmaScript.x3d '/>
<meta name='referencecontent='VRML 97 Specification, Annex C, ECMAScript scripting reference'/>
<meta name='referencecontent=' https://www.web3d.org/technicalinfo/specifications/vrml97/part1/javascript.html '/>
<meta name='referencecontent=' https://www.web3d.org/technicalinfo/specifications/vrml97/part1/javascript.html#AccessingFields '/>
<meta name='referencecontent='Makefile'/>
<meta name='referencecontent='Makefile.out'/>
<meta name='referencecontent=' ScriptNodeEventOutControl_EcmaScript-VrmlConsoleOutput.txt '/>
<meta name='referencecontent=' ScriptNodeEventOutControl_EcmaScriptSnapshots.html '/>
<meta name='referencecontent=' ScriptNodeEventOutControl_Java.x3d '/>
<meta name='subjectcontent='VRML X3D EcmaScript Script conformance'/>
<meta name='generatorcontent='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
<meta name='licensecontent=' ../license.html'/>
</head>
<!--

to top <!-- Event Graph ROUTE Table shows event connections -->
 
<!-- Index for DEF nodes: ClickTextToTest, InterfaceScriptNode, MessageToUser, TextMaterial, TextPosition

Index for Viewpoint node: Viewpoint_1
-->
<Scene>
<WorldInfo title='ScriptNodeEventOutControl_EcmaScript.x3d'/>
<Viewpoint description='View testposition='0 0 12'/>
<Group>
<!-- ROUTE information for ClickTextToTest node:  [from touchTime to InterfaceScriptNode.startTime ] -->
<TouchSensor DEF='ClickTextToTestdescription='Click text to test'/>

<!-- ROUTE information for TextPosition node:  [from InterfaceScriptNode.changedPosition to set_translation ] -->
<Transform DEF='TextPosition'>
<!-- TextPosition translation is modified by InterfaceScriptNode. -->
<Shape>
<!-- note ""
means empty string, which skips a line and pushes the other text upwards by a line -->

<!-- ROUTE information for MessageToUser node:  [from InterfaceScriptNode.changedText to set_string ] -->
<Text DEF='MessageToUserstring='"Default text in VRML scene will be replaced by" "Java initialize() in Script using EventOut control." "This text appears first, if Java initialization fails." ""'>
<FontStyle justify='"MIDDLE" "MIDDLE"size='0.8'/>
</Text>
<Appearance>
<!-- ROUTE information for TextMaterial node:  [from InterfaceScriptNode.changedColor to set_diffuseColor ] -->
<Material DEF='TextMaterialdiffuseColor='0.8 0.2 0.2shininess='0.9'/>
</Appearance>
</Shape>
</Transform>
<!-- No default values are allowed for eventIn or eventOut. -->
<field name='startTimetype='SFTimeaccessType='inputOnly'/>
<field name='changedTexttype='MFStringaccessType='outputOnly'/>
<field name='changedPositiontype='SFVec3faccessType='outputOnly'/>
<field name='changedColortype='SFColoraccessType='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 VRML 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 ('==============================');
}

      
]]>
</Script>
</Group>
< ROUTE  fromNode=' ClickTextToTest' fromField='touchTime' toNode=' InterfaceScriptNode' toField='startTime'/>
< ROUTE  fromNode=' InterfaceScriptNode' fromField='changedText' toNode=' MessageToUser' toField='set_string'/>
< ROUTE  fromNode=' InterfaceScriptNode' fromField='changedPosition' toNode=' TextPosition' toField='set_translation'/>
< ROUTE  fromNode=' InterfaceScriptNode' fromField='changedColor' toNode=' TextMaterial' toField='set_diffuseColor'/>
</Scene>
</X3D>
<!--

to top <!-- Event Graph ROUTE Table shows event connections -->
 
<!-- Index for DEF nodes: ClickTextToTest, InterfaceScriptNode, MessageToUser, TextMaterial, TextPosition

Index for Viewpoint node: Viewpoint_1
-->

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

ROUTE
event to
(1)
InterfaceScriptNode
Script
startTime
SFTime

 
 
then
InterfaceScriptNode
Script
changedColor
SFColor

ROUTE
event to
(2)
TextMaterial
Material
set_diffuseColor
SFColor
 
 
 
then
InterfaceScriptNode
Script
changedPosition
SFVec3f

ROUTE
event to
(2)
TextPosition
Transform
set_translation
SFVec3f
 
 
 
then
InterfaceScriptNode
Script
changedText
MFString

ROUTE
event to
(2)
MessageToUser
Text
set_string
MFString


      InterfaceScriptNode
Script
changedText
MFString

ROUTE
event to
(1)
MessageToUser
Text
set_string
MFString
InterfaceScriptNode
Script
changedPosition
SFVec3f

ROUTE
event to
(1)
TextPosition
Transform
set_translation
SFVec3f
InterfaceScriptNode
Script
changedColor
SFColor

ROUTE
event to
(1)
TextMaterial
Material
set_diffuseColor
SFColor


-->

<!-- Online at
https://www.web3d.org/x3d/content/examples/Basic/ScriptConformance/ScriptNodeEventOutControl_EcmaScriptIndex.html -->
<!-- Version control at
https://sourceforge.net/p/x3d/code/HEAD/tree/www.web3d.org/x3d/content/examples/Basic/ScriptConformance/ScriptNodeEventOutControl_EcmaScript.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. -->