VRML Primer and Tutorial
VRML Primer and Tutorial
net/publication/228529989
CITATIONS READS
6 419
2 authors, including:
Daniel K. Schneider
University of Geneva
109 PUBLICATIONS 1,348 CITATIONS
SEE PROFILE
All content following this page was uploaded by Daniel K. Schneider on 19 February 2014.
1
http://tecfa.unige.ch/tecfa-people/schneider.html
2
http://tecfa.unige.ch/tecfa-people/sylvere.html
3 http://tecfa.unige.ch/
2
DRAFT Version 1.1a - use at your own risk !!
This evolving document is an introduction to VRML 97.
See section 8.6.1 for the version history. We will work on it again in the next few weeks
(test-version).
DON'T bookmark any pages inside this tree.
Node names are generated dynamically and will change !
1 http://tecfa.unige.ch/guides/vrml/examples/
Contents
1 Starting with VRML 9
1.1 Introduction to the VRML standard and 3D Graphics . . . . . . . . . . . . . . . . 9
1.1.1 What is VRML? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.1.2 VRML resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.1.3 An introduction to 3D graphics . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.1.4 Producing VRML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.1.5 Browsers and how to use them . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.2 Basic static VRML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.2.1 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.2.2 Basic Geometry (Shapes) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.2.3 Positioning Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.2.4 Rotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.2.5 De ning appearance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.2.6 Anchors and Teleportals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.2.7 Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
1.2.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
1.2.9 Moving On . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2 Modularization and Abstraction 27
2.1 Multiple instances of the same object . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.2 Inlining other VRML les . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.3 Prototyping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
2.3.1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3 Good VRML Style and Performance 35
3.1 Your rst \real" VRML le . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.2 Levels of Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3.3 Good VRML style and performance . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4 Mixing HTML with VRML 39
4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.2 Mixing HTML and VRML Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.2.1 VRML scenes library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.2.2 VRML to HTML in a frame . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.3 VRML code generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
4.3.1 VRML Code Generation with Javascript . . . . . . . . . . . . . . . . . . . . 42
4.4 Adding and Removing Kids with Javascript . . . . . . . . . . . . . . . . . . . . . . 44
5 Introduction to moving, interactive VRML 49
5.1 The idea . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5.2 Introduction to Events, Routes, Sensors and Interpolators . . . . . . . . . . . . . . 50
5.2.1 TimeSensors and Rotations with Interpolators . . . . . . . . . . . . . . . . 54
3
4 CONTENTS
5.2.2 More on Time Sensors and Interpolators . . . . . . . . . . . . . . . . . . . . 57
5.3 Introduction to Scripting with Javascript . . . . . . . . . . . . . . . . . . . . . . . 58
5.3.1 Touchsensors, ROUTE and Javascript . . . . . . . . . . . . . . . . . . . . . 59
5.3.2 Dealing with state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
5.3.3 Touchsensors, ROUTE, Switch and Javascript . . . . . . . . . . . . . . . . . 63
5.3.4 Scripting with TimeSensors . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
6 The External Authoring Interface 65
6.1 What can we use the EAI for ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
6.2 The very rst steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
6.2.1 The application: HTML plus VRML plus a Java Applet . . . . . . . . . . . 66
6.2.2 Getting a reference to the VRML browser . . . . . . . . . . . . . . . . . . . 67
6.3 Essential EAI tricks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
6.3.1 Getting a reference to a VRML node and writing Event values . . . . . . . 71
6.3.2 Getting a reference to a VRML node and writing Event values II . . . . . . 73
6.3.3 Reading Events from the Scene . . . . . . . . . . . . . . . . . . . . . . . . . 74
6.3.4 Create Vrml from String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
6.3.5 Create, Put and Remove together . . . . . . . . . . . . . . . . . . . . . . . 77
6.3.6 Receiving Events from the Scene . . . . . . . . . . . . . . . . . . . . . . . . 78
6.4 Extracting Information from a scene . . . . . . . . . . . . . . . . . . . . . . . . . . 80
6.5 Object manipulation and better Java Widgets . . . . . . . . . . . . . . . . . . . . . 82
6.5.1 My rst slider applet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
7 Animation and Avatars 83
7.1 Introduction to keyframe animation . . . . . . . . . . . . . . . . . . . . . . . . . . 83
7.2 Building a mini bot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
8 Appendix 85
8.1 On-line Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
8.2 VRML Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
8.2.1 CosmoWorlds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
8.3 VRML II Browsers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
8.3.1 Win95 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
8.3.2 VRML on old SUNs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
8.3.3 PowerMac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
8.3.4 SGI/Irix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
8.4 Field and Event Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
8.5 Introduction to JAVA with VRML . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
8.6 Useless stu (Version History / ToDo List) . . . . . . . . . . . . . . . . . . . . . . 91
8.6.1 Version history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
8.6.2 Things to do . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
8.7 Copyright Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Index 95
List of Tables
1.1 Degrees to radians conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5
6 LIST OF TABLES
List of Figures
1.1 The 3 axis of 3-D graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.2 The right hand rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5.1 the route/events model in VRML . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
5.2 A typical Animation Event Path in VRML . . . . . . . . . . . . . . . . . . . . . . 51
6.1 EAI: Basic JAVA methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
7
8 LIST OF FIGURES
Chapter 1
9
10 CHAPTER 1. STARTING WITH VRML
on the World-Wide-Web3, May 25-27, 1994 at CERN in Geneva. It's conceptual origins are older,
e.g. (a) Science Fiction literature (e.g. [Gibson, 1994], [Stephenson, 1992]), (b) Mark Pesce's,
P. Kennard's and Toni Parisi's \Labyrinth" system ([Pesce et al., 1994]) and proposal for a 3-D
navigation and representation scheme and (c) more generally 3-D computer graphics (including
VR). Based upon SGI's \Open Inventor" format, a almost nal draft for VRML 1.0 was presented
at the second WWW conference4 in fall 94 in Chicago. On April 3, 1995 SGI presented WebSpace,
the rst publicly available VRML browser. So all in all it took about a year to set standards and
make the rst browser available. Since VRML is a relatively simple format building upon a well
de ned standard, very quickly a number of modeling tools and convertors also became available.
In the next sections we will look at simple static VRML scences. These are built with VRML's
symbolic description language. Note di erent VRML browsers all have a di erent user interface
(e.g. for navigation and object examination). They also render things a bit di erently. Most will
also give you a \quality" choice (e.g. faster renderning and lower quality vs. slower rendering but
better quality. For now, let's just assume that the user can move himself though 3D space by
moving a camera through the space (and therefore what he sees on the display is what sees \his"
camera).
Books
Jed Hartman's and Josie Wernecke's \VRML 2.0 Handbook, Building Moving Worlds on
the Web" ([Hartman et Wernecke, 1996] is my recommended book for learning VRML 2. It
includes discussion of a complete example.
Ames', Nadeau's and Moreland's \The VRML 2.0 Sourcebook" ([Ames et al., 1996a]). Useful
if you want to learn the details. RECOMMENDED if you are interested in the graphics part.
Carey's and Bells's \The Annotated VRML 2.0 Reference Manual" ([Carey et Bell, 1997]).
If you need a reference manual on paper.
Lea, Matsuda, and Miyashita's \Java for 3D and VRML Worlds" ([Lea et al., 1996]). For
VRML and JAVA script nodes.
Roehl's et al. \Late Night VRML 2.0" ([Roehl et al., 1997]) for advanced VRML and Java.
Recommended if you plan to go far and want to buy just one single book.
Note that all of those books do have outdated parts.
Yaw is left-right orientation. Imagine turning your head or your body around to look at
something. \The ship can't hold its track."
Pitch is backwards-forwards up/down orientation. \The ship goes straight into big waves."
Roll is left-right up/down orientation. \The ship is hit on the side by big waves."
Therefore, in 3-D graphics there are six degrees of freedom: 3 positions (x,y,z) plus yaw
(around the y axis ), pitch (around the x axis) and roll (around the z axis)
7 http://www.vrml.org/Speci cations/
8 http://tecfa.unige.ch/guides/vrml/vrml97/spec/
12 CHAPTER 1. STARTING WITH VRML
Transform {
translation 0 2 0
children [
Shape {
1.2. BASIC STATIC VRML 15
geometry Sphere {}
}
]
}
VRML II has about 9 major node types. We will shortly list the features of some important nodes
as explained in detail in the Concepts11 and the =>Node Reference12 sections in the VRML 97
speci cation13 . However, don't worry too much about the exact meaning of these features yet.
The purpose of this list is just giving you an overview of some of \what's there". Once you master
some basics you then should consider going back to reading the the Concepts Section of VRML 97
speci cation in whole !
1. Grouping nodes: =>Grouping nodes are used to create hierarchical transformation graphs.
Grouping nodes have a children eld that contains a list of nodes which are the transformation
descendants of the group. Each grouping node de nes a coordinate space for its children. This
coordinate space is relative to the parent node's coordinate space{that is, transformations
accumulate down the scene graph hierarchy
2. Special groups: The =>Inline is a grouping node that reads its children data from a location
in the World Wide Web. The =>LOD speci es various levels of detail or complexity for a
given object, and provides hints for browsers to automatically choose the appropriate version
of the object based on the distance from the user. The =>Switch grouping node traverses
zero or one of the nodes speci ed in the choice eld
3. Common nodes: Used for things like light, sound, scripts, etc. See the =>Node Reference
Chapter in the specs.
4. Sensors: =>Sensor nodes generate events. Geometric sensor nodes (ProximitySensor, Visibil-
itySensor, TouchSensor, CylinderSensor, PlaneSensor, SphereSensor and the Collision group)
generate events based on user actions, such as a mouse click or navigating close to a particular
object. TimeSensor nodes generate events as time passes.
5. Geometry nodes: =>Geometry nodes must be contained by a Shape node in order to be
visible to the user. The Shape node contains exactly one geometry node in its geometry
eld.
6. Appearance: The Appearance node speci es the visual properties of geometry (see above)
by de ning the material and texture nodes.
7. Interpolators: =>Interpolator nodes are designed for linear keyframed animation.
8. Bindable Nodes: =>Bindable Nodes have the unique behavior that only one of each type
can be active (i.e. a ecting the user's experience) at any point in time.
VRML 1.0 contained 6 major (and 36 minor node) types, i.e:
1. Shape Nodes (such as cubes, text, sphere)
2. Geometry and Material Nodes (such as texture and font style)
3. Transformation Nodes (such as rotation and translation)
4. Camera Nodes
5. Lightning Nodes
11 http://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/concepts.html
12 http://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html
13 http://tecfa.unige.ch/guides/vrml/vrml97/spec/index.html
16 CHAPTER 1. STARTING WITH VRML
6. Group Nodes
Now be careful! VRML is a caseSensitive Language. Respect that or you will get strange
errors!
VRML versions are easy to identify: Just look at the rst line in the le You can translate
most of old VRML I les with the vrml1to2 program14 from Sony.
Transform {
# Move the pen up - a second node specifying a translation
# and a sphere
translation 0 2 0
children [
Shape {
geometry Sphere {}
}
]
}
Ordering is quite simple: VRML is a declarative language and all declaration are executed
in the order they appear. Basically speaking, VRML goes \do this", \do this", etc. However,
VRML nodes can be nested at any level of detail (and should be as you will learn later). The
usual scoping principles apply. E.g. if you insert a Transform node within a Transform node
(you will see that later) transformations applied in the child node are applied within or before the
transformations in the parent node. E.g. within a low level node you can rotate some objects and
then place those objects somewhere else with a higher level node.
Now all you need is a VRML manual and you can start producing VRML les or write programs
that generate VRML. Or can you continue reading this for a little while.
14 http://tecfa.unige.ch/guides/vrml/vrml1to2E.html
1.2. BASIC STATIC VRML 17
1.2.2 Basic Geometry (Shapes)
Per de nition, all basic prede ned shapes in VRML are drawn around the origin and have a
standard size. Size is measured in units (roughly meters in reference to the real world). E.g. a
cube has a standard size of 2 by 2 by 2 meters. Note that sizes are given with oating point
numbers, e.g. 2.0 or .01 or 0.2. Degrees are given in radians.
Table 1.1: Degrees to radians conversion
30: 0.5236
60: 1.0472
90: 1.5708
180: 3.1416
270: 4.7124
You can also use our Javascript Radian Converver
Some objects (i.e. Cylinders and Cones) have named parts which you can avoid drawing (e.g.
the bottom of a cylinder). Per default, all parts are drawn.
Cubes: You can look now at this most simple cube15 .
#VRML V2.0 utf8
#A simple box (was called cube in VRML I)
Shape {
geometry Box {}
}
The box (cube) above might appear as a at rectangle in your browser, turn it around to be
sure it's a 3D object. Also it does not have any color so it will appear as without any shading
(in most or all browsers). If you can't see it in your browser skip this example. Per default, all
objects are drawn o the center of the current origin in all directions. E.g. in the above
case we draw around the [0 0 0] point: 1 left/right, 1 up/down and 1 forward/backwards
leading to a 2 by 2 cube. Just remember this right now: You don't draw towards right, up
and forward, but around the origin, i.e. left-to-right, down-to-up, backwards-to-forwards of
the origin (the current coordinates of the \pen").
Example 1.2.2 A simple oor
VRML: ../examples/basics/basics-shapes-2.wrl
Source: ../examples/basics/basics-shapes-2.text
VRML Full: ../examples/basics/basics-shapes-2V.wrl
Source Full: ../examples/basics/basics-shapes-2V.text
The box here represents something like a oor. If you can't see it in your browser, click on
the \Full" version. As you will learn later, you have to de ne appearance and position the
user someplace he can see something when the scene loads.
Shape {
15 ../examples/basics/basics-shapes-1.wrl
18 CHAPTER 1. STARTING WITH VRML
geometry Box {
size 20 0.1 30
}
}
Spheres: or balls:
#VRML V2.0 utf8
#A large sphere
Shape {
geometry Sphere {
radius 2}
}
Cylinders: Cylinders are more complex. Here is a simple and a more complex example.
#VRML V2.0 utf8
#A long stick
Shape {
geometry Cylinder {
radius 0.1
height 3.0
}
Also note that you wouldn't even display a simple cup this way. You'd have to add some
color and position either the cup or the default view somewhere else (you will learn that
later).
Cones have a height and bottomRadius eld and \Sides" and \Bottom" parts
1.2. BASIC STATIC VRML 19
1.2.3 Positioning Shapes
In order to position objects in a VRML scene (unless you want to move the user's viewpoint) you
have to use the =>Transform16 Node. We will introduce some of its features here.
Example 1.2.4 A simple translation
VRML: ../examples/basics/basics-1.wrl
Source: ../examples/basics/basics-1.text
Let's have a look again at the rst VRML scene shown in this tutorial ( and ignore the contents
of the appearance eld right now). The Sphere is placed on top of a stick (the cylinder) because
we told VRML to move the pen 2.5 up on the y axis. Since the stick is drawn from -1.5 to + 1.5
along the y axis we draw the Sphere (which has a radius of 1) starting with an origin of 1 further
up the y axis.
#VRML V2.0 utf8
# The VRML Primer
# 1997 Daniel K. Schneider, TECFA
# No Copyright, steal this!
#
Transform {
# Move the pen up - a second node specifying a translation
# and a red sphere
translation 0 2.5 0
children [
Shape {
geometry Sphere { radius 1 }
appearance Appearance {
material Material { diffuseColor 1 0 0 }
}
}
]
}
To move to another point in the same frame of reference the Transform node has a transla-
tion eld which allows to move the Pen (e.g. the following objects in the group) in some x-y-z
direction.
Within a Transform node, objects can be embedded (combined) and addressed as a whole.
Concretly, this means that a translation will a ect all the renderings within the same Transform
node) This is why you must use the \children" eld to indicate the nodes which are a ected by a
transformation. (You will see more of that later).
You can also draw overlapping shapes like in the following example:
16 http://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html#Transform
20 CHAPTER 1. STARTING WITH VRML
Example 1.2.5 Overlapping objects
VRML: ../examples/basics/basics-shapes-10.wrl
Source: ../examples/basics/basics-shapes-10.text
Full VRML: ../examples/basics/basics-shapes-10V.wrl
Full Source: ../examples/basics/basics-shapes-10V.text
#VRML V2.0 utf8
# Overlapping shapes
Shape {
geometry Box {
size 3 0.1 0.1
}
}
Shape {
geometry Box {
size 0.1 3 0.1
}
}
Shape {
geometry Box {
size 0.1 0.1 3
}
}
Shape {
geometry Sphere { radius 0.5 }
}
Note that rendering overlapping node is less ecient than drawing ajacent nodes. E.g. if you
want to draw a forest with some balls on top of sticks make sure that the ball does not overlap the
stick (altough the visible result would be the same). Also, if you think that this object looks too
dull on the screen, apply some Material like we did in the Full VRML17 scene. We will look into
this in section 1.2.5).
1.2.4 Rotations
Rotations can be around the x, y and z axis (yaw, roll and pitch). The rotation eld takes 4
arguments: The axis and the degree in radians. A 180 degree rotation is 3.14159 (Pi). Here is a
simple example of a rotation around the z axis:
Example 1.2.6 Simple Rotation example
VRML: ../examples/inter/inter-rotation-1.wrl
Source: ../examples/inter/inter-rotation-1.text
Full VRML: ../examples/inter/inter-rotation-1V.wrl
Full Source: ../examples/inter/inter-rotation-1V.text
The cone is rotated 3.14 radians around z by giving the following arguments to the rotation
eld of the Transform node.
rotation 0 0 1 3.14
Shape {
geometry Box {
size 0.1 10 0.1
}
}
Shape {
geometry Box {
size 10 0.1 0.1
}
}
Shape {
geometry Box {
size 0.1 0.1 10
}
}
Transform {
rotation 0 0 1 3.14
children [
Shape {
geometry Cone {}
}
]
}
Rotation is not that intuitive, but if you play around with a few examples you might nd the
grasp for it. When you de ne a rotation you rst of all de ne the angle of rotation in radians
(the 4th number in the eld). Then you specify around which axis to rotate. Imagine that the the
three axis parameters de ne a diagonal line within a cube. Rotation will happen around this
diagonal ! [drawing needed here]. Rotation has the same e ects as translation. It \reorients" the
pen like any other \transform".
PlayTime: You can intuitively learn more about size, translation and rotation by playing with
the Tiny 3D Applet/Java1.0218. Note that you need a EAI capable browser (most will do).
If your browser understands Java 1.1 widgets (e.g. patched Netscape 4) you can try Tiny 3D
Applet/Java1.119.
1.2.5 De ning appearance
Usually you must use an =>Appearance20 node when drawing objects. Else they will appear
blank, or white, that is dull (or if your headlights are turned o you won't even see a thing at all.
Here you will learn how to use simple colors and how to \dress" objects with bitmap les.
Simple Materials Here is an simple example representing Earth and Sun. The Sun is behind to
the right. If you can't see it, put your client in ip mode and turn the scene around. You will learn
later how to de ne correct viewpoints. (Well if you are in a hurry look at the Full Vrml example).
Example 1.2.7 Simple Materials
18 ../examples/eai/tiny3D-2-java1.0.2/tiny3D-2.html
19 ../examples/eai/tiny3D-2/tiny3D-2.html
20 http://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html#Appearance
22 CHAPTER 1. STARTING WITH VRML
VRML: ../examples/basics/basics-materials-1.wrl
Source: ../examples/basics/basics-materials-1.text
Full VRML: ../examples/basics/basics-materials-1V.wrl
Full Source: ../examples/basics/basics-materials-1V.text
#VRML V2.0 utf8
# Different materials for Earth and Sun
# Sun turns around Earth :)
What is new here are the appearance and the material node. =>Appearance21 nodes de ne the
visual properties (skin) of a polygon. The =>material22 nodes specify surface material properties
for associated geometry nodes and are used by the VRML lighting equations during rendering.
You can select from several types of color. Colors themselves are given as three RGB numbers in
the range of [0,1]. E.g. \di useColor 0 0 1" gives a di use blue.
VRML's lightning model23 is quite complex and we will only make a few short comments about
the elds of the Material node here.
Material {
exposedField SFFloat ambientIntensity 0.2
exposedField SFColor diffuseColor 0.8 0.8 0.8
exposedField SFColor emissiveColor 0 0 0
exposedField SFFloat shininess 0.2
21 http://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html#Appearance
22 http://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html#Material
23 /guides/vrml/vrml97/spec/part1/concepts.html#4.14
1.2. BASIC STATIC VRML 23
exposedField SFColor specularColor 0 0 0
exposedField SFFloat transparency 0
}
Those elds de ne both the color of an objects and the way it re ects light from the de ned light
sources. But please note that lightning e ects are also (and mainly) function of the lights you put
into the scene.
The di useColor eld is the most commonly used. It will (like most real world objects) re ect
light depending on the angle of the surface. The object appears brighter (more lit) when its
surface is directly exposed to light as you would expect.
The emissiveColor eld de nes \glowing objects". E.g. you would use this to build a visible
lamp.
The specularColor eld de nes the color extra re ection has when the angle from the light is
close to the angle you are looking at. It is used together with the shininess eld. Mostly you
would use white color. You can experiment this e ect in real life by holding a (new apple)
or a photograph between you and a window (or a lamp).
The transparency eld speci es how much light is transmitted through the object with 1.0
being completely transparent, and 0.0 completely opaque.
The Color Applet: You should now play a little bit with this applet. It will give you a good
feeling for VRML colors under simple lightning conditions. In addition it will generate a complete
VRML scene for your own usage. Color Appplet: eai/color/
Image Textures There are various of ways of using textures in an =>Appearance24 node. Here,
we will see how to use =>ImageTexture25 node. VRML 2 browsers are required to support JPEG
and PNG le formats. GIF support is only an option, so use JPEGs or PNGs if ever possible !
Here is a very simple node that dresses a cube with a bitmap le.
Shape {
appearance Appearance {
texture ImageTexture {
url "tecfa/mendelsohn.gif"
}
}
geometry Box { }
}
Per default each side of an object will be painted with an image (e.g. cubes will have 6 images,
spheres one, and cylinders two).
Here is a small VRML le that shows some Tecfa people using a few few basics geometric
shapes.
Example 1.2.8 Image texture example
VRML: ../examples/basics/basics-persons-1.wrl
Source: ../examples/basics/basics-persons-1.text
Note how you can repeat textures easily by using a =>TextureTransform26. The \ oor" in
the example above has been created using this technique. The scale eld tells how many times to
repeat a bitmap in the s and t direction. (Note: s and t is more or less like a standard x, y of a
plane). Look at the code below:
24 http://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html#Appearance
25 http://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html#ImageTexture
26 http://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html#TextureTransform
24 CHAPTER 1. STARTING WITH VRML
Transform {
translation -4 -2 2
children [
Shape {
appearance Appearance {
texture ImageTexture {
repeatS TRUE
repeatT TRUE
url "tecfa/sylvere.gif"
}
textureTransform TextureTransform {
scale 10 10
}
}
geometry Box {size 10 0.1 10 }
}
]
}
There is much more to texturing with Bitmaps, e.g. you can combine colors and textures (read
the speci cations or another tutorial).
Transform {
rotation 1 0 0 0.4
children Shape {
appearance Appearance {
material Material {
diffuseColor 0.2 0.1 0.6
} }
geometry Box {
size 20 0.1 10
} } }
Anchor {
url "http://tecfa.unige.ch/"
description "A link to the Tecfa Home page"
children [
Shape {
appearance Appearance {
27 http://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html#Anchor
1.2. BASIC STATIC VRML 25
material Material {
diffuseColor 0 0 1
}
}
geometry Sphere {}
}
]
}
Teleportals Teleportals are doors into other VRML worlds (scenes). They are done with WWW
Anchors. Split up your scene into several ones when rendering, downloading, memory usage, etc.
grows too high. But don't, if you want to avoid loading when people walk frequently back and
forth.
1.2.7 Text
This example draws 2 texts near the origin. Per default, text is aligned left and bottom (i.e.
without translation starts at 0 0 0.
Example 1.2.10 Simple Text
VRML: ../examples/basics/basics-text-2.wrl
Source: ../examples/basics/basics-text-2.text
#VRML V2.0 utf8
Shape {
geometry Text {
string "Le chemin vers l'enfer"
fontStyle FontStyle {
size 2
} }
}
Transform {
translation 0 1.5 0
children [
Shape {
appearance Appearance {
material Material {
diffuseColor 1 1 0
}
}
geometry Text {
string [
"Le chemin vers",
"l'autre enfer"
]
fontStyle FontStyle {
size 2
} } }
]
}
26 CHAPTER 1. STARTING WITH VRML
1.2.8 Exercises
Exercice 1.2.1 Play with the Tiny-3d-2 Applet.
It will allow you to create simple VRML geometry, color, size and move around
it. It also allows you to generate VRML code that you can paste into your editor.
Java 1.1.x (Netscape 4x PATCHED): eai/tiny3D-2/tiny3D-2.html
Java 1.0.x (Netscape 3x,4x): eai/tiny3D-2-java1.0.2/tiny3D-2.html
Exercice 1.2.2 You now might consider building a 3-D information page that points to HTML
les.
You can look at some (simple) pages produced by our students28 .
1.2.9 Moving On
You should at least glance at the next chapter (2) in order to know how you can reuse nodes, build
your own nodes, inline other scences etc.
In any case, you then should read chapter 3 on page 35. Section 3.1 is absolutly mandatory
reading.
If you think that you deserve a break go and check out the worlds at SGI's VRML gallery
which can be found at http://vrml.sgi.com/worlds/.
28 http://tecfa.unige.ch/vrml/tecfa-index.html
Chapter 2
27
28 CHAPTER 2. MODULARIZATION AND ABSTRACTION
geometry Sphere {
}
}
}
DEF LUNA Transform {
translation 1 1 1
children Shape {
geometry Sphere {
radius 0.5
}
}
}
]
}
DEF JUPITER Transform {
children [
# Jupiter and it's 14 moons in here
]
}
]
}
A good and slightly more complex example is the solar system, look at the source form Pesce's
book (translated into VRML II). In addition it has anchors to other URLs (see section 1.2.6).
Now let's see how we can reuse a named object. This example shows for instance how to do
the spikes of a wheel (taken from [Ames et al., 1996b, page 90]).
Example 2.1.1 Rotation: Spikes of a Wheel
VRML: ../examples/inter/inter-rotation-2.wrl
Source: ../examples/inter/inter-rotation-2.text
Note the usage of DEF and USE which will allow you to use multiple instances of the same
Object. In order to better understand what (where) we have drawn we also inlined a drawing of
the x (red color), y (green) and z (blue) axis.
You can make use of the coordinates.wrl1 le yourself if you are not sure what your translations
and rotations do (inlining is explained in section 2.2).
#VRML V2.0 utf8
The next example translates and scales this wheel, i.e. it squeezes it together (half size on y
and z axis and a quarter size on the x axis).
Example 2.1.2 Rotation: Spikes of a Wheel II
VRML: ../examples/inter/inter-rotation-3.wrl
Source: ../examples/inter/inter-rotation-3.text
#VRML V2.0 utf8
Transform {
children [
DEF TUBE Shape {
appearance Appearance {
material Material {
diffuseColor 0.6 0.3 0.1
} }
geometry Cylinder {
radius 0.5
height 5
}
}
Transform {
rotation 0 0 1 1.0472
children USE TUBE
}
Transform {
rotation 0 0 1 2.0944
children USE TUBE
}
]
}
Transform {
translation 0 5 0
scale 0.25 0.5 0.5
children USE TUBE
}
Transform {
translation 0 5 0
scale 0.25 0.5 0.5
rotation 0 0 1 1.0472
30 CHAPTER 2. MODULARIZATION AND ABSTRACTION
children USE TUBE
}
Transform {
translation 0 5 0
scale 0.25 0.5 0.5
rotation 0 0 1 2.0944
children USE TUBE
}
Inline {
url "inter-inline-1.wrl"
bboxSize 0.5 2.5 0.5
}
Transform {
translation 3 0 0
children [
Inline {
url "inter-inline-1.wrl"
bboxSize 0.5 2.5 0.5
}
]
}
2.3. PROTOTYPING 31
Note: insted of a translation one could use the bboxCenter eld.
You can also look at our version of the Castle Example created by Mike McCue at Paper
Software, Inc. (Note that this example has disappeared from the Web, if you know where the
original is, please mail me.)
Example 2.2.2 The Castle Example
VRML: ../examples/castle/castle.wrl
In addition it shows how to de ne multiple cameras and how to use GIFs for texturing. Note,
that this example needs some polishing. In order to look at the les just cd to the ../exam-
ples/castle/castle.wrl directory and click on the *.text les. They are identical with the *.wrl
les.
2.3 Prototyping
Once you build more complex objects you want to reuse smaller elements in di erent ways. So,
learning how to de ne =>PROTO node2 is important before you really start to produce a lot
of VRML code. PROTOs de ne a new node name with custom elds you can specify. In
other words, PROTOs allow you to extend the language by adding your own nodes. In this
respect, PROTOs are much more powerful than simple DEFs/USEs that only allow to apply
transformations to reused objects.
The structure of a simple PROTO is the following:
PROTO prototypename [ field fieldtypename name defaultValue
field fieldtypename name defaultValue
... ]
{node}
Let's look shortly at the de nition of elds. Here is an example taken from below:
field SFColor legColor .8 .4 .7
eld is just a keyword you must use. SFColor is a valid VRML \ eld type name" (see section 8.4
on page 87. legColor is the name that the eld will have and \.8 .4 .7" are it's default values. If
this is unclear, go through the next two examples and see how they are used.
Example 2.3.1 Three Stools
VRML: ../examples/inter/inter-proto-1.wrl
Source: ../examples/inter/inter-proto-1.text
Here is an example of three stools. It is taken from the =>VRML II Speci cation3 .
It de nes a \TwoColorStool" node with two public elds named \legColor" and \seatColor"
that one can modify when making instances. Note that there are default colors (pink legs and a
yellow seat)
#VRML V2.0 utf8
TwoColorStool {
legColor 1 0 0 seatColor 0 1 0
}
# The chair to the right has yellow legs and a bright blue seat:
Transform {
translation 2 0 0
children [
TwoColorStool {
legColor 1 1 0 seatColor 0 1 1
}
2.3. PROTOTYPING 33
]
}
Transform {
translation -2 0 0
children [
TwoColorStool {
}
]
}
You can look at an another (locally produced) example that uses embedded protos: Patrick4
Jermann's MOO Ants.
Example 2.3.2 Moo Ants PROTO Example
VRML: ../examples/inter/inter-proto-ant.wrl
Source: ../examples/inter/inter-proto-ant.text
This example uses PROTOS within PROTOS, a facility which can add additional modularity
to your VRML worlds.
2.3.1 Exercises
Exercice 2.3.1 A forest without Snow White
Build a little forest on a at plane
Build a proto made of a cylinder (the trunk) and a cone
Build a proto made of a cylinder and a ball
Both protos should allow you to de ne their position and their color.
4 http://tecfa.unige.ch/%7Ejermann/
34 CHAPTER 2. MODULARIZATION AND ABSTRACTION
Chapter 3
Note: be careful with this. Some browsers (e.g. Community Place) will not allow the user to
switch modes once you de ned one in your le. E.g. when you put the browser in \examination"
(or ip) mode, the user won't be able to turn back into \walking" mode. In this case, use:
NavigationInfo { type [ "EXAMINE", "ANY" ] } # Examine viewer but allow change
Viewpoints Looking at some examples you wrote, you probably noticed that your \scene" (or
yourself) is not at the \right place".
The most simple thing you can do is to de ne a single default =>Viewpoint2 that places the
user at the right distance from the object. Per default, browsers are supposed to put you at (0
0 10) which is ne for viewing small objects. In the following example we place the viewpoint 12
\meters" in front, 3 \meters" up, and 2 \meters" to the right.
Viewpoint { position 2 3 12 }
1 http://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html#NavigationInfo
2 http://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html#Viewpoint
35
36 CHAPTER 3. GOOD VRML STYLE AND PERFORMANCE
The Viewpoint node is more complex than that. You can also give an orientation to the view
(\look into a direction"). It works the same way as rotation does (see section 1.2.4).
Once you have de ned a few viewpoints (and DEFed them with a name), it is important to
ll in the description eld if you want people to be able to use the \viewpoints" menu in their
browser. Here is an example:
Next, you can use viewpoints to organize \tour guides". The next example shows how to
organize a simple guided tour.
Example 3.1.1 A simple ugly tour guide
VRML: ../examples/inter/inter-tour-guide.wrl
Source: ../examples/inter/inter-tour-guide.text
In particular, look at the following details:
how we use the di erent Viewpoint elds (position, description, jump, orientation and eld-
ofView)
The anchor construct is used to jump around. Each DEFed Viewpoint can be accessed with
\internal #xxx" tags. Viewpoints are the VRML equivalent of HTML \name" tags.
Information about your World Instead of putting information about your world in comments
at the beginning of the le, you better should use the =>WorldInfo3 node. Here is an example:
WorldInfo {
info ["A sample home page", "steal it if you like", "Version 1 - Feb 97"]
title "Ka's kewl home page"
}
Note, that you completely can hide away an object by specifying an empty node as the last
level with something like:
Group { children [ ] }
Also, remember that inlined worlds are only loaded on need (at least in Cosmo Win Beta3a). Both
features are useful for building larger scenes.
This example shows Tecfa People at three levels of details: (1) as an uninteresting box if
you look at it from far away, (2) as a group and as (3) individuals if you get closer. Just walk
FORWARD to see the e ect !
Example 3.2.1 Tecfa People LOD
VRML: ../examples/inter/inter-LOD-1.wrl
Source: ../examples/inter/inter-LOD-1.wrl
Of course, this example needs some tuning. First of all, distances should be bigger to have a
smoother \getting closer" e ect and most of all di erent levels of detail ought to have more similar
shapes and appearance. For a better example see page 52 in ([Hartman et Wernecke, 1996] or visit
directly the Tenochtitlan Web Site5 .
But as the above examples shows, LOD nodes can be used not just levels of details, but di erent
functionality, e.g. the mid-level of detail is an anchor to a group WWW page of people, whereas
at the detail level you get anchors to some person's home pages.
4.1 Introduction
There exist several kinds of possible links between HTML and VRML. The most frequently used
are the following:
HTML-VRML links:
<A HREF="../examples/basics/basics-shapes-10V.wrl">My world</A> will replace
your html page by a VRML scene. (a VRML page)
<A HREF="../examples/basics/basics-shapes-10V.wrl TARGET="_blank">My world</A>
will open a new browser window. This is recommended way to bring (non-embedded) VRML
scenes things to newbie Internet users. Others should know how to open another browser
window.
You can also combine HTML and VRML in various frames. See the next section for details.
Embeding a VRML browser in a HTML Page: Use the <embed> tag, e.g. something like
<EMBED align=center
src="../examples/basics/basics-shapes-10V.wrl" border=0
width=180 height=180>
in order to embed a VRML plug-in window within a HTML page. If you don't need to display
large VRML scenes, this is the recommended way to do it (rather then using frames).
VRML-HTML links: See section 1.2.6 on page 24. Note that can you pass parameters like
target= if you want for example the user to open up another HTML frame when clicking on a
VRML object.
You can also use the Browser object in a Script node (make sure to have a recent browser !)
for more sophisticated stu :
Browser.loadURL(url, parameter);
e.g.
Browser.loadURL("publicity.html", "target=_new");
If you want to launch a new window, use 'target=_new' for the parameter. If you want to target
a frame named explanation, use 'target=explanation' for the parameter.
39
40 CHAPTER 4. MIXING HTML WITH VRML
JAVA, Javascript, VRML, HTML links: Of course you can do more crazy stu (more to
follow maybe one day) but just be aware that \Javascript" inside VRML is NOT Netscape's (or
whatever) language. see section 5.3 on page 58 for some more information.
</FRAMESET>
</HTML>
The contents of the les frame-1-source.html and frame-1-vrml.html does not matter since
they will be replaced anyhow by either code listing or your VRML plug-in.
Now, all you need to do in order to display a link in frame-1-contens.html in the right frame
is to use a \TARGET" eld in the \A HREF" tag as in the following example:
<HTML>
<HEAD>
<TITLE>Contents ( 7-Mar-1997)</TITLE>
<!-- Changed by: D.K.S., 7-Mar-1997 -->
</HEAD>
<BODY>
<H1>Contents</H1>
..... and so on
Now let's see how we tell the VRML plug-in to display links in another frame:
# LEVEL II: The bunch as a whole
Anchor {
url "http://tecfa.unige.ch/tecfa-people/tecfa-people.html"
description "A link to Tecfa People"
parameter "target=contents"
children [
Transform { .......
The code for this example3 is exactly the same as for the LOD example4 in section 3.2 on page 36,
except for the parameter eld.
Note that we also generate dynamically an inital object in the frame by directly calling
javascript:top.vrml(). We could have left this page blank or inserted some canned VRML
*.wrl page. Just remember that the frame to the left is called menu_frame and the frame to the
right vrml_frame.
The user enters size and color information in the left (HTML/Javascript) frame and then can
click on \Create Box". This will render the object in the VRML frame to the right.
This is a simple HTML Form that will collect information from the user. Note the following
things:
1. The \form" tag has just a name eld (no method eld needed)
2. The input \button" will trigger an onClick event when pressed that will launch the \make-
Box" script. This script will then poll the form for values the user entered (see below).
<FORM NAME="cont">
<STRONG>Example Objects:</STRONG><p>
<STRONG>Custom Box:</STRONG><p>
Width : <INPUT TYPE="text" NAME="w" VALUE="1" SIZE="5"><br>
Height : <INPUT TYPE="text" NAME="h" VALUE="1" SIZE="5"><br>
Depth : <INPUT TYPE="text" NAME="d" VALUE="1" SIZE="5"><p>
Colors (be sure to enter values between 0 and 1!<br>
Red : <INPUT TYPE="text" NAME="red" VALUE="1" SIZE="5"><br>
Green : <INPUT TYPE="text" NAME="green" VALUE="0.2" SIZE="5"><br>
Blue : <INPUT TYPE="text" NAME="blue" VALUE="0" SIZE="5"><p>
Here are the most important elements of the (simpli ed) source code. The function makeBOX
will draw a box of a given size in given colors. It will access the values entered in the form below
and write lines to the VRML frame.
In this example (like in the original) we poll the values the user entered from the form, e.g.:
w = top.menu_frame.document.cont.w.value;
will assign the value for the width of the box to a temporary variable \w". There are several ways
of doing this as you can note. Also note that polling the form is one way of doing it. Alternatively
we could have passed the values to this function within the INPUT tag of the form. Finally be
aware that we do not any value checking. It's up to the user to enter good values.
7 http://developer.netscape.com/library/documentation/
8 http://tecfa.unige.ch/guides/java/javascript/
44 CHAPTER 4. MIXING HTML WITH VRML
var MIMEType = 'x-world/x-vrml';
function makeBOX() {
var w, h, d, red, green, blue;
// Note: all these ways of accessing values work
w = top.menu_frame.document.cont.w.value;
h = top.menu_frame.document.forms[0].h.value;
d = document.forms[0].d.value;
r = document.forms[0].red.value;
g = document.forms[0].green.value;
b = document.forms[0].blue.value;
with (top.vrml_frame.document) {
open(MIMEType);
writeln('#VRML V2.0 utf8');
writeln('Shape \{');
writeln(' appearance Appearance \{');
writeln(' material Material \{ ');
writeln(' emissiveColor ' + r + ' ' + g + ' ' + b);
writeln(' \} \}');
writeln(' geometry Box \{');
writeln(' size ' + w + ' ' + h + ' ' + d)
writeln('\} \}');
close();
}
}
The only other thing you need to know is how to write to the VRML frame:
1. We rst get some handling on the VRML frame's document window object. The with
statement makes referring to objects properties and methods simpler (you don't have to type
the full path each time). In the following expression top refers to the \top" node in the
Javascript hierarchy (?), vrml_frame is the name we gave to the frame where the plugin will
appear and document refers to it's contents.
with (top.vrml_frame.document) {
Next we de ne a place where we want to put a cousin of the DEFed object. Note the empty
children [ ] of the BoxHolder Node.
DEF Scene Group {
children [
...................
DEF BoxHolder Transform {
translation 0 1 0
children [ ]
}
...................
] }
A little script will be activated by the touchsensor, because of this route statement:
ROUTE MakeRedBox.isActive TO GenBoxS.isActive
and then activate in turn two routes that remove/add the node.
ROUTE GenBoxS.child TO RedBoxSwitch.removeChildren
ROUTE GenBoxS.child TO BoxHolder.addChildren
The next example is slightly more complicated, because it will allow you to \reset" the scene.
Note that it breaks with Cosmo and works with WorldView.... maybe my fault. [Will have to work
on this when I have time].
Example 4.4.2 Add/Remove DEFed objects (and reset) II
Contents: add/remove Children
VRML: generate-js-6.wrl
Cosmo: generate-js-6C.wrl
Source: generate-js-6.text
Compared to the above example we need to add a few things: We want to add a cousin to
the place where we have removed a childe after a reset. So a typical node now looks like this (it
includes the RedBoxHolder) Group from which we will remove/add a child:
Below is the script that will reset the scene. Note how we bind objects in the script in order to
do some direct output (instead of using lots of routes):
url "javascript:
function isActive(value) {
redBallHolder.addChildren = redBall;
4.4. ADDING AND REMOVING KIDS WITH JAVASCRIPT 47
blueBallHolder.addChildren = blueBall;
redBoxHolder.addChildren = redBox;
boxHolder.removeChildren = redBox;
sphereHolder.removeChildren = redBall;
sphereHolder.removeChildren = blueBall;
}
"
}
Introduction to moving,
interactive VRML
DISCLAIMER: I don't really understand a lot about VRML and even less about interactive VRML.
In addition, some code is simply disgusting (blatant lack of abstraction and some
Voodoo code lines). Will clean this up progressively.
This chapter will graducally build up. So far, just consider that there is an order of complexity
in doing/learning VRML:
1. Understanding Events and ROUTE
2. Doing simple routes from sensors to objects
3. Adding Interpolators
4. Pluging some Javascript (or VRMLScript) in between
5. Doing things with JAVA
6. Connecting up to a multi-user server
I intend to look into all of these at some point. Right now this chapter covers some of 1-4 (not
enough!).
49
50 CHAPTER 5. INTRODUCTION TO MOVING, INTERACTIVE VRML
Node 1, e.g sensor Node 2, e.g. script Node 3, e.g. light
1 EventIn EventIn
UTE 2
RO E
UT
RO
EventOut EventOut
you can hook together nodes by de ning a route that links together any outcoming and incoming
event of the same time. In the next sections you will learn how to to this.
In some cases, user triggered events are rst routed to a script node. Scripts in VRML are just
a kind of VRML nodes, but nodes that can compute and that can make changes to any kind of
exposed VRML elds. Figure 5.1 describes such a setup.
At a more abstract level we can describe a typical \Animation Event Path" as described
in chapter 9 [Hartman et Wernecke, 1996], a book you might want to buy if you want a better
introduction. More sophisticated animations are triggered o by some sensor, (e.g. the user clicks
on an object), the event generated by the browser is routed to a script that will trigger a timer.
The timer will trigger a engine (e.g. a position interpolator for moving objects) which in turn
a ect a VRML object (e.g. the position eld of a transform node).
In the next section (5.2) will rst teach you how to do animation without scripting and we will
introduce the other elements of the typical animation path
In order to rotate the object, you want to able to change the value of the rotation eld.
Events: All exposed elds of a VRML node can be changed via incoming events. E.g. if you
look at the de nition of the Transform node, you can see that you can for example scale or rotate
or translate and object, and even add or remove nodes from its children.
Transform {
eventIn MFNode addChildren
eventIn MFNode removeChildren
exposedField SFVec3f center 0 0 0
5.2. INTRODUCTION TO EVENTS, ROUTES, SENSORS AND INTERPOLATORS 51
Script
Timer
A simple sensor switches light example Before reading further on, you might want to have
a look at the example.
Example 5.2.1 A Simple Touchsensor E ect
VRML: ../examples/anim/anim-touch-1.wrl
Source: ../examples/anim/anim-touch-1.text
Click on the \switch" and the blue sphere will be lit while you hold down the mouse. Holding
down the mouse over the sensor means that the LIGHT CONTROL.isActive is TRUE, releasing
the mouse makes it FALSE again.
Here are the important parts of the code:
# A TouchSensor
#(in the same group as a geometry object so that it can be seen)
#
Transform {
translation 0.5 1 5
children [
DEF LIGHT_CONTROL TouchSensor {
}
Inline { url ["light-switch.wrl"] }
]
}
As you can see in the following de nition of the =>PointLight7 node, it has an exposedField
(i.e. accessible eld) called \on". All the ROUTE statement above does, is to de ne a connection
between the sensor's isActive event to the PointLight's set on event (i.e. to the value of the
on eld of PointLight. As in other GUIs it's the browser that will handle the routing of user
actions (events) to sensors, i.e. they will become active. Below we give the complete de nition
of PointLight and you can see that there is indeed a exposedField \on" and therefore implictely a
set on event de ned. [Yes I know, a section on lights is missing in this manual.]
7 http://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html#PointLight
54 CHAPTER 5. INTRODUCTION TO MOVING, INTERACTIVE VRML
PointLight {
exposedField SFFloat ambientIntensity 0
exposedField SFVec3f attenuation 1 0 0
exposedField SFColor color 1 1 1
exposedField SFFloat intensity 1
exposedField SFVec3f location 0 0 0
exposedField SFBool on TRUE
exposedField SFFloat radius 100
}
Of course you can also make light switches that will turn on some light permanently but (if
I am not wrong) you have to do this with some scripting (see section 5.3.1 on page 59 that does
exactly this). But before we look into scripting, let's learn a few more things about events.
When a TimeSensor becomes active it will generate an isActive = TRUE event and begin gener-
ating time, fraction changed, and cycleTime events, which may be routed to other nodes to drive
animation or simulated behaviors. The two most important output events are:
isActive which will output TRUE at timer start and FALSE at timer stop
fraction changed which will output values from 0.0 to 1.0 during a cycle. At the start of
each cycle its value is 0.0
We will discuss more about those events in the example further down.
We route the fraction changed event to a so called OrientationInterpolator whose time-sensor
triggered output is then sent to the object we are rotating. In order to guarantee a smooth
animation, it will compute vaious orientation points as you will learn below.
The Orientation Interpolator Let's look at the =>OrientationInterpolators11 which is one
kind of VRML's =>Interpolators12 . In short, they allow you do simple animations (e.g.rotate
objects, move objects around, change colors of things). An interpolator will generate values based
on \clues" de ned by a set of keys (received from the set faction eventIn) and a set of correspond-
ing keyValues. In other words, it will automatically compute intermediate positions for each
time fraction. You only have to specify a few to get it going like in the example below. Key Values
are of a di erent type for each Interpolator. Here is the de nition for the OrientationInterpolator:
OrientationInterpolator {
eventIn SFFloat set_fraction
exposedField MFFloat key []
exposedField MFRotation keyValue []
eventOut SFRotation value_changed
}
A simple Time Sensor/Orientation Interpolator example You now can rst look at the
example before reading on.
Example 5.2.2 A simple Timesensor Example
VRML: ../examples/anim/anim-rotate-1.wrl
Source: ../examples/anim/anim-rotate-1.text
Below, you can see both the de nition of the Orientation Interpolator and the ROUTE state-
ments of the example world.
The keyValue eld is of type MFRotation, i.e. a comma separated set of orientation values that
correspond to each element in the key eld. In our example you can see that we rotate around the y
axis (0 1 0) using orientations 0, 3.1416 and 6.2832. VRML now uses those positions to interpolate,
i.e. to generate rotation values in between which are sent out with value changed eventOUT each
time the node receives a set fraction eventIN.
The set fraction event is of type SFFloat in the range of [0,1] and usually routed to from a
TimeSensor's fraction changed event. The fraction changed event is an indicater in the range
of [0,1] that tells how much of a complete cycle has elapsed so far. The duration of a cycle itself
is de ned in seconds by the cycleInterval eld. E.g. in our example, the interval is 20 seconds.
DEF TIME TimeSensor {
cycleInterval 20
......
}
Indeed, if you look again at this simple rotation example13 you can see that a full rotation lasts
about 20 seconds. Rotation speed is constant, because we told the interpolator so with the
key/keyValues.
To sum it up Interpolators:
the set fraction input event will set the current fraction along the key path
the value changed output event will output the position according to the keyValue path
each time the fraction is set.
The next example shows some more irregular rotation (randomly put together).
Example 5.2.3 A simple Timesensor Example II
VRML: ../examples/anim/anim-rotate-2.wrl
Source: ../examples/anim/anim-rotate-2.text
Of course, eternal rotations can be annoying to the user and they certainly waste resources.
Since (as far as I understand it) there is no way to start and stop animation at a given time after
the scene has been loaded (time is in seconds starting some obscure date) you'd have to write a
touchsensor that activates the rotation and do some Javascript for that.
13 ../examples/anim/anim-rotate-1.wrl
5.2. INTRODUCTION TO EVENTS, ROUTES, SENSORS AND INTERPOLATORS 57
5.2.2 More on Time Sensors and Interpolators
Let's see how to \con gure" a TimeSensor according to your needs:
1. Continously running:
loop TRUE
stopTime < startTime
The next example inspired from David Frerichs' exellent Creating Integrated Web Content with
VRML 2.0 Tutorial14 In this example you can see something sliding forth and back once you click
on the little red switch.
Example 5.2.4 A TouchSensor activating a Shuttle
VRML: ../examples/anim/anim-shuttle-1.wrl
Source: ../examples/anim/anim-shuttle-1.text
Let's have a look at things that are new: When we load the le, the TimeSensor (called
TimeSource here) has the loop = FALSE, so there will be no eventOUTs looping:
DEF TimeSource TimeSensor {
cycleInterval 10
loop FALSE
}
Then we use a TouchSensor node (see section 5.2 on 50) to activate the loop. More precisely,
the Starter.isActive event (Touchsensor) is routed to TimeSource.set loop (Timesensor). As soon
as you click on the switch the loop will be turned on (and remain so). Here is the code of the
switch and it's route:
Finally, in order to move the object forth and back we use a =>PositionInterpolator15 that
works more or less the same way as the OrientationInterpolator encountered in the previous section.
The keyValue elds are the kinds of values (SFVec3f) that one uses in translation elds. Here is
the other half of the code:
14 http://reality.sgi.com/frerichs esd/course/index.html
15 http://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html#PositionInterpolator
58 CHAPTER 5. INTRODUCTION TO MOVING, INTERACTIVE VRML
DEF TECFA Transform {
translation 0 0 -50
children [
DEF TimeSource TimeSensor {
cycleInterval 10
loop FALSE
}
As you will learn in the examples in the next sections, the \url" elds contains either a pointer
to a script le or a full script.
The VRML standard leaves it open to the browser manufactures what language they will
support for scripting. However, if they implement scripting with either JAVA or JavaScript,
conformance to the spectifcations is required!
In this tutorial we don't teach you how to program with JavaScript or even to program in the
abstract. See our JavaScript Page17 for the most important pointers that will help you to get
started. There are 2-3 good on-line tutorials and several good books. Scripting with JavaScript
will be based on the ECMAScript18 scripting language with extensions that are required for the
VRML plug-in. I.e. it does not contain typical Netscape objects. This means for example that
you can't open popup windows and such!
16 http://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html#Script
17 http://tecfa.unige.ch/guides/js/pointers.html
18 /guides/vrml/vrml97/spec/part1/javascript.html
5.3. INTRODUCTION TO SCRIPTING WITH JAVASCRIPT 59
WARNING: If you use the Cosmo 1.02 on Win95 for any reason (you should not) or Cosmo
1.02 on Irix (you have to), you have either to replace:
url "javascript: ...
by
url "vrmlscript: ...
The better solution is just to duplicate the code within the url eld as in the following example.
Your browser will pick whatever he likes best.
url [
"javascript: ......
",
"vrmlscript: ......
"]
From the little I have looked at the documentation, vrmlscript looks more or less like javascript,
i.e. it implements a subset that contains most functionalities you need to get started. My examples
all work the same (except for the name of the language). Compare yourself:
VrmlScript Reference 19
JavaScript Reference 20
Let's look at the JavaScript node called lightONScript now: We de ne a =>Script21 node with
two mandatory slots: \eventIn" and \eventOut". For each of those slots we must de ne its type
(in our case we use SFBool since both the TouchSensor's and the light's elds we are interested in
are either on or o , i.e. TRUE or FALSE). The second argument are the event names that must
be unique identi ers within the scope of the node.
DEF lightONScript Script {
eventIn SFBool lightONIsActive
eventOut SFBool lightIsON
url "javascript:
function lightONIsActive(active) {
lightIsON = TRUE;
}"
}
In order to compute the eventOUT from the eventIn we must assign a function to the \url" eld.
That function has the same name as eventIn and assigns a value to the variable of eventOut
[hmmmm this does not sound very clean]. Now where do we put the function ? Either we insert
the function as string in the url eld or we use an URL that points to a script. (Note, that you
can write several functions if needed).
As you can see, the script is fairly simple. It takes one argument (the value of eventIn, which
we don't use here) and sets the value of the eventOUT.
In order to change a value of a node, you don't actually need to ROUTE the eventOUT. Instead
you can directly set a value within the Scripting node. Here is how you do it:
# Clicking on the green Light Switch (ON)
#
DEF lightONScript Script {
eventIn SFBool lightONIsActive
field SFNode node USE LIGHT
directOutput TRUE
url "javascript:
function lightONIsActive(active) {
node.set_on = TRUE;
}"
}
In the line
21 http://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html#Script
5.3. INTRODUCTION TO SCRIPTING WITH JAVASCRIPT 61
field SFNode node USE LIGHT
we bind the LIGHT node to \node" and in the function we can simply send an event to the \set on"
eventIn of the LIGHT on with
node.set_on = TRUE;
Our state variable that will remember if the light is on or o is declared as a boolean (note
that name \state" is our choice):
field SFBool state FALSE
Now if you read the speci cations of the =>Touch Sensor23 node again you will learn that when
the user clicks on it, it generates an isActive Event==TRUE. However when the user releases the
mouse button, an isActive Event==FALSE is generated.
We are not interested in the fact that the user releases a button, so we ignore it. When we pass
the value of the eventIn Field lightIsActive to the function we only do something if it is TRUE (as
we said before):
if (active) { .... }
Within the \big" if clause we then look at the value of our state variable. If state = FALSE
we know that the light is o and we will turn it on and remember it by toggling the state variable.
On the contrary we will turn the light on and remember that too.
Now of course we also should change the color of the light button. There are many ways to do
it, e.g. change the color of the little cube or use a switch node to insert another one. We leave
that exercice to the reader.
Well, now did we really had to make use of state variable ? The answer is NO. The PointLight
node itself perfectly knows if it is on or o and we could have asked it each time the script
node receives a \lightIsActive" Event. The next example exactly does this. However to show the
usefulness of state variables we now count the number of times a user has switched on the light.
After 10 trials we will turn on another light that will be lit permanently with the hope that this
will discourage the person from playing too much with light switches.
Example 5.3.5 The Light-on problem with VRML state)
VRML: ../examples/anim/anim-touch-state2.wrl
Source: ../examples/anim/anim-touch-state2.text
Contents: JavaScript, TouchSensor, VRML state
In order to do this we \USE" again handlers to VRML nodes somewhere in the scene as shown
in the two following lines of code:
field SFNode node USE LIGHT
field SFNode node2 USE LIGHT2
Instead of asking a state variable if the light is on we then go and ask the light itself:
if (node.on == FALSE) {....}
Note that you can't turn it o again. Below you can study the whole function:
DEF lightScript Script {
eventIn SFBool lightIsActive
eventOut SFBool fixLightState
field SFNode node USE LIGHT
field SFNode node2 USE LIGHT2
field SFInt32 n 0
directOutput TRUE
}",
"vrmlscript:
function lightIsActive(active) {
if (active) {
if (node.on == FALSE) {
n = n+1;
node.set_on = TRUE;
if (n > 10) {
node2.set_on = TRUE;
}
}
else {
node.set_on = FALSE;
}
}
}",
]
}
All this (I hope) did give you an idea about the \dynamics" potential of VRML. It wouldn't
take much more to program a little bug that would crawl into the scene and remove the light
switch for example after somebody played too much with it.
The WhichChoice eld speci es the index of the list of nodes in choice that will be displayed.
Note that the rst element in the list is 0. If the index is less than 0 or bigger than than number
of nodes, nothing is chosen.
The only tricky stu (assumed that you understood the previous examples) is how to deal with
the fact that all nodes under a Switch continue to receive and send events (i.e.routes) regardless
of the value of whichChoice. So maybe what I did here is more or less illegal. I let you study the
examples by yourself. In any case this example shows a particularly dumb way of programming a
on/o switch but it also introduced the important switch node.
Example 5.3.6 The Light-on problem switch the dumb way(a)
VRML: ../examples/anim/anim-touch-4.wrl
Source: ../examples/anim/anim-touch-4.text
Contents: JavaScript, TouchSensor, Switch Node
Example 5.3.7 The Light-on problem switch the dumb way (b)
VRML: ../examples/anim/anim-touch-5.wrl
Source: ../examples/anim/anim-touch-5.text
Contents: JavaScript, TouchSensor, Switch Node
5.3.4 Scripting with TimeSensors
If you don't know the basics about =>TimeSensors25 , go and read section 5.2.1 on 54 again.
You can manipulate the following eventIns (among others):
set loop whether it should loop over cycles
set enabled whether the time sensor is enabled.
In the next simple example we will show how to start and stop some animation. You can see
something sliding forth and back once you click on the little green switch and you stop it with the
red switch.
Example 5.3.8 Activating and Stopping a Shuttle
VRML: ../examples/anim/anim-shuttle-2.wrl
Source: ../examples/anim/anim-shuttle-2.text
This example used pretty much the same interface mechanism as the light examples. However
it represents an additional element in the interaction, i.e. an animation element.
25 http://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html#TimeSensor
Chapter 6
65
66 CHAPTER 6. THE EXTERNAL AUTHORING INTERFACE
Note that VRML can also talk to the EAI \on its own initiative" as we shall learn later.
Everything you can do within in script node (e.g. by using Java/VrmlScript or the the Java
Scripting Application Interface) you can do with the EAI. However, in many situations it is better
to use the Script Interface [more later].
Here are a few typical situations where you need or should use the EAI:
Control of interactive multimedia presentations involving more than VRML.
Visualizations needing a 2-D interface applet that controls the VRML scene in real time (e.g.
users slides a button and something grows/shrinks/moves in the scene).
Custom VRML navigation
Multiuser Worlds with chat windows and other networking applications that need a user
interface applet. (Note however that Sony's system3 is based upon the JSAI, but you need
a special browser)
<HTML>
<HEAD>
<TITLE>Typical HTML EAI/VRML/JAVA file</TITLE>
</HEAD>
<BODY>
<H1>Typical HTML EAI/VRML/JAVA file</H1>
</BODY>
3 http://sonypic.com/vs/
6.2. THE VERY FIRST STEPS 67
</HTML>
Note, that you can copy this template4 for your own use. Also make sure to include the
MAYSCRIPT parameter in the <applet> tag. Finally, if you never have seen any EAI applet you
can browse though our examples5 if you wish.
The Java classes you need are all in the vrml.external package. Make sure that you do not
include the vrml, vrml.node and vrml.field packages in the Java Classpath. These are reserved
for the scripting interface and will con ict. 6 Therefore a typical applet skeleton would look like
this:
import java.awt.*;
import java.applet.*;
import vrml.external.*;
We then can use the getBrowser method of the Browser class to get a browser reference:
browser = Browser.getBrowser(this);
Now let's look at a complete applet that does just about this and nothing much else:
Example 6.2.1 EAI: The do nothing applet
Contents: getBrowser(),
HTML page: eai/getbrowser/get-browser.html
JAVA code: eai/getbrowser/get-browser.java
(dir): (dir)
// Example applet illustrating getting a browser reference
import java.awt.*;
import java.applet.*;
import vrml.external.*;
Note that getBrowser() is a static method that ought to work with most modern browsers. In
some older code that oats around or in tricky situations (e.g. nding an embedded something
within a table I believe) you can nd the following alternative:
import netscape.javascript.JSObject;
....
JSObject win = JSObject.getWindow(this);
JSObject doc = (JSObject) win.getMember("document");
JSObject embeds = (JSObject) doc.getMember("embeds");
browser = (Browser) embeds.getSlot(0);
Java Widgets: The example's last piece of code we need to discuss relates to the \user interface":
// Paint something to the applet so that you can see something :)
add (new Label ("This is the Java Applet with a "));
add (new Button ("No nothing button"));
Those two lines add a label and a button. Note that it is a good idea to start learning some basic
widget programming if you haven't already done so. However we will explain somewhat the simple
widgets we use in the other examples of this chapter.
Trouble with getBrowser(): Chances are there that the above will not work (even if you did
install a recent VRML browser and did compile the classes as you should have). One reason might
be that your applet needs more than one trial in order to get the browser reference. Instead of the
code above you will have to to use something like this:
This template7 is also available on-line. Now let's start for real !
In order to do so, we must rst get a reference to the node which de nes the color, i.e.
DEF MAT Material {...} . Next, we need a reference to the set_diffuseColor eld. Finally,
we we must be able to set a value to this EventIn eld. The following example just does this:
Example 6.3.1 EAI: RGB Change Applet
Contents: getNode(), getEventIn()
HTML page: eai/rgb-change/rgb-change.html
JAVA Code: eai/rgb-change/RGBChange.java
Directory: (dir)
Here is the relevant code in the Java applet for getting the node and eld references:
The browser.getNode("MAT") method will get a reference to the material node which we
called \MAT" in the VRML scene.
The material.getEventIn("set_diffuseColor") method will do the same for the eventIn
eld.
.....
Node material = null;
EventInSFColor diffuseColor = null;
......
Java programming comments: Java Newbies need some more explanation (others can skip
this): The reference to the VRML browser is hold by a variable we called \browser". It has
been initialized of type \Browser". Browser is a class that de nes the \getNode" method allow-
ing to retrieve named nodes from the VRML scene. In a similar way we assigned the result of
72 CHAPTER 6. THE EXTERNAL AUTHORING INTERFACE
browser.getNode("MAT") to the material variable we declared as type Node. Let's just show you
the de nition of the \Node" class from the EAI Spec8 (in Java code format):
public Node getNode(String name)
throws InvalidNodeException;
This means that getNode (a) wants as argument a node name (the string of a DEF), (b) returns
an instance of a Node class (i.e. the reference to a node) unless it fails in which case it signals an
InvalidNodeException. More later about this latter case.
Now the \Node" class de nes a method called getEvent that will return an instance of the
EventIn class. However you must cast (i.e. translate) this instance to the appropriate class you are
interested in. The reason is that getEventIn can return di erent types of values. In our example
we cast to (EventInSFColor) in the following line:
diffuseColor = (EventInSFColor) material.getEventIn("set_diffuseColor");
You have to do this everytime you deal with some event elds. The EAI Spec is pretty self
explaining about those types. So far, we only have the handles on VRML things we want to
manipulate. In order to obtain what we want we now must proceed with some ordinary Java
coding. If you look at the Java code and the applet you can see that we painted three simple
buttons:
// paint 3 simple Java buttons
add(new Button("Red"));
add(new Button("Green"));
add(new Button("Blue"));
The Applet class which is imported from java.applet.* is a child of the java.awt.Component9
class which de nes a simple action10 event method. This method is activated (i.e. called) with the
Event and the Object triggered when the user clicks on a button. The programmer now has to
deal with the event, i.e. implement an \action" method for this applet. Since the \action" method
is depreciated in Java 1.1. we will not explain much here, but revise the code once most Netscape
and VRML plug-in users will have versions that fully support Java 1.1.
Java Event handling and writing to the VRML scene: Let's just look at the VRML related
part for dealing with the Blue button:
Lines like:
add(new TextField("Failed to get node:" + ne));
will paint a text eld on the Java Applet with the error message we de ned. (Note, that we could
just have written something to the Java Console instead.) In addition, the catch statements will
set the \error" variable to true. If true the action method will not try to handle any events, i.e. it
will just exit. Below is the the code (in old Java 1.0.x style) that whill handle the event.
74 CHAPTER 6. THE EXTERNAL AUTHORING INTERFACE
public boolean action(Event event, Object what) {
if (error)
{
showStatus("Problems! Had an error during initialization");
return true; // Uh oh...
}
.......
Finally note the usage of the \showStatus" method which will print a message on the status
bar (the bottom) of your WWW client window. If you now want to see how this works play with
the following example which shows a Java Applet where \MAT" it misspelled as \MATS" in the
code:
Example 6.3.3 EAI: RGB Change Test Error Applet with an error
Contents: getNode(), getEventIn(), Java: try/catch
HTML page: eai/rgb-change/rgb-change-err.html
JAVA Code: eai/rgb-change/RGBChangeErr.java
Directory: (dir)
Once we got the handle we can read. In the action method of our example we get the position
and the orientation of a Viewpoint with the following lines of code:
currentPosition = positionVP.getValue();
currentOrientation = orientationVP.getValue();
Writing into a Java text eld: Again some comments for Java newbies: The following de nes
a text widget to which we can print text:
6.3. ESSENTIAL EAI TRICKS 75
TextArea output = null;
.....
public void init() {
......
output = new TextArea(5, 40);
add(output);
......
}
Such a thing is de nitively better than telling the user to open up the Java Console.
Error handling again: The next example does exactly the same, but includes error handling.
Of new interest is only the \InvalidEventOutException":
public void initScene() {
try {
.......
positionVP = (EventOutSFVec3f) entryVP.getEventOut("position_changed");
orientationVP = (EventOutSFRotation) entryVP.getEventOut("orientation_changed");
}
.........
catch (InvalidEventOutException ee) {
System.out.println("InvalidEventOutException: " + ee);
die("initScene: EventOut Field not found!");
return;
} }
Also note that that a \die" method has been de ned that is called when encountering an error.
This adds some better modularization to the code.
Finally you can look at a minimal implementation of the \start", \stop" and \destroy" methods
that are called by the Java interpreter.
Example 6.3.5 EAI: Get Node Info Demo with Error Handling
Contents: getNode(), getEventOut(), Java: try/catch
HTML page: eai/get-node-info/get-node-info.html
JAVA code: eai/get-node-info/GetNodeInfo.java
Directory: (dir)
6.3.4 Create Vrml from String
In this subsection you will learn how to create a VRML scene from a string and to replace the
existing scene in the browser. Let's start with an empty world, i.e. all there is in the *.wrl le is
a line that will get the plug-in going:
#VRML V2.0 utf8
76 CHAPTER 6. THE EXTERNAL AUTHORING INTERFACE
The following example will paint a blue ball as soon as the applet starts up:
Example 6.3.6 EAI: Creating and inserting a simple VRML tree
Contents: createVrmlFromString()
HTML page: eai/create/create-ex0.html
JAVA code: eai/create/CreateEx0.java
Directory: (dir)
A Vrml scene (or tree) is represented in the Java Applet as as an array of Nodes which we will
initialize as follows:
Node[] scene = null;
The Browser class' createVrmlFromString method will take a simple string containing ordi-
nary VRML statements and then create an array of VRML nodes from it. In this example we
just add simple strings together, but of course you also could produce strings from variables and
methods to program some more useful applet. The code below will just create a few VRML objects.
scene = browser.createVrmlFromString(
"DEF Camera Viewpoint {\n" +
" position 0 0 5}\n" +
"DEF MySphere Transform {\n" +
" children [ \n" +
......
" ] \n" +
" } \n"
);
Once the scene array contains VRML nodes (represented as Java instances) the rest is very
simple. We can replace the current (in this case empty) VRML scene by the nodes in the new
scene array with the replaceWorld method.
browser.replaceWorld(scene);
Note that we also could have added these nodes to a children eld of an existing scene without
replacing everything else. With what you already learned you ought to be able to set a value to a
\addChildren" eld of a grouping node, but we will demonstrate it anyhow in section 6.3.5.
The next example is more complex, because it will separately create a series of VRML nodes
and then assemble them together by setting respective EventIn elds. If you do not understand
what it does you should read again the previous sections or just move on and come back later.
Example 6.3.7 EAI: Creating and assembling a VRML tree
Contents: createVrmlFromString()
HTML page: eai/create/create-ex.html
JAVA code: eai/create/CreateEx.java
Directory: (dir)
A more sophisticated example from which the above has been inspired can be found in the EAI
speci cation. A local copy is below. You can study it yourself :)
Example 6.3.8 EAI: Creating and assembling a VRML tree
Contents: createVrmlFromString()
HTML page: eai/create-test/create-test.html
JAVA code: eai/create-test/CreateTest.java
Directory: (dir)
6.3. ESSENTIAL EAI TRICKS 77
6.3.5 Create, Put and Remove together
In this subsection we pull together most of what we have learned so far. This applet will allow the
user to add a (VrmlFromString created) ball to an exiting Group node and also to remove it. The
Vrml we originally start with is very simple:
#VRML V2.0 utf8
As you might remember from section 4.4 on page 44, nodes like =>Group11 and Transform de ne
the EventIn addChildren and the EventOut removeChildren allowing you to add and remove
objects from children. We will make use of this feature in the next example.
Example 6.3.9 EAI: Add and remove an object
Contents:
HTML page: eai/add-remove/add-remove1.html
JAVA code: eai/add-remove/AddRemove.java
Directory: (dir)
If you understood the previous subsections there is not much explaining needed. Look rst at
these lines in the init() method:
// Get root node of the scene
root = browser.getNode("ROOT");
This example is just a simpli ed version of the one found in the EAI spec. The original adds
some error checking and feedback and you can look at it in the example below. Also, if the example
above won't work on your browser, the one below will print out the reasons for you :)
Example 6.3.10 EAI: Add and remove test
Contents:
HTML page: eai/add-remove-test/AddRemoveTest.html
JAVA code: eai/add-remove-test/AddRemoveTest.java
Directory: (dir)
11 http://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html#Group
78 CHAPTER 6. THE EXTERNAL AUTHORING INTERFACE
6.3.6 Receiving Events from the Scene
The last element we consider basic and essential in the EAI Spec is receiving Events from the Scene
which as bit analogous to the ROUTE statement used with animated VRML and scripting. It is
not the same as reading something from a scene which was discussed for example in subsection
6.3.3.
In the example we will discuss a simple TouchSensor example. When the user clicks on the
cube it will change color (something that usually would not need the EAI).
Example 6.3.11 EAI: Monitor and act upon a touch
Contents: EventOutObserver
HTML page: eai/monitor-test/monitor-touch.html
JAVA code: eai/monitor-test/MonitorTouch.java
Directory: (dir)
So what's new ? Our applet in order to receive call-backs from the VRML scene needs to
implement an EventOutObserver Interface. It can be done like this:
public class MonitorTouch extends Applet implements EventOutObserver
Of course you also could de ne a subclass implementing EventOutObserver but it would be slightly
more complicated. In any case, you must write a callback method for the EventOutObserver
class in order to process events. This method takes three arguments: the EventOut, the time and
some user de nable data. Let's look at the code:
public void callback(EventOut who, double when, Object which) {
// only deal with the event if isActive was true, else the ball would flip back
if (state.getValue() == true) {
System.out.println("callback(): EventOut=" + who
+ " state =" + state.getValue());
// Change the color and remember it
if (colorState == 1) {
diffuseColor.setValue(redColor);
colorState = 0;
}
else {
diffuseColor.setValue(greenColor);
colorState = 1;
}
}
}
In our case we do not need to deal with the EventOut object nor with the time stamp. The which
variable contains any kind of Java Object that we decided to pass over from the VRML scene. In
this example we passed isActive, i.e. an EventOutSFBool object related to the TouchSensor. To
set up the call-back we had to add the following lines to the init() method:
....
// Get the Touch Sensor
Node sensor = browser.getNode("TOUCH");
// Get its touchTime EventOut
isActive = (EventOutSFBool) sensor.getEventOut("isActive");
6.3. ESSENTIAL EAI TRICKS 79
// Set up the callback
isActive.advise(this, isActive);
....
As you can see, EventOuts do have an advise method that is used to tell (advise) the class, that
this EventOut will be used for a call-back. Let's go back to the callback() method listed above.
If you remember how to deal with state and isActive Events from a TouchSensor (see section 5.3.2
on page 61) you know that isActive will both generate true and false events depending on whether
the user clicks or releases a mouse button. Here again, we are just interesting in the \down" click:
EventOutSFBool state = (EventOutSFBool) which;
// only deal with the event if isActive was true ...
if (state.getValue() == true) { .... }
The rest is fairly easy. If the ball is green (remembered within our Java code as colorState) we
paint it red, else green. The following line should be meaningful to you, else go back to subsection
6.3.1.
diffuseColor.setValue(redColor);
Voila, that's it. We have written an invisible applet that does something we have been doing before
with Javascript (or that could be done with the Java Script node).
Other examples: The following example will monitor the output of a TimeSensor Node and
the rotation eld of a spinning cube.
Example 6.3.12 EAI: Monitor a Rotation
Contents: EventOutObserver
HTML page: eai/monitor-test/monitor-test2.html
JAVA code: eai/monitor-test/MonitorTest2.java
Directory: (dir)
The VRML scene we are dealing with is slightly more complex than the previous ones. In case
you forgot all your basic animated VRML you can go back reading section 5.2.1 on 54. It just
links the pulse of a TimeSensor to an OrientationInterpolator which sets the rotation eld of a
Transform node containing a cube.
On the Java Side there is not much more than in the previous example. Note that the advise
methods simply passes an Integer as a way to identify the Event we have to handle. There are also
2 buttons to stop and start the animation, some error handling code, and a long loop that makes
sure that we really get the browser. [I have a feeling that one should put the EAI/Java inits into
the start() method to be sure that the VRML scene has enough time to fully load ... to be tested].
Finally you can now look at the RGB Test Applet from the EAI Spec. It does about everything
you have learned so far.
Example 6.3.13 EAI: RGB Test Applet
Contents: getEventIn, getEventOut, EventOutObserver
HTML page: eai/rgb/RGB-demo.html
JAVA code: eai/rgb/RGBTest.java
Directory: (dir)
In the next sections we will discuss some slightly more complex examples and introduce some
more EAI stu .
80 CHAPTER 6. THE EXTERNAL AUTHORING INTERFACE
6.4 Extracting Information from a scene
So far you have learned that you can access any node in a existing VRML scene that has a
DEFed name. You can actually do more. Since you can inspect exposed eld values, you can
also retrieve children nodes. We are going to demo this in the next example. It will retrieve all
the Viewpoints from a Group node called \Viewpoints" in a VRML scene. The Java applet then
generates navigation nodes inserted into the applet. Note that this example is still pretty useless.
Useful things have a tendency to become quite complex.
Example 6.4.1 EAI: Retrieving children nodes
Contents: getEventOut, children nodes
HTML page: eai/navigate/navigate-dyn.html
JAVA code: eai/navigate/NavigateDyn.java
Directory: (dir)
DEF Viewpoints Group {
children [
DEF Entry Viewpoint {
position 0 1 15
description "Entry"
}
............
]
}
The init() method is fairly standard, so we will not comment it. Now let's see how we exact
these nodes: We rst declare an array variable to store the nodes:
Node[] VPList ;
Note how we cast the result of getEventOut to EventOutMFNode, i.e. it will return a list of Nodes.
And that's it. Now in order to be able to rebind the user to a Viewpoint, we are interested in
getting handles on the set_bind eld for each found viewpoint. The following lines of code relate
to that:
nVPs = VPList.length;
set_VPList = new EventInSFBool[nVPs];
......
for (i=0; i < nVPs ; i++) {
set_VPList[i] = (EventInSFBool)VPList[i].getEventIn("set_bind");
}
6.4. EXTRACTING INFORMATION FROM A SCENE 81
In the same loop we also generate the Java press buttons which we also store in an array (look at
the source code) All we nally need to do is to implement the action() method that will handle
user events and bind the user to a new ViewPoint. It's very much the same technology we discussed
in section 6.3.1 as well as others. The only di erence is that buttons are not stored in variables
but in an array called VPButtons:
/** Handle actions from AWT widgets */
public boolean action(Event event, Object what) {
This example assumed that the only children of the \Viewpoints" node were Viewpoints. In
other words, our code would break if there were other types of children nodes.
The next example deals with this issue. The applet below adds a \tour" button that will move
the user throught all viewpoints with some pause in between (Jumping is not nice I know, but this
will be addressed somewhere else).
Example 6.4.2 EAI: Retrieving children nodes with errors
Contents: getEventOut(), getType(), children nodes
HTML page: eai/navigate/navigate-tour.html
JAVA code: eai/navigate/NavigateDyn.java
Directory: (dir)
Basically we just had to add a few lines to the initScene() method. The Node.getType()
methode will return a string with the VRML Node name which you then can use to identify the
kind of node you have retrieved.
for (int i=0; i < nVPCs ; i++) {
String type_found = VPCandidates[i].getType();
if (!type_found.equals("Viewpoint")) {
System.out.println("WARNING! initScene: Ignored node of type " + type_found);
}
else {
// got a ViewPoint
VPList[nVPs] = VPCandidates[i];
nVPs = nVPs+1;
}
}
We will also add here some comments about a revisited version of the Tiny3D applet that
extracts node de nitions]
Example 6.4.3 EAI: Tiny3d-2
82 CHAPTER 6. THE EXTERNAL AUTHORING INTERFACE
Java 1.1.x (Netscape 4x PATCHED): eai/tiny3D-2/tiny3D-2.html
Java 1.0.x (Netscape 3x,4x): eai/tiny3D-2-java1.0.2/tiny3D-2.html
In the same directory you will nd more sophisticated versions of this applet, illustrating some
more features and also politically better Java programming.
12 /guides/java/jdk/docs/api/java.awt.GridLayout.html
Chapter 7
83
84 CHAPTER 7. ANIMATION AND AVATARS
The set fraction eventIn receives an SFFload event that can be any kind of oating point
number. In practise it is usually a number between 0 and 1 produced by a TimeSensor's frac-
tion changed eld. Now, for each \critical" fraction of the whole animation cycle you add the
fraction to the array of key s and for each key you must specify a interpolator-speci c keyValue.
Finally, the interpolator will produce the interpolated value changed eventOuts (as many as your
implementation can handle).
The principle of keyframe animation is very simple. What is not so simple are for example:
Multiple synchronized animations, e.g. a body that walks, moves legs, swings arms. etc. If
we are not wrong, it seems that for creating animations in a reasonable amount of time you
need a VRML authoring tool.
Non-linear animations, e.g. shuttle ying around in VRML space. Note that you could break
it down such a non-linear ight path to a large number of liner interpolation.
Coordination of animations with interactive user input. E.g. have an avatar jump while it
runs.
[ ... more to come]
Appendix
8.1 On-line Tools
The Tiny-3d-2 Applet This applet will allow you to create simple VRML geometry, color, size
and move around it. It also allows you to generate VRML code that you can paste into your editor.
Java 1.1.x (Netscape 4/Jx): eai/tiny3D-2/tiny3D-2.html
Java 1.0.x (Netscape 3/4x): eai/tiny3D-2-java1.0.2/tiny3D-2.html
DegressToRadian Converter You can use this JavaScript degree/radian converter1 to gure
out rotations.
8.2.1 CosmoWorlds
CosmoWorlds for Irix is quite a powerful tool, but it does have its limitations. I (Daniel Schneider)
would recommend to buy this tool for Irix since it's the only one available. Probably CW 2 for
Windows has less limitations (but I haven't seen that yet).
VRML code produced is overally speaking rather clean. It does add a few extra useless Trans-
forms, Groups and elds. The only major gripe I have is the placement of animation nodes.
Documentation is only in HTML format (dicult to print) and therefore writing code while
looking at the documentation on single monitor is dicult (at best)
The Script editor will not let you do certain things, like adding \USE xx" or values to elds,
or \directOutput TRUE"
The OutLine editor will not let you move or delete nodes and the general tool is VERY
restrictive about moving nodes. The worst thing is that you can't move animation nodes
outside of the geometry it animates (correct me if I am wrong). This leads to very unreadable
code.
1 http://tecfa.unige.ch/vrml/tools/rad-convert.html
85
86 CHAPTER 8. APPENDIX
The tool will not leave certain eld values alone if you don't touch them (is that a bug
or feature for optimized rendering if you get 0.000000something instead of a plain 0 in a
translation?
You can edit the source to clean things up, but be VERY careful. Moving around animations
makes them unavailable for later editing (even if the tool does not complain when you read
the le back).
Hiding unselected objects does not work and is a pain ! (correct me if I am wrong).
The is no support for protos, although you can hand edit the le to add them (but be careful,
save a copy and make a test before you clean up all your code).
When you import a le with an error you will not get any serious error message, it will just
break and say so :(
8.3.1 Win95
In March 97 I preferred the Cosmo Player. Note that text nodes don't are not implemented.
Use Sony's Community Place for that. In order to switch between plugins, get Sony's plug-in
chooser. Those two browsers will certainly rapidly try to match the full VRML 2 standard, but
other contenders may appear too.
Since April 97 I am using Worldview Beta4. It's the faster browser around and seems to
implement most everything. Colors may not be as pretty, but I don't care right now.
Since Jan 98 we are back to Cosmo for general work and use Sony's and Blaxxun's browsers
for multi-user things.
8.3.3 PowerMac
Currently (Jan 98), the best VRML 2 browser I could nd is WorldView (but it lacks Java support).
In order to look at standard VRML 2 worlds you must give your browser more memory !
(before you run Netscape: \Get Info" in the Finder's \File" menu).
2 http://tecfa.unige.ch/guides/vrml/pointers.html
8.4. FIELD AND EVENT REFERENCE 87
8.3.4 SGI/Irix
As of Jan 98 the news is that SGI decided not to favor development for its own hardware, so you
are stuck with last year's Cosmo Player. It will lack support of Java scripting, and won't recognize
Javascript if you don't call it VrmlScript. Send them angry mails and decide to learn the EAI
which is a kewl interface for doing many interesting things. Use a PC for scripting Script nodes in
the meantime (though nobody can tell if we EVER will get Cosmo 2 on Irix).
Here is a clue about Java Problems found at http://help.netscape.com/kb/client/970907-1.html
To troubleshoot your Java applets in UNIX environment,
you can start Communicator with the "-java" switch.
#netscape -java
Usage: -java [-options] class
SFBool A eld or event containing a single boolean value. SFBools are written as TRUE or
FALSE. For example,
fooBool FALSE
is an MFColor eld, fooColor, containing the three primary colors red, green, and blue.
The initial value of an SFColor eventOut is (0 0 0). The initial value of an MFColor eventOut
is [ ].
SFFloat/MFFloat SFFloat speci es one single-precision oating point number, and MFFloat
speci es zero or more single-precision oating point numbers. SFFloats and MFFloats are written
to le in ANSI C oating point format. For example:
fooFloat [ 3.1415926, 12.5e-3, .0001 ]
A one-component image speci es one-byte hexadecimal values representing the intensity of the
image. For example, 0xFF is full intensity, 0x00 is no intensity. A two-component image puts
the intensity in the rst (high) byte and the alpha (opacity) in the second (low) byte. Pixels
in a three-component image have the red component in the rst (high) byte, followed by the
green and blue components (0xFF0000 is red). Four-component images put the alpha byte after
red/green/blue (0x0000FF80 is semi-transparent blue). A value of 0x00 is completely transparent,
0xFF is completely opaque.
Each pixel is read as a single unsigned number. For example, a 3-component pixel with value
0x0000FF may also be written as 0xFF or 255 (decimal). Pixels are speci ed from left to right,
bottom to top. The rst hexadecimal value is the lower left pixel and the last value is the upper
right pixel.
For example,
fooImage 1 2 1 0xFF 0x00
is a 1 pixel wide by 2 pixel high one-component (i.e. greyscale) image, with the bottom pixel white
and the top pixel black. And:
fooImage 2 4 3 0xFF0000 0xFF00 0 0 0 0 0xFFFFFF 0xFFFF00
# red green black.. white yellow
8.4. FIELD AND EVENT REFERENCE 89
is a 2 pixel wide by 4 pixel high RGB image, with the bottom left pixel red, the bottom right pixel
green, the two middle rows of pixels black, the top left pixel white, and the top right pixel yellow.
The initial value of an SFImage eventOut is (0 0 0).
SFInt32/MFInt32 The SFInt32 eld and event speci es one 32-bit integer, and the MFInt32
eld and event speci es zero or more 32-bit integers. SFInt32 and MFInt32 elds and events are
written to le as an integer in decimal or hexadecimal (beginning with '0x') format. For example:
fooInt32 [ 17, -0xE20, -518820 ]
The SFNode and MFNode elds and events may contain the keyword NULL to indicate that it is
empty.
The initial value of an SFNode eventOut is NULL. The initial value of an MFNode eventOut
is [ ].
SFRotation/MFRotation The SFRotation eld and event speci es one arbitrary rotation,
and the MFRotation eld and event speci es zero or more arbitrary rotations. S/MFRotations are
written to le as four oating point values separated by whitespace. The rst three values specify
a normalized rotation axis vector about which the rotation takes place. The fourth value speci es
the amount of right-handed rotation about that axis, in radians. For example, an SFRotation
containing a 180 degree rotation about the Y axis is:
fooRot 0.0 1.0 0.0 3.14159265
The initial value of an SFRotation eventOut is (0 0 1 0). The initial value of an MFRotation
eventOut is [ ].
SFString/MFString The SFString and MFString elds and events contain strings formatted
with the UTF-8 universal character set
ISO/IEC 10646-1:19934 SFString speci es a single string, and the MFString speci es zero or
more strings. Strings are written to le as a sequence of UTF-8 octets enclosed in double quotes
(e.g. "string").
Any characters (including newlines and '#') may appear within the quotes. To include a double
quote character within the string, precede it with a backslash. To include a backslash character
within the string, type two backslashes. For example:
fooString [ "One, Two, Three", "He said, \\"Immel did it!\\"" ]
8.6.2 Things to do
Just a short list of what you can expect in some nearer future.
Little things:
Introduction on \how to use"
A \framed" page with the list of examples to the left and VRML to the right.
Fix English
External Protos (!)
Add a few JavaScript scripting examples that manipulate SF and MF type elds.
Medium things:
More on color (Build a color tool that shows in operation all the Material node parameters
with a few di erent light sources).
Lights
Viewpoint angles and positioning (Build a tool ?)
Complex objects (non-simple shapes)
tricks to make your scene look good
Big things:
An introduction to humanoid avatars (REAL SOON!)
Good scenes with simple moving objects
Good scenes with Javascript
Scripts with Java (Introduction)
Multi-user worlds
8.7. COPYRIGHT INFORMATION 93
8.7 Copyright Information
This manual and associated examples (unless otherwise stated) are copyrighted Daniel
Schneider and Sylvere Martin-Michiellot, TECFA, FPSE, University of Geneva. (email:
[email protected])
You may use this manual and our own associated examples for non-commercial purposes if you
give us some sort of credit. Else ask and you likely will get permission.
You can freely distribute electronic or printed versions of this manual and examples at NO
charge, but you are NOT allowed to mirror this manual at any site without password protecting it
from general access and without adding a link to the original. (This is to prevent that old versions
oat around, some stu is REALLY alpha or beta or whatever you want to call it).
If you decide to use this manual for a course, please give us feedback on things you like, don't
like and so on, so that we can improve things.
Enjoy !
94 CHAPTER 8. APPENDIX
Bibliography
[Ames et al., 1996a] Ames, A. L., Nadeau, D. R., et Moreland, J. L. (1996a). The VRML 2.0
Sourcebook. Wiley, New York. URL: http://www.wiley.com/compbooks/catalog/07/16507-
7.html (source code and ordering information).
[Ames et al., 1996b] Ames, A. L., Nadeau, D. R., et Moreland, J. L. (1996b). The VRML Source-
book. Wiley, New York. URL: http://www.wiley.com/Compbooks/vrmlsrbk/cover/cover.html
(source code and ordering information).
[Bishop, 1997] Bishop, J. (1997). Java Gently, Programming Principles Explained. Addison-
Wesley, Reading. URL: http://www.cs.up.ac.za/javagently.
[Carey et Bell, 1997] Carey, R. et Bell, G. (1997). The Annotated VRML 2.0 Reference Manual.
Addison-Wesley, Reading (MA). URL: http://www.awl.com/devpress/titles/41974.html.
[Gibson, 1994] Gibson, W. (1994). Neuromancer. Ace, New York.
[Hartman et Wernecke, 1996] Hartman, J. et Wernecke, J. (1996). The VRML 2.0 Hand-
book, Building Moving Worlds on the Web. Addison Wesley, Reading (MA). URL:
http://vrml.sgi.com/handbook/index.html.
[Hughes, 1995] Hughes, K. (1995). From Webspace to Cyberspace. EIT WWW publications. URL:
http://www.eit.com/%7Ekevinh/cspace/ or http://www.scit.wlv.ac.uk/kevinh/ (UK Mirror).
[Kimen, 1997] Kimen, S. (1997). VRML Is- Java Does- And the EAI Can Help. On-line article at
vrml.sgi.com. URL: http://vrml.sgi.com/features/java/java.html.
[Lea et al., 1996] Lea, R., Matsuda, K., et Miyashita, K. (1996). Java for 3D and VRML Worlds.
New Riders, Indianapolis. URL: http://www.mcp.com/newriders/books/1-56205-689-1.html.
[Marrin, 1996] Marrin, C. (1996). Anatomy of a VRML Browser. on-line publication. URL:
http://www.marrin.com/vrml/Interface.html.
[Pesce, 1995] Pesce, M. (1995). VRML, Browsing and Building Cyberspace. New Riders, Indi-
anapolis. URL: http://www.mcp.com/newriders/internet/vrml/ (source code, ordering infor-
mation and patches).
[Pesce et al., 1994] Pesce, M. D., Kennard, P., et S., P. A. (1994). Cyberspace. In
Proceedings of The First International Conference on The World-Wide Web. URL:
http://www1.cern.ch/PapersWWW94/mpesce.ps.
[Roehl et al., 1997] Roehl, B., Couch, J., Reed-Ballreich, C., Rohaly, T., et Brown, G.
(1997). Late Night VRML 2.0 with Java. Zi -Davis Press, Emeryville. URL:
http://ece.uwaterloo.ca:80/%7Ebroehl/vrml/lnvj/index.html.
[Stephenson, 1992] Stephenson, N. (1992). Snow Crash. Bantam.
95
Index
Examples Simple Materials, 21
A simple cup, 18 Simple Rotation example, 20
A simple oor, 17 Simple Text, 25
A simple Timesensor Example, 55 Tecfa People LOD, 37
A simple Timesensor Example II, 56 The Castle Example, 31
A Simple Touchsensor E ect, 53 The Light-on problem again, 59
A simple translation, 19 The Light-on problem switch the dumb
A simple ugly tour guide, 36 way (b), 64
A simple VRML 2.0 le, 16 The Light-on problem switch the dumb
A TouchSensor activating a Shuttle, 57 way(a), 64
A viewpoint changing TouchSensor The Light-on problem with state, 61
Script, 61 The Light-on problem with VRML
Activating and Stopping a Shuttle, 64 state), 62
Add/Remove DEFed objects (and reset) The Light-on problem without
II, 46 eventOUT, 61
Add/Remove DEFed objects I, 45 The MiniBot, 84
Anchors, 24 Three Stools, 31
Ball Brow, 82 VRML code generation with Javascript,
EAI: Add and remove an object, 77 42
EAI: Add and remove test, 77 VRML in a Frame, 40
EAI: Creating and assembling a VRML VRML in a Frame II, 41
tree, 76
EAI: Creating and inserting a simple Good VRML, 27, 35
VRML tree, 76
EAI: EAI: Tiny3d-2, 81 Multiple Instances, 28
EAI: Get Node Info Demo, 74
EAI: Get Node Info Demo with Error Nodes
Handling, 75 Anchor, 24
EAI: Monitor a Rotation, 79 Appearance, 21
EAI: Monitor and act upon a touch, 78 DEF, 28
EAI: Retrieving children nodes, 80 ImageTexture, 23
EAI: Retrieving children nodes with er- LOD, 36
rors, 81 Material, 21
EAI: RGB Change Applet, 71 OrientationInterpolator, 55
EAI: RGB Change Test Applet, 73 PositionInterpolator, 57
EAI: RGB Change Test Error Applet Shapes
with an error, 74 Box, 17
EAI: RGB Test Applet, 79 Cylinder, 18
EAI: The do nothing applet, 68 Switch, 63
Image texture example, 23 Text, 25
Inlining other VRML les, 30 TimeSensor, 55
Moo Ants PROTO Example, 33 TouchSensor, 52, 59
Overlapping objects, 20 Transform, 19, 20
Rotation: Spikes of a Wheel, 28 USE, 28
Rotation: Spikes of a Wheel II, 29 PROTO, 31
96
INDEX 97
Prototypes, 31
the ROUTE statement, 49, 52