by Jim O'Donnell
The capability of creating and presenting three-dimensional information content on the World Wide Web suggests many possible applications: tours of actual and planned architectural structures, visualization of intricate chemical or biological models, or online sales of mechanical parts that allow customers to actually see the part before buying, to name a few. The VRML 1.0 standard established the format in which this information could be presented.
The official adoption of the VRML 2.0 standard, along with extensions to the VRML 1.0 language used by Netscape and others, provides a way to make three-dimensional VRML worlds much more dynamic and interactive. Now, as users travel through your VRML world, the objects within it can interact with them-and with each other-in many different ways.
However, the usefulness and availability of browsers that understand VRML 2.0, along with the current bandwidth limitations of most users on the Internet, limits what the appropriate applications are for widespread VRML use. Choosing the right language and tools for creating a dynamic VRML world are vital to its success.
The VRML 1.0 standard provides a means for the creation and display of static, three-dimensional worlds over the Web and the Internet. As shown in the two previous chapters, it supplies a collection of language elements-called nodes-for creating simple three-dimensional objects and assembling them into more complex objects and VRML environments. These VRML environments are generally either smaller, special purpose applications meant to be used (via the <EMBED> HTML tag) as inline VRML scenes or larger ones used as full-blown VRML worlds.
VRML 1.0 environments are static, though. The objects within them do not move and do not interact very much with the user. The only motion is the navigation of the user through the world. The only real interaction is through the inclusion and use of hypertext links within the VRML world.
The VRML 2.0 standard was created to alleviate this shortcoming of VRML 1.0 worlds. Objects within a VRML world can be programmed with movement, animation, and behaviors that allow them to interact with the user and with one another. Three-dimensional sound can be included to add further realism to the VRML world.
However, the VRML 2.0 standard is a new one. At the time of this writing, there are no VRML browsers or plug-ins that support the official VRML 2.0 standard, and it will probably be some time before VRML 2.0-compatible browsers become widespread. In the meantime, an attractive alternative for creating dynamic VRML worlds is Netscape's Live3D, a standard part of the full install of their Netscape Navigator 3 Web browser. Netscape has given Live3D a selection of VRML extensions that give it some of the dynamic capabilities of VRML 2.0. Unlike the current state of VRML 2.0 and VRML 2.0-compatible browsers, however, a lot more people will have Live3D. This allows Web authors to create dynamice VRML worlds for Live3D that will have a much greater potential audience than those made for VRML 2.0. (The Live3D plug-in also works within Microsoft's Internet Explorer 3.)
Netscape's Live3D VRML plug-in is the descendant of the WebFX VRML plug-in, developed by Paper Software, Inc. After Paper Software was acquired by Netscape, the plug-in was revised and rechristened Live3D, to join LiveAudio, LiveVideo, LiveConnect, and Netscape's other "live" technologies. While the VRML extensions to Live3D, for creating dynamic worlds, are based on the Moving Worlds proposal that was eventually chosen as the basis for the current VRML 2.0 standard, they are not the same as the elements in the standard. Live3D is part of the standard download for Netscape Navigator 3 and can be downloaded separately from the Live3D Web site at http://home.netscape.com/comprod/products/navigator/live3d/.
The new nodes included in the Live3D VRML extensions add a subset of the capabilities offered by the official VRML 2.0 standard. They add two kinds of motion (spinning and animation), three-dimensional sound options, methods to add more realistic appearances to VRML worlds, and support for targeting frames to VRML hypertext links.
The VRML 2.0 standard adds a full range of increased capabilities for adding dynamic motion, behaviors, sound, and animation to VRML worlds. It supports scripted behaviors and touch sensors for VRML objects, allowing them to react to the presence of other objects of the user, as he or she navigates through the VRML world.
While VRML 2.0 is based on the VRML 1.0 standard, and VRML 2.0-compatible browsers are backward-compatible with VRML 1.0 worlds, the languages do look somewhat different. Many of the VRML 1.0 nodes survived but are used somewhat differently in VRML 2.0. Some nodes are different and some have been changed, in most cases to generalize or simplify their use. You will see some specifics of these changes in the VRML 2.0 discussion, later in this chapter.
Yet another way to create dynamic VRML worlds and to add interactivity and behaviors to objects within those worlds is to combine Java and VRML. This will be discussed in Chapter 55, "Java and VRML."
The question of whether to use Live3D or VRML 2.0 to program your VRML applications depends on several factors. Some of the things to consider when making this decision are the following:
Currently, for most HTML authors who want to use VRML to create cool special effects in their Web pages, using Live3D's VRML extensions is probably the way to go. Using Live3D assures a much larger user base of people who can view the pages, while providing you with a more stable development environment (the VRML 2.0 browsers are all in early beta testing).
The remainder of this chapter will focus on creating small, dynamic VRML environments, meant to be embedded in HTML Web pages, using the Live3D VRML extensions. The sample application that will be developed later is a VRML version of my home page. After this discussion, however, you will learn some more of the capabilities of the VRML 2.0 standard and see them in action in SGI's "Boink!" example VRML 2.0 world.
Through Netscape's Live3D Web site, much information and documentation about Live3D's capabilities and language elements can be found. The Live3D Web site is located at
http://home.netscape.com/comprod/products/navigator/version_3.0/
For more complete information about the syntax and language elements of Live3D, you can check out the Live3D: Creating Content Web site at
http://home.netscape.com/eng/live3d/live3d_content.html
| ON THE WEB |
http://home.netscape.com/eng/live3d/live3d_content.html This Web site gives information about how to create content for the Web using VRML and Netscape's Live3D. |
This site contains a beginner's guide to VRML and the Live3D extensions and pointers to some cool VRML worlds that use Live3D.
In the following sections, there are descriptions of all of the Live3D VRML extensions, along with (where appropriate) examples of how they would be used.
Motion blur is activated through this node or through one of the commands available through the Live3D plug-in Options, Motion Blur menu item. This feature creates a viewing mode where all objects that are moving with respect to the viewer blur as they move, giving a greater appearance of movement. This effect can be quite distracting when there are moving objects in the VRML world. It works best when the world is static and the effect arises from motion of the viewer.
The MotionBlur node is used to enable this viewing mode by including the following in your VRML code:
MotionBlur {
on TRUE
}
The Animator node is used to add animation to a VRML model. Currently, this can only be done by linking an Autodesk 3DStudio. Vue animation file to the VRML model. The syntax for doing this is the following:
Animator {
filename "filename.vue"
loop TRUE
reverse FALSE
startframe -1
endframe -1
}
You can use 3DStudio to create a .Vue file for use with the Live3D plug-in by following these steps:
| CAUTION |
When you give your models names, make sure none of them have spaces because when the VRML is exported, spaces are replaced with underscores, while the .Vue file generator does not. Also, 3DStudio's Morph keys and IK-based animations are not currently supported; you can achieve jointed movement, however, by changing the rotation axis and using Keyframer linking. |
Figures 54.1 and 54.2 show one of the example animations available through the Live3D Web site. In this case the animation is a looping one and also reverses itself, creating a continuous loop between the positions shown in the two figures.
This node is a grouping node, like the Separator node, that is used to spin the object or objects within it. The objects can be spun about a specified axis, either about the object itself or about the center of the VRML world.
For an example of the use of the SpinGroup node, see the "Adding Motion" section of the Live3D example later in this chapter.
Live3D adds the target field to the WWWAnchor node to allow target frames to be specified in a VRML hypertext link. For example, to create a hypertext link inside a VRML cube to a frame named IndexFrame in an HTML document located at
http://www.company.com/example.html
the following could be used:
WWWAnchor {
name "http://www.company.com/example.html"
target "IndexFrame"
Cube {}
}
Live3D supports two different sound nodes, each of which provides three-dimensional sound capabilities within a VRML world. Three-dimensional sound means that the sounds behave as they do in the real world. Directional sounds, such as those coming from a bullhorn, are heard best when you are directly in front of them. As you move away from where they are pointed, they are heard less well. Both directional and point sounds are heard less well, and eventually not at all, as you move away from them.
The DirectedSound Node This node implements a directional sound source within Live3D VRML worlds. The sound is described in terms of two regions: an inner ellipse, where the sound volume is constant and at its maximum intensity, and an outer ellipse, outside of which no sound is heard. Between the two ellipses, the sound drops off in intensity, depending on where the viewer is located with respect to distance away from the source and away from the direction in which the sound it pointed.
The following bit of code is an example of attaching a directional sound. This example attaches a sound to a cone, where the line from the apex of the cone to the center of the base defines the sound's direction.
Separator {
DirectedSound {
name "announce.wav"
description "Directed Sound"
intensity 1
location 0 0.5 0
direction 0 -1 0
minFrontRange 0.5
maxFrontRange 37.5
minBackRange 0.06
maxBackRange 0.200
loop TRUE
}
Cone {}
}
The PointSound Node This node implements a sound that is omnidirectional and drops off in intensity uniformly, from the minimum to the maximum range. To associate a sphere with a point sound, for example, so that the sound radiates from the sphere in all directions, you would do something like the following:
Separator {
PointSound {
name "music.wav"
description "Point Sound"
intensity 1
location 0 0 0
minRange 1
maxRange 5
loop TRUE
}
Sphere {}
}
Live3D provides two enhancements to the VRML Texture2 node for allowing different effects to be achieved with textures. These effects allow the texture applied to a surface to be animated, as with the Netscape logo shown on the cubes in Figure 54.1, or to change depending on the movement of the camera.
Animated Textures Animated textures provide animation of any supported file format in the Texture2 node. The image must consist of multiple images stacked vertically-the height of the image must be an even multiple of the width, which should be a power of two. For instance, to cycle through eight images on one of your VRML objects, where each image is 645128 pixels, you need to create one image that ends up being 6451024 pixels long.
Another great example of the use of animated textures in Live3D (other than the animated Netscape logo mapped to the cubes on the Live3D Web site) is the Perimeter Ball example shown at
http://home.netscape.com/eng/live3d/examples/sleball.html
This example maps an image depicting a bouncing ball, with a transparent background, onto a transparent VRML cube to create the appearance of a three-dimensional bouncing ball.
Environment Mapping This added capability of the Texture2 node is provided with the envmap field. It is used to shift the coordinates of the affected texture in response to the movement of the user's viewpoint. One use of this field is to create an object with a polished surface that reflects its surrounding environment. The envmap field is implemented with
Texture2 {
filename "surface.gif"
envmap TRUE
}
The AxisAlignment node forces objects to stay aligned with the specified axis. This can be used, for instance, to force objects to always face the camera. In this usage, it is particularly effective in conjunction with AsciiText nodes to create text tags that can be viewed from any angle.
An example of another use of this node, to create hypertext links attached to AsciiText nodes, is shown in the "Axis-Aligned Text" section of the Live3D example later in this chapter.
These Live3D VRML extensions add support for two named Info nodes that allow you to specify a color or background image to be used in your VRML world. Examples of their use are
DEF BackgroundColor Info {
string "1 0 0" # red background
}
DEF BackgroundImage Info {
string "sky.jpg" # image URL
}
The CollideStyle node enables cube-based collision detection to your VRML world (this can also be enabled using the Live3D plug-in's Navigation, Collision Detection menu item). Collision detection is enabled by including the following in your VRML world:
CollideStyle {
collide TRUE
}
We will now go through an exercise to create a Live3D dynamic VRML scene to be used as a VRML version of my home page. Because the idea is to create something that will be used by people over dialup connections to the Internet, we want to keep the VRML file size as small as possible. The best way to do this is to include only a few objects and to code as much of the VRML file by hand.
The basic concept for my VRML home page will be to create a three-dimensional text object of my initials, "JOD," along with a couple other objects and use AsciiText nodes to add hyper-links to my other Web pages. Live3D elements for spinning, background, and axis-alignment will be used to make the page more dynamic and usable.
The first step in the creation of my VRML home page is to create and assemble the VRML objects that will be used. While most of them will be created by hand, it will be necessary to use a VRML authoring program to create the three-dimensional text object.
Three-Dimensional Text Object To create the three-dimensional text object of the letters "JOD," we will use Caligari Pioneer. Figure 54.3 shows the three-dimensional text object after it has been created and the front faces of the letters painted red, using these steps:
Because we are only interested in using the three-dimensional text, we want to eliminate any other VRML objects that Pioneer puts into the VRML scene. For instance, Pioneer includes a number of light sources. To see the list of VRML objects in a scene, delete some, and name the others, use the following steps:
Figure 54.4 shows the result. Note that the window with the overhead view of the text object was created by clicking the New Perspective View button.
Figure 54.4 : Eliminating light sources from the VRML scene renders all objects within it black.
By selecting File, World, Save As, the result can be saved as the VRML world, Jod.wrl. (Because of the size of this file-it takes about a 23K file to render this three-dimensional text object-the listing will not be shown here.)
Now, what does the resultant VRML file look like with Live3D? Figure 54.5 shows what appears when Jod.wrl is loaded into Netscape Navigator with Live3D. Note that, even though there are no light sources included in the VRML world, the object appears because the plug-in supplied light.
To make use of this three-dimensional text object, created by Caligari Pioneer, we need to be able to place it where we'd like. The easiest way to do this is to edit the Jod.wrl file and comment out everything that we don't want or need. For this VRML file, this includes the CALIGARISceneInfo, Switch, and all three MatrixTransform nodes. This removes the special information used by Caligari Pioneer, which isn't supported by Live3D: the Switch node clock used to control multiple cameras, which should be empty for this file, and the transforms used to place the three text objects.
By removing these transforms, we have allowed all of the letters to appear at the origin. This allows us to more easily place them but also requires us to perform a little further initial placement. (Note that we also added the BackgroundColor Info node to set the background to sky blue.) By adding Translation nodes to each of the three letters and experimenting with them, we can place the three letters in the correct positions with respect to one another (see Figure 54.6).
Once we have these letters positioned correctly, we won't need to adjust them anymore. They will be at the center of our VRML scene so they don't need to be moved from the origin. Further VRML objects and language elements can be added to the VRML file by hand.
Adding a Surface and Other Objects Now, we want to add a few other objects to our VRML world. First, a surface upon which to rest the text object and the other objects and then a couple of cubes that we'll use to bracket the text object. Listing 54.1 shows the VRML code used to do this. The surface is created with an IndexedFaceSet node, with a Material node to make it brown. The two cubes are created with Cube nodes, and Material and MaterialBinding nodes make each face a different color of the rainbow.
Listing 54.1 Jod3.wrl-Building a Dynamic VRML Scene with Live3D
#VRML V1.0 ascii
# Pioneer (tm) was used to create this VRML file.
# Additions and deletions to the file made by JOD
#
# Add info and background, JOD
#
Separator {
Info {
string "Platinum Edition, Using HTML, Java, and CGI, chapter 54"
}
DEF BackgroundColor Info {
string "0.75 0.75 1"
}
}
#
# Add ground
#
DEF GROUND Separator {
Material {
diffuseColor [1 0.5 0]
}
Coordinate3 {
point [
-20 0 -6,
20 0 -6,
20 0 10,
-20 0 10]
}
IndexedFaceSet {
coordIndex [0,1,2,3,-1]
}
}
#
# Add cube #1
#
Separator {
Translation { translation -5 1.1 0 }
Material {
diffuseColor [1 0 0,
1 0.5 0,
1 1 0,
0 1 0,
0 0 1,
1 0 1]
}
MaterialBinding {
value PER_FACE
}
DEF JCUBE1 Separator {
Cube {
height 1.5
width 1.5
depth 1.5
}
}
}
#
# Add cube #2
#
Separator {
Translation { translation 5 1.1 0 }
Material {
diffuseColor [1 0 0,
1 0.5 0,
1 1 0,
0 1 0,
0 0 1,
1 0 1]
}
MaterialBinding {
value PER_FACE
}
DEF JCUBE2 Separator {
Cube {
height 1.5
width 1.5
depth 1.5
}
}
}
DEF JOD Separator {
VRML code generated by Caligari Pioneer for text object not shown...
}
As shown in Figure 54.7, however, when this scene is viewed, the Live3D plug-in automatically picks its initial viewpoint to be able to accommodate the whole scene in the browser window. In order to change this, we need to define some viewpoints of our own.
Cameras and Light Sources Listing 54.2 shows the VRML nodes added to create a couple of light sources and three cameras to our VRML world. The light sources are created with DirectionalLight nodes and are both sources of white light, one from above and one from the left. The cameras are created with the PerspectiveCamera nodes-two are front views from different distances, and the third is a top view. The Switch node is used to make sure that only one view is active at a time. Figure 54.8 shows the VRML scene using the default view. The alternative views can be selected from under the Live3D ViewPoints menu (see Figure 54.9).
Listing 54.2 Jod4.wrl-Lighting and Camera Views Can Be Added
#
# Directional Light
#
Separator {
DirectionalLight {
on TRUE
intensity 0.75
color 1 1 1
direction 0 -1 0
}
}
#
# Directional Light
#
Separator {
DirectionalLight {
on TRUE
intensity 0.6
color 1 1 1
direction 1 0 0
}
}
#
# Cameras
#
DEF Cameras Switch {
whichChild 0
DEF Entry PerspectiveCamera {
position 0 3 7
orientation -1 0 0 0.2
}
DEF "Step Back" PerspectiveCamera {
position 0 6 14
orientation -1 0 0 0.2
}
DEF Above PerspectiveCamera {
position 0 11 0
orientation 1 0 0 -1.5708
}
}
Embedding in an HTML Page Because we want this VRML scene to be embedded in an HTML Web page, the HTML document needs to be created. Listing 54.3 shows the HTML document used, where the VRML scene is included by using the <EMBED> tag and specifying the URL of the VRML file and the width and height of the embedded Live3D window. Figure 54.10 shows the resulting HTML Web page. Note that the Live3D navigation bar is disabled by default with embedded VRML scenes (it can be re-enabled by the user selecting Options, Navigation Bar). As an embedded scene, it is still possible to navigate around.
Figure 54.10 : VRML scenes can be embedded in HTML Web pages using the <EMBED> tag.
Listing 54.3 Jod4.htm-VRML Worlds Can Be Embedded in HTML
Web Pages
<HTML> <HEAD> <TITLE>JOD's VRML Home Page</TITLE> </HEAD> <BODY BGCOLOR=#FFFFFF> <CENTER> <TABLE BORDER=10><TR><TD> <EMBED NAME=JODWORLD SRC="jod4.wrl" WIDTH=400 HEIGHT=250> </TD></TR></TABLE> </CENTER> </BODY> </HTML>
Now, at last, we are ready to put our world in motion using Live3D's SpinGroup node. SpinGroup is a grouping node, like Separator, that uses the rotation and local fields to create a spinning motion in the objects within it. For example, the following
SpinGroup {
rotation 1 0 0 0.1
local TRUE
Cone { }
}
creates a cone that rotated at 0.1 radians per iteration about the 1 0 0 (positive x) axis. Because the value of the local field is TRUE, it rotates about its center point; if it were false, it would rotate about the center point of the VRML world.
Listing 54.4 shows excerpts of the file Jod5.wrl, where the SpinGroup node is added to the file Jod4.wrl and is used to set the two cubes and the text object into motion. All that was done is that the Separator node was replaced with SpinGroup, and the rotation and local fields were added.
Listing 54.4 Jod5.wrl-Live3D's SpinGroup Node Puts Objects in Motion
DEF JCUBE1 SpinGroup {
rotation -1 1 -1 0.1
local TRUE
Cube {
height 1.5
width 1.5
depth 1.5
}
}
DEF JCUBE2 SpinGroup {
rotation 1 1 -1 0.1
local TRUE
Cube {
height 1.5
width 1.5
depth 1.5
}
}
DEF JOD SpinGroup {
rotation 0 1 0 0.05
local TRUE
VRML code generated by Caligari Pioneer for text object not shown...
}
Figure 54.11 shows the result, after the viewpoint has been moved around a bit, when viewing the VRML scene embedded into the HTML Web page.
Just as my HTML home page includes hypertext links to other pages, so too should the VRML version of the home page. We will implement these with WWWAnchor and AsciiText nodes, but we will also use the Live3D AxisAlignment node to make sure that the text is always facing the viewpoint. Because AsciiText objects are two-dimensional, without this axis alignment it is easy to get in a position where the text cannot be seen.
We will place these AsciiText nodes in a circle above the three-dimensional text object, and use the SpinGroup node to set them in motion as well. Listing 54.5 shows an excerpt of Jod6.wrl, showing one of the hypertext links-the others are identical, with different name and description fields in the WWWAnchor node and string field in the AsciiText node, as appropriate for each hypertext link, and a different Translation node to reflect their different initial positions.
Listing 54.5 Jod6.wrl-WWWAnchor Allows Hypertext Links to Be Attached to VRML Objects
#
# Hypertext Links
#
WWWAnchor {
name "http://www.rpi.edu/~odonnj"
description "JOD's Home Page"
AxisAlignment {
alignment ALIGNAXISXYZ
}
Translation { translation 3 3 0 }
SpinGroup {
rotation 0 -1 0 0.02
local FALSE
FontStyle {
size 0.4
}
AsciiText {
string "HOME PAGE"
justification CENTER
}
}
}
Figure 54.12 shows this VRML scene with the mouse pointer indicating one of the hypertext links. Note that the value in the description field of the WWWAnchor node appears when the link is active.
When this world is viewed as an embedded VRML scene and looked at from overhead, as shown in Figure 54.13 (by navigating the viewpoint there, or selecting ViewPoints, Above to access the defined overhead viewpoint), the AsciiText remains oriented toward the camera. Also note that the text now appears white, as opposed to the darker appearance in Figure 54.12. This is because there is a light source shining from above this VRML scene but not from the front.
One of the goals of our design was to create a VRML world that wasn't too big to be conveniently viewed over the World Wide Web. At a final size of 29K, we have achieved this. It is interesting to note that, of the 29K of the final VRML file, 26K is taken up by the three-dimensional text object generated by Caligari Pioneer, using three very large IndexedFaceSet nodes. If you want to see how the final version of the VRML home page works and integrates in the other pages on my Web site, check out http://www.rpi.edu/~odonnj/jod6.html.
The VRML 1.0 language specification allows for the creation, presentation, and viewing of static three-dimensional scenes and worlds. VRML 2.0 has been designed to build on that standard to provide a lot more. The goal of the VRML 2.0 standard is to provide the tools to create three-dimensional worlds that include movement and sound and allow the objects within the world to be programmed with behaviors that allow them to react to your presence and the presence of other objects. VRML fish can be programmed to swim away from you if you get too close, for instance.
A second goal of VRML 2.0 is to create a foundation for Web-based three-dimensional content that can continue to evolve and grow. As computers continue to grow more and more powerful, the Internet continues to develop, and high-bandwidth high-speed connections become more commonplace, the VRML standard will continue to be developed to take advantage of the new capabilities.
The new capabilities of VRML 2.0 over VRML 1.0 fall into the five general categories of static world enhancements, interaction, animation, scripting, and prototyping. These are discussed in the VRML 2.0 specification available on this book's CD-ROMs, along with the complete details of the final VRML 2.0 specification. They are summarized in the following sections.
VRML 2.0 supports several new nodes and fields that allow the static geometry of VRML worlds to be made more realistic. You can create separate backdrops for the ground and the sky, using colors or images. Objects such as clouds and mountains can be put in the distance, and fog can be used to blur distant objects. Irregular terrain can be created, rather than using flat planes for your surface. VRML 2.0 also provides three-dimensional sound to further enhance realism.
VRML 2.0 includes a new class of nodes, called sensor nodes, that are able to set off events in response to different inputs. Touch and proximity sensors react to the presence of the viewer either touching or coming close to an object. A time sensor is able to keep track of the passage of time, allowing time-correlated events to be added to your VRML world. And VRML 2.0 supports realistic collision detection and terrain following to ensure that your viewers bounce off of (or at least stop at) your walls and solid objects and are able to travel through your world while easily following things like steps and inclines.
VRML 2.0 interpolator nodes allow you to create predefined animations for any of the objects in your VRML world. These animations can be programmed to occur automatically or in response to some other factor, either an action of your viewer or at a given time. With these interpolators, you can create moving objects, objects such as the sun or the moon that change color as they move, or objects that change shape. The viewpoint can also be animated to create an automatic guided tour of your VRML world.
The key to many of VRML 2.0's other features, particularly the movement of VRML 2.0 objects, is its support of scripting. Scripting is used to program objects behaviors, not only allowing them to move but also giving them the ability to react realistically to objects around them. A script is the link that is used to take an event, generated by a sensor node, for instance, and generate the appropriate action.
The final category of enhancement to VRML 2.0 is the capability for prototyping. What this allows you to do is to create your own nodes. By grouping a set of nodes together to achieve a specific purpose within a new prototype node, that node becomes available for reuse.
The new capabilities of VRML 2.0 are carried out through the inclusion
of new nodes in the language. Table 54.1 shows a brief summary
of the VRML 2.0 nodes. For a complete description of these nodes,
along with the full syntax of how to use them, you can consult
the VRML 2.0 specification on the CD-ROMs included with this book.
| Node Type | Node Name | Description |
| Grouping | Collision | Specify whether objects can be moved through. |
| Grouping | Transform | Group nodes under a single, local coordinate system. This node combines the elements of the VRML 1.0 Separator and Transform nodes. |
| Browser Information | Background | Specify colors or images used for VRML world background. |
| Browser Information | NavigationInfo | Provide hints to the VRML 2.0 browser to optimize it for the current scene. |
| Browser Information | Viewpoint | Specify viewpoints. This node replaces the VRML 1.0 PerspectiveCamera node. |
| Browser Information | WorldInfo | Provide title and other information in a similar but more structured manner to the VRML 1.0 Info node. |
| Lighting | Fog | Add atmospheric effects. |
| Sound | Sound | Define a three-dimensional sound source. |
| Shapes | Shape | Contain a set of geometry nodes and property nodes that apply to the geometry. |
| Geometry | ElevationGrid | Specify irregular ground surfaces. |
| Geometry | Extrusion | Specify extruded and rotated shapes. |
| Geometry | Text | Specify ASCII text. This node replaces, and adds many more features to the VRML 1.0 AsciiText node. |
| Geometric Properties | Color | Specify object colors. |
| Appearance | Appearance | Group all of the appearance properties for a Shape node. |
| Sensors | ProximitySensor | React to the proximity of the viewer. |
| Sensors | TouchSensor | React when the viewer clicks an object. |
| Sensors | CylinderSensor | React to a viewer's click and drag within a virtual cylinder. |
| Sensors | PlaneSensor | React to a viewer's click and drag within a virtual plane. |
| Sensors | SphereSensor | React to a viewer's click and drag within a virtual sphere. |
| Sensors | VisibilitySensor | React when objects become visible or hidden within the currently rendered view. |
| Sensors | TimeSensor | Generate events based on time. |
| Scripting | Script | Program behaviors that can process incoming events and generate and carry out responses. |
| Interpolator Nodes | ColorInterpolator | Interpolate between colors. |
| Interpolator Nodes | CoordinateInterpolator | Interpolate between vectors. |
| Interpolator Nodes | NormalInterpolator | Interpolate between normalized vectors. |
| Interpolator Nodes | OrientationInterpolator | Interpolate between absolute rotations. |
| Interpolator Nodes | PositionInterpolator | Interpolate between translations. |
| Interpolator Nodes | ScalarInterpolator | Interpolate between numbers. |
Most VRML 1.0 nodes have changed in some respects. Though VRML
2.0 browsers are required to be backward-compatible with VRML
1.0 worlds, some VRML 1.0 nodes have been removed. While they
will be supported within a VRML 1.0 world, they will not be recognized
in a VRML 2.0 world. Table 54.2 shows this list of nodes.
| VRML 1.0 Node | VRML 2.0 Replacement |
| AsciiText | Text |
| Info | WorldInfo |
| OrthographicCamera | None |
| PerspectiveCamera | Viewpoint |
| Separator | Transform |
| MatrixTransform | Function incorporated into Transform |
| Transform | Function incorporated into Transform |
| Translation | Function incorporated into Transform |
| Rotation | Function incorporated into Transform |
| Scale | Function incorporated into Transform |
To give you a feel for some of what can be done with VRML 2.0, we will go through the Boink! example from Silicon Graphics. This example, included with their Cosmo Player VRML 2.0 plug-in, can only be viewed with this plug-in or another VRML 2.0-compatible browser, and can also be found at
http://webspace.sgi.com/worlds/vrml2/boink/boink.wrl
Cosmo Player is a Web browser plug-in that works with Netscape Navigator 3 and Microsoft Internet Explorer 3. Beta versions of it are available from the Silicon Graphics Web site at
http://webspace.sgi.com/cosmoplayer/.
By taking a look at the example VRML 2.0 worlds, offered by Silicon Graphics and others, you can get an idea of the capabilities of the VRML 2.0 language, as well as how to achieve some of them. In the space we have here, and given all of the new elements in the VRML 2.0 language, it won't be possible to get more than a feel for how it works. Nonetheless, you should at least be able to use this overview, along with the VRML concepts you picked up in the previous two chapters, to attain a reasonably good grasp of VRML 2.0 and be able to understand VRML 2.0 worlds when you study them.
Static Elements In Listing 54.6 is the basic structure of the Boink! VRML 2.0 example. The first line tells the VRML browser that this VRML world is based on draft #2 of the VRML 2.0 standard (though the final version of the standard has been released, Cosmo Player and the other VRML 2.0 browsers are currently lagging somewhat behind it). The WorldInfo and NavigationInfo nodes are used to give information about the world and to give some initial configuration information to the browser. The bulk of the VRML 2.0 code is included as child nodes to the FOO and SCENE-ROOT-XFORM Transform nodes and instructions for the VRML 2.0 interpolators follow.
Listing 54.6 Structure of Boink.wrl
#VRML Draft #2 V2.0 utf8
WorldInfo {
info [ "Silicon Graphics Inc 1996
Author: Sam Chen" ]
title "Boink!"
}
NavigationInfo {
headlight TRUE
type"EXAMINE"
avatarSize 0.5
}
DEF FOO Transform { children
DEF SCENE-ROOT-XFORM Transform {
children [
VRML 2.0 code...
]} # End of SCENE-ROOT
}
VRML 2.0 interpolator commands...
Taking a look at Listing 54.7 to see some of the information that will remain static in the VRML 2.0 world, these nodes are defined near the top of the SCENE-ROOT-XFORM group. The Cameras Group node defines the different viewpoints included in the scene. Directional light is included, and a floor is used. Note that the details of the floor are included in another VRML file defined by the URL field. This ability to include information from other VRML files allows VRML worlds to be organized and transmitted efficiently. Also note the touch sensor embedded in the floor; this will be used to set the scene in motion, as shown in Listing 54.7.
Listing 54.7 VRML 2.0 Viewpoints and Light Sources and the Static "Floor"
DEF Cameras Group {
children [
DEF center Viewpoint {
position 1 0 9
orientation 1 0 0 0.3
fieldOfView 1.0
description "center"
},
DEF entry Viewpoint {
position 0 5 20
# orientation 1 0 0 0.3
fieldOfView 0.785398
description "entry"
}
]
},
DirectionalLight {
direction 0.4 -1 0.3
},
Transform {
children [
DEF FLOOR Inline {
url "floor.wrl"
bboxSize 10 10 10
},
DEF FLOOR-TOUCHSENSOR TouchSensor {}
]
translation 0 -0.1 0
},
Finally, the cone, cube, and sphere must also be defined within the VRML 2.0 world. Again, this is done by including other VRML files that do the actual definition, as shown for the cone in Listing 54.8. Figure 54.14 shows the static VRML scene, as viewed from the entry Viewpoint.
Figure 54.14 : Until set in motion, this VRML 2.0 world shows a rather unexciting static scene.
Listing 54.8 The VRML 2.0 Cone
DEF CONE-DEFORM-XFORM Transform { children
DEF CONE Inline {
url "cone.wrl"
}
scale 1.4 .5 1.4
},
Dynamic Elements This VRML 2.0 scene is set into motion using the TouchSensor node to detect user clicks any of the VRML objects: cone, cube, or sphere. When each is clicked, scripts and interpolators are activated to set that object and motion. Sounds, that are synchronized with the object as it hits the floor, are played as well. Listing 54.9 shows some of the sensors and scripts used, in this case attached to the cone. Once the TouchSensor has set the cone in motion it remains in motion, looping through its prescribed set of movements.
Listing 54.9 VRML 2.0 Sensors and Scripts
DEF CONE-SENSOR TouchSensor{},
DEF CONE-BOUNCE-TIMER TimeSensor {
loop TRUE
stopTime 1
cycleInterval 1.5
},
DEF CONE-SOUND-TIMER TimeSensor {
loop TRUE
stopTime 1
# discrete TRUE
cycleInterval 1.5
},
DEF CONE-SOUND-SCRIPT Script {
eventIn SFTime startTime
eventOut SFTime modifiedTime
url "vrmlscript:
function startTime (time){
modifiedTime = time - .29;
}"
},
Listing 54.10 shows the instructions used for the cone object to describe its animation, once it has been activated. These instructions turn time values into interpolations between positions, interpolations into transforms to move the objects where they should be at a given instant and to supply the correct sound.
Listing 54.10 Configuration for VRML 2.0 Animation
# CONE: Timer->Interpolators ROUTE CONE-SENSOR.touchTime TO CONE-BOUNCE-TIMER.set_startTime ROUTE CONE-SENSOR.touchTime TO CONE-SHUTTLE-TIMER.set_startTime ROUTE CONE-BOUNCE-TIMER.fraction TO CONE-BOUNCER.set_fraction ROUTE CONE-BOUNCE-TIMER.fraction TO CONE-DEFORMER.set_fraction ROUTE CONE-BOUNCE-TIMER.fraction TO CONE-SHADOW-DEFORMER.set_fraction ROUTE CONE-SHUTTLE-TIMER.fraction TO CONE-SHUTTLER.set_fraction # CONE: Interpolators->Xforms ROUTE CONE-BOUNCER.value_changed TO CONE-XFORM-BOUNCE.set_translation ROUTE CONE-DEFORMER.value_changed TO CONE-DEFORM-XFORM.set_scale ROUTE CONE-SHUTTLER.value_changed TO CONE-XFORM-SHUTTLE.set_translation ROUTE CONE-SHUTTLER.value_changed TO CONE-SHADOW-XFORM.set_translation ROUTE CONE-SHADOW-DEFORMER.value_changed TO CONE-SHADOW-XFORM.set_scale # CONE: Sound ROUTE CONE-SENSOR.touchTime TO CONE-SOUND-SCRIPT.startTime ROUTE CONE-SOUND-SCRIPT.modifiedTime TO CONE-SOUND-TIMER.startTime ROUTE CONE-SOUND-TIMER.cycleTime TO CONE-SOUND-SOURCE.startTime
Each object, in turn, can be sent "boinking" around the VRML scene, as shown in Figure 54.15, with the cone and sphere in motion.
Figures 54.16 and 54.17 show the final aspect of the realism that is possible with VRML 2.0 and demonstrated in this example. Examine the cone and the cube in each of these figures, and note that they are deformed by impact with the floor, as you might expect if bouncing a rubber ball, for instance. This effect is achieved using VRML 2.0 interpolators to control the bouncing and deformation of each object as it is animated. When the object is in the air, it appears normally. When is it impacting the floor, it is compacted.
Figure 54.16 : Objects in the air appear as the normally would.
This is done in the Boink! example shown in Listing 54.11. Observe that for each CONE-BOUNCER position defined in its value field, there is a CONE-DEFORMER scale factor. For instance, when the cone is at its highest point, at the point the value field is 0 4.8 0, the deformation scale factors are 1 1 1, indicating a normally scaled cone. When the cone is striking the floor, at position 0 0 0, the cone is at its most deformed, with scale factors of 1.4 0.5 1.4.
Listing 54.11 Interpolators Used for the Bouncing and Deformation of the Cone Object
DEF CONE-BOUNCER PositionInterpolator {
keys [0,0.04,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.96,1]
values [0 0 0,0 0.66 0,
0 1.664 0,0 3.036 0,
0 4.016 0,0 4.604 0,
0 4.8 0,
0 4.604 0,0 4.016 0,
0 3.036 0,0 1.664 0,
0 0.66 0,0 0 0]
},
DEF CONE-DEFORMER PositionInterpolator {
keys [0,0.06,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.94,1]
values [1.4 0.5 1.4, 0.995 1.005 0.995,
0.92 1.08 0.92,0.955 1.045 0.955,
0.98 1.02 0.98,0.995 1.005 0.995,
1 1 1, 0.995 1.005 0.995,
0.98 1.02 0.98,0.955 1.045 0.955,
0.92 1.08 0.92,0.995 1.005 0.995,
1.4 0.5 1.4]
}
For more information, tutorials, and examples of VRML 2.0, as well as VRML 1.0 and other VRML implementations, take a look at the excellent Web site provided by Vijay Mukhi at http://www.neca.com/~vmis/vrml.htm.