This annex provides a variety of VRML examples.
B.1 Introduction and table of contents
B.2 Simple example
B.3 Instancing (sharing)
B.4 Prototype example
B.5 Scripting example
B.6 Geometric properties
B.7 Prototypes and alternate representations
B.8 Anchor
B.9 Directional light
B.10 PointSet
B.11 Level of detail
B.12 Color interpolator
B.13 TimeSensor
B.13.1
Introduction
B.13.2
Click to animate
B.13.3
Alarm clock
B.14 Shuttles and pendulums
B.15 Robot
B.16 Chopper
B.17 Guided tour
B.18 Elevator
B.19 Execution model
This example contains a simple scene defining a view of a red sphere and a blue box, lit by a directional light:
Binary encoded definition of example goes here.
Click here to view this example in a VRML browser.
Reading the following file results in three spheres being drawn. The first sphere defines a unit sphere at the origin named "Joe", the second sphere defines a smaller sphere translated along the +x axis, the third sphere is a reference to the second sphere and is translated along the -x axis. If any changes occur to the second sphere (e.g. radius changes), then the third sphere, will change too:
Binary encoded definition of example goes here.
Click here to view this example in a VRML browser. (Note that the spheres are unlit because no appearance was specifieB.)
A simple table with variable colours for the legs and top might be prototyped as:
Binary encoded definition of example goes here.
Click here to view this example in a VRML browser.
This Script node decides whether or not to open a bank vault given openVault and combinationEntered messages. To do this, it remembers whether or not the correct combination has been entereB. The Script node combined with a Sphere, a TouchSensor and a Sound node to show how is works. When the pointing device is over the sphere, the combinationEntered eventIn of the Script is sent. Then, when the Sphere is touched (typically when the mouse button is pressed) the Script is sent the openVault eventIn. This generates the vaultUnlocked eventOut which starts a 'click' sounB. Here is the example:
Binary encoded definition of example goes here.
Click here to view this example in a VRML browser.
The following IndexedFaceSet (contained in a Shape node) uses all four of the geometric property nodes to specify vertex coordinates, colours per vertex, normals per vertex, and texture coordinates per vertex (note that the material sets the overall transparency):
Binary encoded definition of example goes here.
Click here to view this example in a VRML browser.
VRML 2.0 has the capability to define new nodes. The following is
an example of a new node RefractiveMaterial. This node behaves as a Material
node with an added field, indexOfRefraction. The list of URLs for
the EXTERNPROTO are searched in order. If the browser recognizes the URN,
urn:inet:foo.com:types:RefractiveMaterial
, it may treat
it as a native type (or load the implementation). Otherwise, the URL, http://www.myCompany.com/vrmlNodes/RefractiveMaterial.wrl
,
is used as a backup to ensure that the node is supported on any browsers.
See below for the PROTO implementation that treats RefractiveMaterial as
a Material (and ignores the refractiveIndex field).
Binary encoded definition of example goes here.
Note that the name of the new node type, RefractiveMaterial, is not used by the browser to decide if the node is native or not; the URL/URN names determine the node's implementation.
Click here to view this example in a VRML browser.
The target parameter can be used by the anchor node to send a request to load a URL into another frame:
Binary encoded definition of example goes here.
An Anchor may be used to bind the viewer to a particular viewpoint in a virtual world by specifying a URL ending with #viewpointName, where viewpointName is the DEF name of a viewpoint defined in the worlB. For example:
Binary encoded definition of example goes here.
specifies an anchor that puts the viewer in the someScene world bound to the viewpoint named OverView when the box is chosen (note that OverView is the DEF name of the viewpoint, not the value of the viewpoint's description field).
If no world is specified, the current scene is implieB. For example:
Binary encoded definition of example goes here.
binds the user's view to the viewpoint with the DEF name Doorway in the current scene.
A directional light source illuminates only the objects in its enclosing grouping node. The light illuminates everything within this coordinate system including the objects that precede it in the scene graph as shown below:
Binary encoded definition of example goes here.
Click here to view this example in a VRML browser.
This simple example defines a PointSet composed of 3 points. The first point is red (1 0 0), the second point is green (0 1 0), and the third point is blue (0 0 1). The second PointSet instances the Coordinate node defined in the first PointSet, but defines different colours:
Binary encoded definition of example goes here.
Click here to view this example in a VRML browser.
The LOD node is typically used for switching between different versions of geometry at specified distances from the viewer. However, if the range field is left at its default value, the browser selects the most appropriate child from the list given. It can make this selection based on performance or perceived importance of the object. Children should be listed with most detailed version first just as for the normal case. This "performance LOD" feature can be combined with the normal LOD function to give the browser a selection of children from which to choose at each distance.
In this example, the browser is free to choose either a detailed or a less-detailed version of the object when the viewer is closer than 10 meters (as measured in the coordinate space of the LOD). The browser should display the less detailed version of the object if the viewer is between 10 and 50 meters and should display nothing at all if the viewer is farther than 50 meters. Browsers should try to honor the hints given by authors, and authors should try to give browsers as much freedom as they can to choose levels of detail based on performance.
Binary encoded definition of example goes here.
For best results, ranges should be specified only where necessary and LOD nodes should be nested with and without ranges.
Click here to view this example in a VRML browser.
This example interpolates from red to green to blue in a 10 second cycle:
Binary encoded definition of example goes here.
Click here to view this example in a VRML browser.
The TimeSensor is very flexible. The following are some of the many ways in which it can be used:
The first example animates a box when the user clicks on it:
Binary encoded definition of example goes here.
Click here to view this example in a VRML browser.
The second example plays chimes once an hour:
Binary encoded definition of example goes here.
Click here to view this example in a VRML browser.
Shuttles and pendulums are great building blocks for composing interesting animations. This shuttle translates its children back and forth along the X axis, from -1 to 1 (by default). The distance field can be used to change this default. The pendulum rotates its children about the Z axis, from 0 to 3.14159 radians and back again (by default). The maxAngle field can be used to change this default.
Binary encoded definition of example goes here.
Click here to view this example in a VRML browser.
These nodes can be used to do a continuous animation when loop is TRUE. When loop is FALSE they can perform a single cycle under control of the startTime and stopTime fields. The rate field controls the speed of the animation. The children field holds the children to be animateB.
This example is a simple implementation of a robot. This robot has very simple body parts: a cube for his head, a sphere for his body and cylinders for arms (he hovers so he has no feet!). He is something of a sentry--he walks forward and walks back across a path. He does this whenever the viewer is near. This makes use of the Shuttle and Pendulum of B.14.
Binary encoded definition of example goes here.
Click here to view this example in a VRML browser.
Move closer to the robot to start the animation.
This example of a helicopter demonstrates how to do simple animation triggered by a TouchSensor. It uses an EXTERNPROTO to include a Rotor node from the Internet which does the actual animation.
Binary encoded definition of example goes here.
Click here to view this example in a VRML browser.
VRML provides control of the viewer's camera through use of a script. This is useful for things such as guided tours, merry-go-round rides, and transportation devices such as buses and elevators. These next two examples show a couple of ways to use this feature.
This example is a simple guided tour through the worlB. Upon entry, a guide orb hovers in front of the viewer. Click on this and a tour through the world begins. The orb follows the user around on his tour. A ProximitySensor ensures that the tour is started only if the user is close to the initial starting point. Note that this is done without scripts thanks to the touchTime output of the TouchSensor.
Binary encoded definition of example goes here.
Click here to view this example in a VRML browser.
This is another example of animating the camera by depicting an elevator to ease access to a multi-storey building. For this example, a 2 storey building is shown and it is assumed that the elevator is already at the ground floor. To go up, the user just steps onto the elevator platform. A ProximitySensor fires and starts the elevator up automatically. Additional features such as call buttons for outside the elevator, elevator doors, and floor selector buttons could be added to make the elevator easier to use.
Binary encoded definition of example goes here.
Click here to view this example in a VRML browser.
This example illustrates the execution model example described in 4.10.3, Execution model.
Binary encoded definition of example goes here.
Click here to view this example in a VRML browser.
Clicking on the green sphere should display a text string for each eventsProcessed event. The two possible correct displays for this example are:
Event Sequence: 1) Script1.eventsProcessed occurred 2) Script2.eventsProcessed occurred 3) Script3.eventsProcessed occurred 4) Script6.eventsProcessed occurred
or
Event Sequence: 1) Script2.eventsProcessed occurred 2) Script1.eventsProcessed occurred 3) Script3.eventsProcessed occurred 4) Script6.eventsProcessed occurred