1 |
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN" "https://www.web3d.org/specifications/x3d-3.3.dtd">
|
3 | <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'> |
4 | <head> |
5 | <meta name='title' content='Bounce1.x3d'/> |
6 | <meta name='description' content='Bouncing beachball (JavaScript/VRMLscript version): this world illustrates the use of a Script node to create a computed animation path. In particular, the Script node uses a JavaScript (or VRMLScript) program script to compute translation values for a vertically bouncing beach ball.'/> |
7 | <meta name='creator' content='David R. Nadeau'/> |
8 | <meta name='translator' content='Don Brutzman'/> |
9 | <meta name='created' content='1 July 1998'/> |
10 | <meta name='translated' content='2 February 2014'/> |
11 | <meta name='modified' content='20 October 2019'/> |
12 | <meta name='reference' content='originals/bounce1.wrl'/> |
13 | <meta name='reference' content='http://www.siggraph.org/s98'/> |
14 | <meta name='reference' content='http://www.siggraph.org/s98/conference/courses/18.html'/> |
15 | <meta name='reference' content='http://www.sdsc.edu/~moreland/courses/Siggraph98/vrml97/slides/mt0407.htm'/> |
16 | <meta name='reference' content='http://www.sdsc.edu/~moreland/courses/Siggraph98/vrml97/slides/mt0426.htm'/> |
17 | <meta name='reference' content='http://www.sdsc.edu/~moreland/courses/Siggraph98/vrml97/vrml97.htm'/> |
18 | <meta name='reference' content='https://www.web3d.org/x3d/content/examples/X3dResources.html'/> |
19 | <meta name='identifier' content='https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Siggraph98Course/Bounce1.x3d'/> |
20 | <meta name='generator' content='Vrml97ToX3dNist, http://ovrt.nist.gov/v2_x3d.html'/> |
21 | <meta name='generator' content='X3D-Edit, https://savage.nps.edu/X3D-Edit'/> |
22 | <meta name='license' content='../license.html'/> |
23 | </head> |
24 | <Scene> |
25 | <!-- http://www.sdsc.edu/~moreland/courses/Siggraph98/vrml97/slides/bounce1.htm --> |
26 | <!-- This world illustrates the use of a Script node to create a computed animation path. In particular, the Script node uses a JavaScript (or VRMLScript) program script to compute translation values for a vertically bouncing beach ball. --> |
27 | <!-- The bounce path is based upon the projectile motion equation of physics, constrained to create a cyclic bouncing path with a user-selected maximum bounce height. Also, there is no friction, drag, or damping. --> |
28 | <!-- The equation is derived as follows: --> |
29 | <!-- (1) Projectile motion computes a y(t) value (height as a function of time) based upon the gravitation constant, g, an initial y-direction velocity, v0, an initial y position, y0, and the current time, t: --> |
30 | <!-- y(t) = 0.5 * g * t * t + v0 * t + y0 --> |
31 | <!-- (2) At time t=0, the ball should be on the ground with y=0. So, y0 = y(0) = 0. The equation in (1) simplifies to: --> |
32 | <!-- y(t) = 0.5 * g * t * t + v0 * t --> |
33 | <!-- (3) At time t=1, at the end of the TimeSensor's fractional time cycle, the ball should again be on the ground with y=0. So, y(1) = 0. Plugging this in to the equation in (2), we get: --> |
34 | <!-- y(t) = 0.5 * g * t * t + v0 * t --> |
35 | <!-- y(1) = 0.5 * g * 1 * 1 + v0 * 1 --> |
36 | <!-- 0 = 0.5 * g + v0 --> |
37 | <!-- So v0 = -0.5 * g --> |
38 | <!-- (4) At time t=0.5, the ball should be at the peak of its bounce at a user-selected maximum height, h. So, y(0.5) = h. Plugging this in to the equation in (2), we get: --> |
39 | <!-- y(t) = 0.5 * g * t * t + v0 * t --> |
40 | <!-- y(0.5) = 0.5 * g * 0.5 * 0.5 + v0 * 0.5 --> |
41 | <!-- h = g * 0.125 + v0 * 0.5 --> |
42 | <!-- And v0 = -0.5 * g from equation (3), so --> |
43 | <!-- h = g * 0.125 - 0.5 * g * 0.5 --> |
44 | <!-- h = -g * 0.125 --> |
45 | <!-- So g = -8.0 * h --> |
46 | <!-- (5) We can now simplify the equation in (2) using the results from (3) and (4) to get an equation that computes the ball height y(t) parameterized only by the maximum height, h, giving us: --> |
47 | <!-- y(t) = 0.5 * g * t * t + v0 * t --> |
48 | <!-- y(t) = 0.5 * (-8.0 * h) * t * t + (-0.5 * g) * t --> |
49 | <!-- y(t) = 0.5 * (-8.0 * h) * t * t + (4.0 * h) * t --> |
50 | <!-- y(t) = 4.0 * h * (-t * t + t) --> |
51 | <!-- y(t) = 4.0 * h * t * (1.0 - t) --> |
52 | <!-- In the program script, the maximum height, h, is given in the 'bounceHeight' field. The current time, t, is given in the 'set_fraction' eventIn and passed to the eventIn function as the 'frac' parameter. Using these names, the above equation becomes: --> |
53 | <!-- y = 4.0 * bounceHeight * frac * (1.0 - frac) --> |
54 | <!-- Things to experiment with --> |
55 | <!-- - Encapsulate the ball, script, timer, and sensors within a PROTO for a new node named "BouncingBall". Then use that new BouncingBall node multiple times to create multiple bouncing balls. Your PROTO interface might look like this: --> |
56 | <!-- PROTO BouncingBall [ field SFFloat bounceHeight 2.0 field SFTime cycleInterval 2.0 ] { . . . } --> |
57 | <!-- See 'bounce3.wrl', which implements such a PROTO. --> |
58 | <!-- - Add a shadow under the bouncing ball. To do this, add a circular, semi-transparent, black shape that doesn't bounce. To make the shadow more realistic, scale the shadow in the X and Z directions, shrinking it as the ball goes up, and increasing it as the ball comes down. You'll need to add another eventOut for the Script node and send an XYZ scaling factor triple out that eventOut. Try the following values for the XYZ scale values: --> |
59 | <!-- xzscale = 1.0 - 0.5 * y / bounceHeight; --> |
60 | <!-- shadowScale_changed[0] = xzscale; --> |
61 | <!-- shadowScale_changed[1] = 1.0; --> |
62 | <!-- shadowScale_changed[2] = xzscale; --> |
63 | <!-- See 'bounce4.wrl', which implements shadows using the above scale values. --> |
64 | <!-- - Add a sound to the PROTO so that each time the ball touches the ground, it makes a 'boing' sound. --> |
65 | <!-- - When the ball hits the ground, scale the ball slightly so that it appears to squish. --> |
66 | <WorldInfo info='"Copyright (c) 1997, David R. Nadeau"' title='Bouncing beachball (JavaScript)'/> |
67 | <Viewpoint description='Bouncing beachball, JavaScript version' orientation='1.0 0.0 0.0 0.1' position='0.0 0.6 8.0'/> |
68 | <NavigationInfo headlight='false' speed='2.0'/> |
69 | <DirectionalLight ambientIntensity='0.5' direction='0.0 -1.0 -0.5'/> |
70 | <Background skyAngle='1.371 1.571' skyColor='0.0 0.0 1.0 0.0 0.5 1.0 0.7 0.7 1.0'/> |
71 | <Shape> |
72 | <Appearance> |
73 | <TextureTransform scale='10.0 10.0'/> |
74 | <Material/> |
75 | <ImageTexture url=' "sand.jpg " "https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Siggraph98Course/sand.jpg " '/> |
76 | </Appearance> |
77 | <IndexedFaceSet solid='false' coordIndex='0 1 2 3'> |
78 | <Coordinate point='-50.0 -1.0 50.0 50.0 -1.0 50.0 50.0 -1.0 -50.0 -50.0 -1.0 -50.0'/> |
79 | </IndexedFaceSet> |
80 | </Shape> |
81 | <Transform translation='-3.0 -1.0 -10.0'> |
82 | |
83 | <Billboard> |
84 | <Shape> |
85 | <Appearance> |
86 | <ImageTexture url=' "palm.png " "https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Siggraph98Course/palm.png " '/> |
87 | </Appearance> |
88 | <IndexedFaceSet solid='false' coordIndex='0 1 2 3' texCoordIndex='0 1 2 3'> |
89 | <TextureCoordinate point='0.0 0.0 1.0 0.0 1.0 1.0 0.0 1.0'/> |
90 | <Coordinate point='-2.5 0.0 0.0 2.5 0.0 0.0 2.5 11.25 0.0 -2.5 11.25 0.0'/> |
91 | </IndexedFaceSet> |
92 | </Shape> |
93 | </Billboard> |
94 | <Shape> |
95 | <Appearance> |
96 | <Material diffuseColor='0.0 0.0 0.0' transparency='0.5'/> |
97 | <ImageTexture url=' "palmsh.png " "https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Siggraph98Course/palmsh.png " '/> |
98 | </Appearance> |
99 | <IndexedFaceSet solid='false' coordIndex='0 1 2 3' texCoordIndex='0 1 2 3'> |
100 | <TextureCoordinate point='0.0 0.0 1.0 0.0 1.0 1.0 0.0 1.0'/> |
101 | <Coordinate point='-2.5 0.05 2.5 2.5 0.05 2.5 2.5 0.05 -2.5 -2.5 0.05 -2.5'/> |
102 | </IndexedFaceSet> |
103 | </Shape> |
104 | </Group> |
105 | </Transform> |
106 | <Transform scale='0.6 0.6 0.6' translation='-5.0 -1.0 -6.0'> |
107 | <Group USE='Palm'/> |
108 | </Transform> |
109 | <Transform translation='5.0 -1.0 -9.0'> |
110 | <Group USE='Palm'/> |
111 | </Transform> |
112 | <Transform translation='10.0 -1.0 -15.0'> |
113 | <Group USE='Palm'/> |
114 | </Transform> |
115 |
<!-- ROUTE information for Ball node:
[from Bouncer.value_changed to set_translation
]
-->
<Transform DEF='Ball'> |
116 | <Shape> |
117 | <Appearance> |
118 | <TextureTransform scale='2.0 1.0'/> |
119 | <Material ambientIntensity='0.5' diffuseColor='1.0 1.0 1.0' shininess='0.4' specularColor='0.7 0.7 0.7'/> |
120 | <ImageTexture url=' "beach.jpg " "https://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Siggraph98Course/beach.jpg " '/> |
121 | </Appearance> |
122 | <Sphere/> |
123 | </Shape> |
124 | </Transform> |
125 |
<!-- ROUTE information for Clock node:
[from fraction_changed to Bouncer.set_fraction
]
-->
<TimeSensor DEF='Clock' cycleInterval='2.0' loop='true' startTime='1.0'/> |
126 |
<!-- ROUTE information for Bouncer node:
[from Clock.fraction_changed to set_fraction
]
[from value_changed to Ball.set_translation
]
-->
<Script DEF='Bouncer'> |
127 | <field name='value_changed' type='SFVec3f' accessType='outputOnly'/> |
128 | <field name='bounceHeight' type='SFFloat' value='3.0' accessType='initializeOnly'/> |
129 | <field name='set_fraction' type='SFFloat' accessType='inputOnly'/> |
<![CDATA[
ecmascript: function set_fraction( frac, tm ) { y = 4.0 * bounceHeight * frac * (1.0 - frac); value_changed[0] = 0.0; value_changed[1] = y; value_changed[2] = 0.0; }
]]>
|
|
131 | </Script> |
132 | < ROUTE fromNode='Clock' fromField='fraction_changed' toNode='Bouncer' toField='set_fraction'/> |
133 | < ROUTE fromNode='Bouncer' fromField='value_changed' toNode='Ball' toField='set_translation'/> |
134 | </Scene> |
135 | </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 |
Bouncer
Script set_fraction SFFloat |
then
|
Bouncer
Script value_changed SFVec3f |
Ball
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. -->