<?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='ScriptNodeFieldControlEcmaScript.x3d'/>
<meta name='descriptioncontent='Script node interface between X3D and EcmaScript: this conformance example tests field-based X3D-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='referencecontent=' https://www.web3d.org/x3d/content/examples/Basic/ScriptConformance/ScriptNodeFieldControlEcmaScript.x3d '/>
<meta name='identifiercontent=' https://X3dGraphics.com/examples/X3dForWebAuthors/Chapter09EventUtilitiesScripting/ScriptNodeFieldControlEcmaScript.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='ScriptNodeFieldControlEcmaScript-VrmlConsoleOutput.txt'/>
<meta name='referencecontent='ScriptNodeFieldControlEcmaScriptSnapshots.html'/>
<meta name='referencecontent='ScriptNodeFieldControl-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>
<!--

Index for DEF nodes : ClickTextToTest, InterfaceScriptNode, MessageToUser, TextMaterial, TextPosition

Index for Viewpoint image : Viewpoint_1
-->
<Scene>
<WorldInfo title='ScriptNodeFieldControlEcmaScript.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'/>
<Transform DEF='TextPosition'>
<!-- TextPosition translation is modified by InterfaceScriptNode. -->
<Shape>
<Text DEF='MessageToUserstring='"Default text in X3D 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>
<Material DEF='TextMaterialdiffuseColor='0.8 0.2 0.2shininess='0.9'/>
</Appearance>
</Shape>
</Transform>
<!-- ROUTE information for InterfaceScriptNode node:  [from ClickTextToTest.touchTime to startTime ] -->
<Script DEF='InterfaceScriptNodedirectOutput='true'>
<!-- No default values are allowed for eventIn or eventOut. -->
<field name='startTimetype='SFTimeaccessType='inputOnly'/>
<field name='sceneTexttype='SFNodeaccessType='initializeOnly'>
<Text USE='MessageToUser'/>
</field>
<field name='sceneTransformtype='SFNodeaccessType='initializeOnly'>
<Transform USE='TextPosition'/>
</field>
<field name='sceneMaterialtype='SFNodeaccessType='initializeOnly'>
<Material USE='TextMaterial'/>
</field>
<![CDATA[
        
ecmascript:

function initialize ()
{
	DEBUG = true;
	mode  = 1;
	if (DEBUG) Browser.print ('initialize ():');

	sceneText.string = new MFString (
	'EcmaScript initialize () with field control',
 	'has reinitialized the changedText node.',
 	'',
 	'Please click text for additional results.');
	sceneTransform.translation = new SFVec3f ( 0, 3, 0 );
	sceneMaterial.diffuseColor = new SFColor ( 0.8, 0.8, 0.2 );
	if (DEBUG) Browser.print ('sceneText.string           =' + sceneText.string);
	if (DEBUG) Browser.print ('sceneTransform.translation =' + sceneTransform.translation);
	if (DEBUG) Browser.print ('sceneMaterial.diffuseColor =' + sceneMaterial.diffuseColor);
}
function startTime (value, timestamp)
{
	if (DEBUG) Browser.print ('==============================');
	if (DEBUG) Browser.print ('touchEvent startTime =' + value);

	mode = (mode + 1) % 3;
	if (DEBUG) Browser.print ('mode =' + mode);
	switch (mode)
	{
	  case 0:	// pre-initialize error messsage
		sceneText.string = new MFString (
		'Default text in X3D scene will be replaced by',
 		'EcmaScript initialize() in Script using field control.',
 		'This text appears first, if EcmaScript initialization fails.',
 		'');
 		sceneTransform.translation = new SFVec3f ( 0, 1, 0 );
		sceneMaterial.diffuseColor = 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
		sceneText.string = new MFString (
		'User click on text seen by EcmaScript',
 		'function via Script node eventIn.',
 		'Text & position successfully changed',
 		'via field control.  Test passed.');
	 	sceneTransform.translation = new SFVec3f ( 0, -1, 0 );
	 	sceneMaterial.diffuseColor = new SFColor ( 0.2, 0.8, 0.2 );
		break;
	}
		
	if (mode != 1)
	{
	 	if (DEBUG) Browser.print ('sceneText.string           =' + sceneText.string);
	 	if (DEBUG) Browser.print ('sceneTransform.translation =' + sceneTransform.translation);
	 	if (DEBUG) Browser.print ('sceneMaterial.diffuseColor =' + sceneMaterial.diffuseColor);
	 	if (DEBUG) Browser.print ();
 	}
}
function shutdown()
{
	if (DEBUG) Browser.print ('==============================');
  	if (DEBUG) Browser.print ('script shutdown.');
	if (DEBUG) Browser.print ('==============================');
}

      
]]>
</Script>
</Group>
<ROUTE fromNode='ClickTextToTestfromField='touchTimetoNode='InterfaceScriptNodetoField='startTime'/>
</Scene>
</X3D>
<!--

Index for DEF nodes : ClickTextToTest, InterfaceScriptNode, MessageToUser, TextMaterial, TextPosition

Index for Viewpoint image : Viewpoint_1
-->

<!-- Color key: <X3dNode DEF='idName' field='value'/> matches <XmlElement DEF='idName' attribute='value'/>
(Light blue background: behavior node) (Grey background: inserted documentation) (Magenta background: X3D Extensibility)
-->

<!-- For additional help information about X3D scenes, please see X3D Tooltips, X3D Resources and X3D Scene Authoring Hints. -->