Special Edition Using HTML 2nd Edition - Chapter 17 VRML Copyright ©1996, Que Corporation. All rights reserved. No part of this book may be used or reproduced in any form or by any means, or stored in a database or @retrieval system without prior written permission of the publisher except in the case of brief quotations embodied in critical articles and reviews. Making copies of any part of this book for any purpose other than your own personal use is a violation of @United States copyright laws. For information, address Que Corporation, 201 West 103rd Street, Indianapolis, IN 46290 or at support@mcp.com.

Notice: This material is excerpted from Special Edition Using HTML, 2nd Edition, ISBN: 0-7897-0758-6. This material has not yet been through the final proof reading stage that it will pass through before being published in printed form. Some errors may exist here that will be corrected before the book is published. This material is provided "as is" without any warranty of any kind.

Chapter 17 VRML

by Jim O'Donnell

The advent of the World Wide Web (WWW), the @HyperText Markup Language (HTML), and @Web browsers capable of viewing @HTML documents including text, @graphics, and sound revolutionized the @Internet. Previously, the most common way of exchanging information was through @e-mail and @Usenet discussion groups. Because these methods could handle text only, the only way to exchange @graphics, sound, or other binary information was for the sender to encode it and the receiver to decode it. @HTML and the WWW changed this process by enabling you to create true multimedia information sites on the Internet, offering real-time display and exchange of text, graphics, sound, and other information.

The next big step beyond @HTML for information distribution on the @Internet may be the Virtual Reality Modeling Language (VRML). @HTML's hypertext links and the @Web browsers that make use of them create an essentially two-dimensional interface to @Internet information. VRML expands this interface by allowing the creation of three-dimensional worlds on the WWW, offering a much more natural way of presenting information.

What Is VRML?

VRML, the Virtual Reality Modeling Language, is an authoring standard, currently defined at version 1.0, for creating three-dimensional documents on the @World Wide Web. These documents create @VRML worlds that a user can navigate in and around using the capabilities of a VRML-compatible browser. The current standard is file-based, involving the transfer of 3-D scenes to the local computer-VRML source files usually have a .wrl extension-after which all navigating through the scene is done there. And, like HTML documents, @VRML worlds can contain links to other documents, @graphics, text, @HTML documents, or other @VRML worlds.

@Freeware, @shareware, and @commercial VRML tools are becoming widely available.

Like HTML, VRML is a fast-evolving standard for conveying information over the @World Wide Web. If you are going to be working with VRML a lot, you would do well to frequently consult @newsgroups and other @Internet and @WWW resources (such as those mentioned in the "VRML Resources on the Internet" section at the end of this chapter) that deal with VRML, its tools, and its standards.

Example VRML World

Included with the Windows WebFX VRML browser, a plug-in module for Netscape Navigator 2.0 that is discussed later in this chapter, is a series of sample VRML worlds. To get a feel for what navigating around a VRML world is like and how it is different from regular HTML, you look at a simple VRML world in this chapter.

Figure 17.1 shows a sample @VRML world called Netscape.wrl, which, when loaded, shows an up-close view of the familiar Netscape "N." After you install the WebFX plug-in, Netscape automatically calls WebFX when a VRML world is loaded. (You know it has been called successfully if you see the WebFX Navigation Bar at the bottom of the browser window.) At this point, this world looks like an HTML imagemap. The pointer even turns into a hand pointer when you move it over the "N," indicating the presence of a hypertext link. However, you can navigate around this three-dimensional world.

Fig. 17.1

When you enter this sample VRML world, you see the familiar Netscape "N."

Navigating VRML Worlds

WebFX beginners can click the ? (question mark) WebFX button to turn on the Heads up display. Then, when you click the fly button, the display shown in figure 17.2 appears, indicating how to navigate around while you're in WebFX fly mode.

Fig. 17.2

If you turn on the Heads up display, WebFX gives you hints about how to navigate the VRML world.

The quickest way to show the three-dimensional nature of the @VRML world at this point is to press and hold down the Z key, which is used in fly mode to thrust backward. You quickly see the Netscape "N" world recede into the distance, as shown in figure 17.3. The star field in this figure is a background image allowed by VRML.

Fig. 17.3

