<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "http://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 =' http://www.web3d.org/specifications/x3d-3.0.xsd '>
<head>
<meta name='titlecontent='Figure30.1ScriptSlidingBall.x3d'/>
<meta name='creatorcontent='Figure 30.1, The VRML 2.0 Sourcebook, Copyright [1997] By Andrea L. Ames, David R. Nadeau, and John L. Moreland'/>
<meta name='referencecontent=' http://www.wiley.com/legacy/compbooks/vrml2sbk/ch30/30fig01.htm '/>
<meta name='translatorcontent='Don Brutzman'/>
<meta name='createdcontent='28 November 2000'/>
<meta name='modifiedcontent='4 February 2014'/>
<meta name='descriptioncontent='A sliding red sphere and a custom interpolation script. Three ways to include ECMAScript (JavaScript) programming are compared: external file, url script code, and embedded script code. Recommendation: use embedded script code inside a CDATA block.'/>
<meta name='identifiercontent=' http://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter30-Scripts/Figure30.1ScriptSlidingBall.x3d '/>
<meta name='generatorcontent='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/>
<meta name='licensecontent=' ../../license.html'/>
</head>
<!-- -->
<Scene>
<Viewpoint description='sliding ballorientation='1 0 0 -0.2position='0.5 0.5 1.5'/>
<!-- Background nodes are usually best placed at the top of the scene since they have global effect and are bindable nodes. -->
<Background groundAngle='1.309 1.570796groundColor='0 0 0.1 0 0.1 0.3 0.3 0.3 0.6skyAngle='1.309 1.571skyColor='1 0 0.8 0.5 0 0.8 0 0 0.8'/>
<Group>
<Transform DEF='Floortranslation='0.5 -0.005 0'>
<Shape>
<Box size='1 0.01 0.5'/>
<Appearance>
<Material diffuseColor='0.7 0.7 0.7'/>
</Appearance>
</Shape>
</Transform>
<Transform translation='0 0.1 0'>
<!-- BallTransform ROUTE:  [from MoverUsingContainedScript.value_changed to set_translation ] -->
<Transform DEF='BallTransform'>
<Shape>
<Sphere radius='0.1'/>
<Appearance>
<Material diffuseColor='1 0.3 0.3'/>
</Appearance>
</Shape>
</Transform>
</Transform>
<!-- Clock ROUTE:  [from fraction_changed to MoverUsingContainedScript.set_fraction ] -->
<TimeSensor DEF='ClockcycleInterval='4loop='true'/>
<!-- In this example, each Script node can serve as a simple replacement for a PositionInterpolator node. -->
<!-- First Script example: external .js javascript file. This can be helpful if multiple Script nodes (perhaps in multiple scenes) reuse the same code, allowing any changes to occur in a single .js ecmascript file. -->
<Script DEF='MoverUsingExternalScriptFile'
  url=' "Figure30.1ScriptSlidingBall.js" "http://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter30-Scripts/Figure30.1ScriptSlidingBall.js" '>
<field name='set_fractiontype='SFFloataccessType='inputOnly'/>
<field name='value_changedtype='SFVec3faccessType='outputOnly'/>
</Script>
<!-- Second Script example: executable code is placed in url field. This is legal, but no longer a recommended approach. -->
<!-- Warning: avoid // inline comments or else canonicalization will hide all follow-on code! -->
<Script DEF='MoverUsingUrlScript'
  url=' "ecmascript:" function set_fraction( fraction eventTime ) { value_changed[0] = fraction; value_changed[1] = 0.0; value_changed[2] = 0.0; "}" '>
<field name='set_fractiontype='SFFloataccessType='inputOnly'/>
<field name='value_changedtype='SFVec3faccessType='outputOnly'/>
</Script>
<!-- Third Script example, using preferred method: script code contained in CDATA block -->
<!-- MoverUsingContainedScript ROUTEs:  [from Clock.fraction_changed to set_fraction ] [from value_changed to BallTransform.set_translation ] -->
<Script DEF='MoverUsingContainedScript'>
<field name='set_fractiontype='SFFloataccessType='inputOnly'
 appinfo='receive fraction from clock'/>

<field name='value_changedtype='SFVec3faccessType='outputOnly'
 appinfo='produce output position to move the ball'/>

<![CDATA[
        
ecmascript:

// Move a shape in a straight path
function set_fraction( fraction, eventTime ) {
	value_changed[0] = fraction;    // X component
	value_changed[1] = 0.0;         // Y component
	value_changed[2] = 0.0;         // Z component
}

      
]]>
</Script>
</Group>
<!-- Any one of the three Mover script alternatives can drive the ball - modify both ROUTEs to test -->
<ROUTE fromNode='ClockfromField='fraction_changedtoNode='MoverUsingContainedScripttoField='set_fraction'/>
<ROUTE fromNode='MoverUsingContainedScriptfromField='value_changedtoNode='BallTransformtoField='set_translation'/>
</Scene>
</X3D>
<!--

Index for DEF nodes : BallTransform, Clock, Floor, MoverUsingContainedScript, MoverUsingExternalScriptFile, MoverUsingUrlScript

Index for Viewpoint image : Viewpoint_1
-->

<!-- Color key: <X3dNode DEF='idName' field='value'/> matches <XmlElement DEF='idName' attribute='value'/> -->

<!-- Additional help information about X3D scenes: X3D Resources, X3D Scene Authoring Hints and X3D Tooltips -->