<Transform DEF='Floor' translation='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'>
</Transform>
<!--
Clock ROUTE:
[
from fraction_changed to MoverUsingContainedScript.set_fraction
]
-->
<TimeSensor DEF='Clock' cycleInterval='4' loop='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_fraction' type='SFFloat' accessType='inputOnly'/>
<field name='value_changed' type='SFVec3f' accessType='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_fraction' type='SFFloat' accessType='inputOnly'/>
<field name='value_changed' type='SFVec3f' accessType='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_fraction' type='SFFloat' accessType='inputOnly'
appinfo='receive fraction from clock'/>
<field name='value_changed' type='SFVec3f' accessType='outputOnly'
appinfo='produce output position to move the ball'/>