By pressing Z to thrust backward, you can move away from "Netscape world."

After you move some distance from the Netscape world, you can reverse course and approach it again by pressing the A key to thrust forward. Using this key, you can retrace the steps from where you began to thrust backward-you can also keep going to get a much closer view of the Netscape "N" (see fig. 17.4). You can even continue to thrust forward until you are past the "N," in which case you see only the star field background. At this point, you can turn around by pressing the right- or left-arrow key, and you actually move behind the "N" world (see fig. 17.5).

Fig. 17.4

By pressing A to thrust forward, you can move right up to the Netscape "N." You can even move through and beyond it!

Fig. 17.5

You can even move past the object and turn around to see it from behind.

It's easy to get lost in a VRML world sometimes. If that happens in WebFX, right-click the screen and choose Viewpoints, @Entry View to return to your starting point.

Hypertext Links

Because the WebFX VRML browser is a Netscape plug-in, you might suspect that, just as with an HTML document, you can link together VRML worlds using hypertext links. You can even interchangeably link VRML worlds and HTML documents! Other @VRML browsers offer similar capability, whether they are Web browser plug-ins, helper applications, or stand-alone applications.

In this chapter's sample Netscape world, for instance, when you place the pointer on the "N," the pointer turns into the hand pointer, indicating the presence of a hypertext link. As shown in figure 17.6, the hand pointer and a label for the @hypertext link, which appears in the upper left, indicate where the link will take you. In the case of this Netscape world, as you might expect, clicking on the link takes you to the familiar Netscape HTML home page.

Just as when using new HTML enhancements, if you would like to add VRML content to your Web pages, you should keep in mind that not everyone has the necessary software to view it. Therefore, you should also convey the information included in your VRML using conventional means.

Fig. 17.6

When you move the pointer over an object that is a hypertext link, such as an HTML anchor, it turns into the hand pointer, and a @URL label for the link appears in the upper-left corner of the window.

VRML Basics

