1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "https://www.web3d.org/specifications/x3d-3.0.dtd">
|
3 | <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'> |
4 | <head> |
5 | <meta name='title' content='Figure30_1ScriptSlidingBall.x3d'/> |
6 | <meta name='creator' content='Figure 30.1, The VRML 2.0 Sourcebook, Copyright [1997] By Andrea L. Ames, David R. Nadeau, and John L. Moreland'/> |
7 | <meta name='reference' content='http://www.wiley.com/legacy/compbooks/vrml2sbk/ch30/30fig01.htm'/> |
8 | <meta name='translator' content='Don Brutzman'/> |
9 | <meta name='created' content='28 November 2000'/> |
10 | <meta name='modified' content='20 October 2019'/> |
11 | <meta name='description' content='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.'/> |
12 | <meta name='identifier' content='https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter30Scripts/Figure30_1ScriptSlidingBall.x3d'/> |
13 | <meta name='generator' content='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit'/> |
14 | <meta name='license' content='../../license.html'/> |
15 | </head> |
16 | <Scene> |
17 | <WorldInfo title='Figure30_1ScriptSlidingBall.x3d'/> |
18 | <Viewpoint description='sliding ball' orientation='1 0 0 -0.2' position='0.5 0.5 1.5'/> |
19 | <!-- Background nodes are usually best placed at the top of the scene since they have global effect and are bindable nodes. --> |
20 | <Background groundAngle='1.309 1.570796' groundColor='0 0 0.1 0 0.1 0.3 0.3 0.3 0.6' skyAngle='1.309 1.571' skyColor='1 0 0.8 0.5 0 0.8 0 0 0.8'/> |
21 | <Group> |
22 | <Transform DEF='Floor' translation='0.5 -0.005 0'> |
23 | <Shape> |
24 | <Box size='1 0.01 0.5'/> |
25 | <Appearance> |
26 | <Material diffuseColor='0.7 0.7 0.7'/> |
27 | </Appearance> |
28 | </Shape> |
29 | </Transform> |
30 | <Transform translation='0 0.1 0'> |
31 |
<!-- ROUTE information for BallTransform node:
[from MoverUsingContainedScript.value_changed to set_translation
]
-->
<Transform DEF='BallTransform'> |
32 | <Shape> |
33 | <Sphere radius='0.1'/> |
34 | <Appearance> |
35 | <Material diffuseColor='1 0.3 0.3'/> |
36 | </Appearance> |
37 | </Shape> |
38 | </Transform> |
39 | </Transform> |
40 |
<!-- ROUTE information for Clock node:
[from fraction_changed to MoverUsingContainedScript.set_fraction
]
-->
<TimeSensor DEF='Clock' cycleInterval='4' loop='true'/> |
41 | <!-- In this example, each Script node can serve as a simple replacement for a PositionInterpolator node. --> |
42 | <!-- 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. --> |
43 | <Script DEF='MoverUsingExternalScriptFile' url=' "Figure30_1ScriptSlidingBall.js" "https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter30Scripts/Figure30_1ScriptSlidingBall.js" '> |
44 | <field name='set_fraction' type='SFFloat' accessType='inputOnly'/> |
45 | <field name='value_changed' type='SFVec3f' accessType='outputOnly'/> |
46 | </Script> |
47 | <!-- Second Script example: executable code is placed in url field. This is legal, but no longer a recommended approach. --> |
48 | <!-- Warning: avoid // inline comments or else canonicalization will hide all follow-on code! --> |
49 | <Script DEF='MoverUsingUrlScript' url=' "ecmascript:" function set_fraction( fraction eventTime ) { value_changed[0] = fraction; value_changed[1] = 0.0; value_changed[2] = 0.0; "}" '> |
50 | <field name='set_fraction' type='SFFloat' accessType='inputOnly'/> |
51 | <field name='value_changed' type='SFVec3f' accessType='outputOnly'/> |
52 | </Script> |
53 | <!-- Third Script example, using preferred method: script code contained in CDATA block --> |
54 |
<!-- ROUTE information for MoverUsingContainedScript node:
[from Clock.fraction_changed to set_fraction
]
[from value_changed to BallTransform.set_translation
]
-->
<Script DEF='MoverUsingContainedScript'> |
55 |
<field name='set_fraction' type='SFFloat' accessType='inputOnly'
appinfo='receive fraction from clock'/> |
56 |
<field name='value_changed' type='SFVec3f' accessType='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 }
]]>
|
|
58 | </Script> |
59 | </Group> |
60 | <!-- Any one of the three Mover script alternatives can drive the ball - modify both ROUTEs to test --> |
61 | < ROUTE fromNode='Clock' fromField='fraction_changed' toNode='MoverUsingContainedScript' toField='set_fraction'/> |
62 | < ROUTE fromNode='MoverUsingContainedScript' fromField='value_changed' toNode='BallTransform' toField='set_translation'/> |
63 | </Scene> |
64 | </X3D> |
Event Graph ROUTE Table entries with 2 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.
Clock
TimeSensor fraction_changed SFFloat |
MoverUsingContainedScript
Script set_fraction SFFloat |
then
|
MoverUsingContainedScript
Script value_changed SFVec3f |
BallTransform
Transform set_translation SFVec3f |
<!--
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. -->