In many ways, VRML is an extension of @HTML; the source code for @HTML documents and code for @VRML worlds are very different, but the concepts are similar. The differences between the two lie in the fact that HTML documents are two-dimensional, whereas VRML worlds are three-dimensional. An HTML document is like a bulletin board, where text and @graphics can be displayed, and each can also represent a @hypertext link to another place in the document, or another document entirely. On the other hand, a VRML world is more like a room (or world, I suppose, if it's big enough) filled with three-dimensional objects. Because of the three-dimensional nature of the VRML world, you can navigate around and see objects from all sides. In VRML, like HTML, each of these objects can also be a @hypertext link.

With a VRML-compatible Web browser, users can navigate back and forth between @HTML documents and @VRML worlds with no additional steps. This compatibility is achieved either by means of a plug-in module such as with WebFX and Netscape Navigator, by setting up a VRML browser as a helper app for a Web browser, or by using a stand-alone VRML browser that also supports HTML. Inside an HTML document, if there is a hypertext link to a VRML world, it will be loaded and the Web browser placed into a VRML browsing mode. Conversely, @HTML links from a @VRML world will lead back to conventional @web page viewing.

Programming in VRML

Just as with HTML documents, @VRML worlds are defined by @VRML source code. However, as you might imagine from the fact that VRML worlds are three-dimensional, the source code is likely to be much more complex. Figure 17.7 shows the top of the @VRML source file for the @Netscape world. The @VRML language is much more like C/C++ than it is like HTML.

Fig. 17.7

@VRML "worlds" are defined by @VRML source code as shown here.

Many tools are currently being written to allow @HTML authors to create @Web pages and documents more easily. You can, however, create fairly sophisticated Web pages programming directly in HTML. Because of the complexity of VRML, however, it would be very difficult to do the same-to create a VRML world by directly writing VRML code. Consider the Netscape world, which consists of only a few objects-the Netscape "N," the sphere upon which it rests, and the "glow" around them. The source code to describe the Netscape "N" is partially shown in figure 17.8. Even a relatively simple object like the "N" is described by a long series of coordinates. Programming this object directly would be very difficult.

Fig. 17.8

@VRML 3-D objects, such as the Netscape "N," are defined by the coordinates of the lines that make up the object.

To be able to create VRML worlds, you need to use a VRML authoring tool for creating VRML 3-D objects and building them into a world. @Libraries of VRML objects are also available on the @Internet.

VRML Tools

A variety of tools for viewing and creating VRML worlds-freeware, shareware, and commercial-has begun to appear. Because of the relative infancy of the VRML version 1.0 standard, most of these products are still in the @beta test stage and are available for at least trial use through the @Internet. @VRML tools are primarily being developed for two platforms: Windows (3.1, Windows for Workgroups, 95, and NT) and UNIX (primarily SGI and Sun) machines.

VRML Browsers

The following are some of the VRML browsers currently available, along with the platform for which they are made, and where on the WWW to look for more information:

The VRML Repository, whose URL is shown at the end of this chapter, is an excellent resource for finding the latest VRML tools and examples available.

VRML Authoring Tools

@VRML worlds can be considerably more complex than @HTML documents, which makes sense considering that they are three-dimensional models. A full discussion of creating @VRML worlds would require a book in itself, but in this chapter you go over the types of tools that you are liable to require. Later in the chapter, you find a simple example of creating a VRML world using Fountain, by Caligari Software.

Using WebFX, a VRML Plug-In for Netscape

To get a better feel for what using a VRML browser is like, you install and try out one of them, WebFX by Paper Software, in the following sections.

Installing WebFX

The version of WebFX used herein is the WebFX plug-in for @Netscape Navigator 2. To install this plug-in, follow these steps:

  1. Copy the file npwfx32e.exe from the CD into a temporary directory on your hard drive.
  2. Run npwfx32e.exe. Running this executable gives the following files (if you have Windows Explorer set up to hide MS-DOS file extensions for registered file types, this list might look a little different, but the files will still be there):
  3. Setup.exe
  4. _setup.dll
  5. Setup.ins
  6. _setup.lib
  7. Setup.pkg
  8. Data.z
  9. Run Setup.exe. If you installed Netscape Navigator 2 in the default location and want to do the same for WebFX, you can select the defaults for each entry in the WebFX setup process.
  10. You should get a message similar to the one shown in figure 17.9, indicating a successful installation. WebFX is now installed as a @Netscape Navigator plug-in module, and automatically runs when you encounter a @VRML source file when using Netscape.

The WebFX plug-in is usually meant for a specific version of @Netscape Navigator. Make sure you have compatible versions before installing or you may have unpredictable results.

Fig. 17.9

When WebFX has successfully installed, you get a dialog box similar to this one. WebFX now automatically runs when a @VRM source file is encountered when using the @Netscape Navigator.

Navigating through a Virtual World Using WebFX

WebFX offers three different modes for navigating around and through a three-dimensional @VRML world: walk, fly, and point. Other @VRML browsers may have different means of @navigation-the VRML source file defines the layout of the world, but the browser dictates how you travel through it.

Walk Mode

To get some help in remembering what actions work in each mode, click the ? (question mark) @WebFX Navigation Bar button, which enables the Heads up display. If you then click the walk button, you have the following navigation options:

Fly Mode

When you place WebFX in fly mode, the @mouse and @keyboard actions change to the following:

Point Mode

The last @navigation mode of WebFX, point mode, allows you to navigate the VRML worlds as follows:


Troubleshooting

I've loaded a VRML world, and I can't see anything! What should I do?

Sometimes the initial viewpoint for a VRML world is poorly chosen, or you may have navigated yourself around until you are lost. In this case, the best way to try to find your way, in any navigation mode, is to do a right-drag, holding down the right mouse button and moving the pointer around to rotate the entire VRML world. Usually, you will be able to get the actual objects into view this way, and you can then use the navigation means discussed above to move in closer.


Configuring WebFX

WebFX allows you to customize its behavior in several different ways. This customization is achieved using a pop-up menu and submenus that first appear when you right-click. The main pop-up window shown in figure 17.10 then appears.

Fig. 17.10

Right-clicking in the @VRML screen opens a pop-up menu that you can use to configure WebFX. The Entry View selection under the ViewPoints submenu returns you to where you entered the VRML world.

Each of the six entries shown in the main pop-up window gives you different options for customizing WebFX. The following describes the most important submenus, but you should feel free to experiment with these and the other options to get a feeling for what you can do with WebFX.

Fig. 17.11

WebFX allows you to control how much detail is shown in the three-dimensional image.

If you are using a slower computer, you can improve the performance of WebFX by changing the amount of detail that is shown.

Fig. 17.12

The Heads up Display submenu allows you to control what information is shown in the WebFX Heads up display.

Example VRML World on the World Wide Web

In this section, you examine an example VRML world I found while surfing the Internet. It is a good example of an achievement with @VRML worlds that might not be as effective with a standard @HTML Web page. It also demonstrates how these two types of documents-representing two ways of presenting information-can be effectively used in tandem.

Using Netscape Navigator 2 with the WebFX plug-in installed, I connected to the following URL:

http://esewww.essex.ac.uk/campus-model.wrl

Note the .wrl extension, denoting a VRML world source document. After the connection was made by Netscape, the WebFX plug-in was called, the @VRML world source was downloaded, and the image shown in figure 17.13 appeared. Although it isn't obvious, this figure shows the University of Essex campus, as seen from a long way off.

Fig. 17.13

The entry point to the University of Essex VRML world.

To get a closer look, put your WebFX in fly mode and fly in toward the VRML world. Give yourself a little bit of altitude to be able to see more of the campus buildings. As you get closer, you'll see the campus layout shown in figure 17.14.

Fig. 17.14

You can fly in closer to the university and see a view of the campus.

As you learned earlier, @VRML worlds and @HTML documents can call one another interchangeably. The @University of Essex site uses this capability to not only convey the three-dimensional layout of their campus, but also to allow visitors to learn more about the different campus facilities. Consider figure 17.15; I placed the cursor over a building that has a @hypertext link, indicated by the presence of the hand pointer and the @URL label in the upper-left corner of the screen. Apparently, this building is the University Library. When I double-clicked, an HTML web page was called (see fig. 17.16), giving information about the library.

Fig. 17.15

By placing the pointer over a given building and clicking...

Fig. 17.16

...you can jump to an HTML document with information about it.

Because the VRML world is a three-dimensional model, you can look at it from any angle, including from below (which isn't very helpful) and from above, as shown in figure 17.17, giving you a useful map of the University of Essex campus.

Fig. 17.17

You can even fly up high enough and look down to get an aerial map of the campus.

Authoring VRML Worlds Using Fountain

Discussing VRML authoring would take a whole book, but we'll take a quick look at what it would entail here. To do so, use Caligari Software's Fountain.

Unless you do three-dimensional modeling for a living, you may find that creating VRML worlds is not the easiest thing in the world. To improve your productivity and the ease with which you arrive at your final product, it's probably a good idea to sketch out what you want your world to look like on paper before diving into Fountain or another VRML authoring program.

See Special Edition Using VRML

Installing Fountain

To install Fountain, follow these steps:

  1. Copy the file Fountain.exe from the CD into a temporary directory on your hard drive.
  2. Run Fountain.exe. Running this executable gives you the following files (if you have Windows Explorer set up to hide MS-DOS file extensions for registered file types, this list might look a little different, but the files will still be there):
  3. Fountain.exe
  4. Setup.exe
  5. Install.ins
  6. Info.txt
  7. License.txt
  8. Fountain.z
  9. Run Setup.exe. The installation process is fairly straightforward, and only requires you to decide where to install the Fountain software.
  10. You should get a message similar to the one shown in figure 17.18, indicating a successful installation. Fountain is now installed on your computer. To use it, you should create a desktop shortcut icon for it, install it in the Start menu, or run it using the Run option of the Start menu.

Fig. 17.18

When Fountain has successfully installed, you get a dialog box similar to this one.

VRML Authoring Example Using Fountain

Now you're ready to create a simple VRML world using Fountain.

Simple Example with Hypertext Link

To create a simple world with one object and a hypertext link, follow these directions:

  1. Start Fountain, and select File, Scene, New to create a new VRML world.
  2. Select the Text Primitive button, and type some text. In figure 17.19, I typed my initials, JOD.
  3. Select the Sweep button, which makes the selected object three-dimensional. By grabbing an edge of the text and dragging the cursor, you can extrude the object further, as shown in figure 17.20.
  4. Select the Attach URL Link button so that you can add a hypertext link to the selected object (see fig. 17.21).

Fig. 17.19

After selecting the Text Primitive button, you can type the desired text.

Fig. 17.20

With the text object selected, by selecting the @Sweep button, you can make the text three-dimensional.

Fig. 17.21

You can attach a URL link to any VRML object. This link can point to an HTML document.

At this point, save the document by choosing File, Scene, Save. Use the file name jod.wrl. To see if you were successful, try to load this file using Netscape Navigator with the WebFX plug-in module installed. You then see the screen shown in figure 17.22. You can see that the hypertext link is there-when you move the cursor over the text object, it turns into a hand pointer and the @URL label appears in the upper-left corner. Because this model is three-dimensional, you can navigate around, getting closer or farther away from the objects there, changing the viewpoint (see fig. 17.23).

Fig. 17.22

You can load my simple VRML world using Netscape Navigator and view it using the WebFX plug-in.

Fig. 17.23

Because this world is three-dimensional, you can move in and around the world's objects. If you click the JOD text object, the @hypertext link takes you to my HTML home page.

Another Example Using Multiple Objects

This example creates multiple objects and gives an idea of how to manipulate light sources and change the color of objects. In this one, we attempt to achieve a similar effect to the Netscape "N" world shown at the beginning of the chapter.

  1. Start Fountain, and select File, Scene, New to create a new VRML world. Start off by creating a sphere using the Sphere button in the Primitives panel (see figure 17.24).
  2. To create the "JOD" letters (instead of the Netscape "N"), first select the font by right-clicking the Text Primitives button, which will give you the @font selection dialog box shown in figure 17.25.
  3. After selecting the font, left-click the Text Primitives button, left-click somewhere on the screen, and type the letters JOD. Then select the Sweep button to get three-dimensional letters (see fig. 17.26).
  4. Now move the "JOD" on top of the sphere. To do this, select the Object Move button. Left-dragging moves objects right and left, or back and forth. Right-dragging moves them up and down. Figure 17.27 shows what it looks like after the "JOD" has been embedded in the top of the sphere.
  5. To change the color of an object, in this case the sphere, select the Paint Faces button, which gives the panels shown in figure 17.28. These panels give you the option of what color and shading to use when coloring an object.
  6. Figure 17.29 shows the sphere after being colored blue. Now, to further manipulate the appearance of the world by creating and configuring a local light source, select the Local Light Source button from the Primitives panel. This gives the Lights panel shown in figure 17.29. The light source can be moved around just as any other object.
  7. By moving the local light source above and in front of the letters and sphere, you can brighten its appearance (see fig. 17.30).
  8. By selecting File, Scene, Save As, the VRML world can be saved, as shown in figure 17.31.
  9. Your results can be viewed with any VRML-compatible browser. WebFX displays it as shown in figure 17.32.

Fig. 17.24

First, you create a sphere to be your "world." The 3-D arrow points to the current object.

Fig. 17.25

Right-clicking on the Text Primitives button allows you to pick your font and font size.

Fig. 17.26

After typing in the letters JOD, you can hit the Sweep button to create the 3-D look.

Fig. 17.27

You can move the JOD on top of your "world," even embedding it in the top.

Fig. 17.28

The @Paint Faces button brings up these panels, giving you options for what color and style to use to paint an object.

Fig. 17.29

After painting your world, you can adjust where and what color the light sources are.

Fig. 17.30

Moving the light source in front of your "world" brightens its appearance.

Fig. 17.31

You can save this world as a WRL file.

Fig. 17.32

You can view this sample world using the WebFX plug-in for Netscape Navigator.

By navigating around this sample world, one of the hazards of working in three dimensions becomes apparent. As shown in figure 17.33, you have to remember to work with all sides of an object-when you are coloring objects, for instance, be sure to get all sides!

Fig. 17.33

You can see one of the effects of working in three dimensions-I didn't paint the back of my world!

VRML Resources on the Internet

After you have your system set up to view VRML documents, you'll want to start cruising the Internet and the World Wide Web to see what VRML resources and worlds are available. The list is growing every day. Following are a few of the bigger sites that will direct you to many other VRML resources-browsers, authoring tools, worlds, and object libraries: