Skip to main content.

Web Based Programming Tutorials

Homepage | Forum - Join the forum to discuss anything related to programming! | Programming Resources

Java Unleashed

ch34.htm Previous Page toc Index Next Page

Chapter 34

VRML and Java

Virtual Reality Modeling Language (VRML) is a way to describe virtual worlds on the Web, just as HTML describes Web pages. Soon, having a home page on the World Wide Web will not be enough. You’ll need your own home world (home.wrl) as well! As Java becomes integrated with VRML, you’ll be able to write Java scripts to animate and enliven VRML worlds.

In this chapter, you’ll get an introduction to what Virtual Reality Modeling Language is, what it looks like (see Figure 34.1), what you can do with it, and how it works. We’ll look at the most exciting developments so far in wedding Java to VRML—from such companies as Dimension X, Paper Software, SGI, and WorldMaker—and will include source code for Java/VRML examples. At this point, Java APIs for VRML still are being developed, so these examples are right at the cutting edge.

FIGURE 34.1.

Aereal Serch is a VRML world by Dennis Mckenzie and Adrian Scott with links to other worlds inside the various buildings.

We also will look at designing a VRML site and what kinds of business models could work for VRML creators. In Appendix F, there is a VRML resources section with pointers to URLs relating to software, examples, converters, and other information.

The goal of virtual reality is to create an immersive experience so that you feel you are in the middle of a separate virtual world. Virtual reality generally relies upon three-dimensional computerized graphics plus audio. Virtual reality uses a first-person outlook. You move about in the virtual world rather than controlling a computer-generated figure moving around in the world.

HTML is a markup language, but VRML (pronounced “ver-mul”) is not. We’ll look at a simple world described in the standard VRML ASCII text representation, plus screen shots of what it actually looks like using a VRML browser.

What is a VRML browser? A VRML browser is to VRML what a standard browser such as Mosaic or Netscape Navigator is to HTML. The VRML browser loads in a virtual world described in VRML, and then renders it in three-dimensional graphics and lets you roam through the virtual world. You can select links in the virtual world that take you to other virtual worlds or any other URL such as an HTML page or GIF image.

Your VRML and standard Web browsers will communicate, so that when you select a link to an HTML file from a virtual world, your standard Web browser will load that URL. Conversely, when you select a link to a VRML file from your standard Web browser, the Web browser will recognize the MIME type and pass the URL or VRML file to your VRML browser. In the future we might see added capabilities in VRML browsers so that they can render an HTML page without having to switch to the standard Web browser.

One of the exciting developments in browsers has been the use of VRML plug-ins to other browsers, which was pioneered by Paper Software’s WebFX VRML plug-in. Working as a plug-in, the VRML is displayed in the standard area of the Web browser where HTML is normally displayed. In some cases, such as Netscape’s browser, there can be multiple VRML worlds showing at one time within an HTML page.

VRML files can be sent using the standard HTTP servers you use for your current HTML Web sites. In the future, we might see new kinds of servers with special capabilities suited to virtual reality applications, or these might be a part of HTTP-NG, a future version of HTTP.

So what can your home world look like? You might have a three-dimensional figure of yourself, or even of your living room (real or virtual). If you like windsurfing, you might have a windsurfer in some waves, linked to a map of your favorite windsurfing spots. Or you could have an art sculpture floating in midair.

History of VRML

At the first World Wide Web conference in 1994, Tim Berners-Lee (developer of the Web concept) and Dave Raggett organized a session known as a “Birds of a Feather” (BOF) session for interested people to discuss virtual reality and how it could be applied to the Web. Things took off rapidly, with the creation of an e-mail list for discussion of what was then called Virtual Reality Markup Language.

Because VRML isn’t SGML (Standard Generalized Markup Language), and because of its graphical nature, the word “Markup” was later changed to “Modeling,” though you can still find references to VR Markup Language floating around the Net. Memes are hard to kill.

The initial BOF meeting included several people who were working on 3D graphical interfaces to the Web. The e-mail list grew and grew: Within a week, there were more than one thousand members. The list moderator is Mark Pesce, one of the prime architects of VRML. Pesce announced the goal of having a draft version of the VRML specification ready for the fall 1994 WWW Conference.

Rather than reinvent the wheel, list members wanted to choose an existing technology as a starting point. Several proposals were put together. You can still see these proposals at the VRML Repository ( Eventually—try getting agreement among that many people—the list chose the Open Inventor ASCII file format developed by Silicon Graphics.

A subset of this format with extensions for Web hyperlinks came to form the initial VRML Specification. Gavin Bell of SGI adapted the Open Inventor format for VRML, with input from the list members. SGI allowed the format to be used in the open market, and also put a language parser into the public domain to help VRML gain momentum.

The three credited authors of the VRML 1.0 specification are Pesce, Bell, and Anthony Parisi of Intervista. Other major contributors are Chris Marrin of SGI and Jan Hardenbergh of Oki Advanced Products.

In December 1995, the first VRML Symposium was held in San Diego. It was the first exclusive VRML gathering, and excitement was everywhere. Several large companies not initially involved in VRML had become quite interested and came to the symposium with their own proposals for how VRML should evolve in the future.

A VRML consortium will most likely be created very shortly. In the meantime, the www-vrml e-mail list and a group known as the VAG, the VRML Architecture Group (, are leading the analysis of proposals for future versions of VRML. The VRML 2.0 Specification is currently under discussion. VRML 2.0 will define the exact mechanism of how VRML and Java will interact, such as tying Java scripts to 3D VRML geometry.

What You Need to Experience VRML

The very minimal setup for experiencing VRML is a computer and VRML browser software. An Internet connection is necessary to download worlds. However, VRML worlds stored on a computer disk can be viewed without an Internet connection. Actually, when I started out creating VRML software, I didn’t have even VRML browser software, so I had to use wetware—my imagination—to visualize how my VRML worlds might look.

A very basic VRML/Java setup would include a 486/50 computer with 8MB RAM, VRML browser software such as WebFX, WebSpace, or WorldView, and an Internet connection with a 14.4KB modem. This will give you basic performance. Because the first versions of the VRML browsers are CPU-intensive and complicated, uncompressed VRML worlds can take up as much as 500KB, which takes a while to transfer over a 14.4KB Internet connection. However, world authors are learning how to create interesting worlds that can be as small as 20KB compressed.

Serious VRML/Java creators will want to move toward a UNIX workstation and a T1 connection. However, to create VRML worlds, all you really need is a text editor and knowledge of the VRML Specification!

There are many VRML browsers available. The most popular ones can be downloaded over the Internet, including:

To go beyond the basic system setup, you can start getting into fancy input and output devices. These can make the experience more immersive, but most people don’t use them. Head-mounted displays (HMDs) bring virtual worlds closer to your eyes by displaying the worlds on two small screens that are part of glasses you wear. Head-tracking devices on the HMDs can figure out which direction you are facing and relay this information to the browser to change your orientation. Using a 3D mouse for input, you can move around in the three-dimensional virtual world, just as a standard mouse lets you move around in two dimensions.

Using the Browsers

Once you have downloaded a VRML browser from the Internet and installed the browser, you are ready to get started. (See Appendix F for URLs.)

Browsers come with some simple worlds that you can load into the VRML browser to begin with. Once you get familiar with the navigation commands, you can start moving out around the Web. A nice starting point on the Web is Aereal Serch, which is a VRML world with links to many other VRML worlds (


In the main navigation mode, you can use a combination of keyboard and mouse to move around. For example, in WebFX from Paper Software (see Figure 34.2), the Fly mode uses arrow keys to affect the orientation of your head, and A and Z move you forward and backward. In Walk mode, the up and down arrow keys move you forward and backward, and the left and right keys turn you left or right. Holding down the Alt button with the arrow keys lets you pan to the sides. Several browsers feature an Examiner or Model mode, where you can spin around the world, rather than moving around inside it. In WebFX, this is accomplished by holding down the right mouse button and moving the mouse. A fun thing to do in WebFX and Webspace is to fling with the mouse: Hold down the button and quickly move the mouse and let go of the button while the mouse is moving. This will spin the world around and leave it spinning—very cool!

FIGURE 34.2.

WebFX from Paper Software.

In WebFX, if you tap the right mouse button for a moment, a menu appears that lets you change the settings or change cameras (that is, move to a different part of the world).


Webspace from SGI and TGS features a unique user interface for the mouse. Examiner mode, where you spin the world around, is controlled with a trackball-style sphere (which will look familiar to fans of the old Centipede) and a roller that moves you forward into and backward out of the world. In Walk mode (see Figure 34.3), you move around a bar that looks like the handlebars of a tricycle. Somehow, it feels like driving a golf cart. Note that there is a little notch on the right side of the bar that attempts to give an indication of the vertical tilt of your viewpoint. This lets you set if you are looking up or down while you move around.

FIGURE 34.3.

A VRML world viewed with Webspace.


WorldView from Intervista is geared towards using the mouse for navigation. (See Figure 34.4.) It has three boxes of buttons that correspond to panning, tilting, and flying. You also can choose between Fly and Inspect modes. Inspect mode is when you are spinning around the world itself rather than navigating in it. WorldView defaults to a blue background in worlds. Also, WorldView works as a standalone browser, so you can start navigating around VRML space without starting up a standard Web browser.

FIGURE 34.4.

A virtual world viewed with WorldView from Intervista.

Introduction to Creating VRML Worlds

Creating VRML can be challenging at first. It’s not as easy as HTML, nor are VRML browsers nearly as forgiving as HTML browsers. There are two ways to get started. First you can use a Web-based VRML authoring tool called Aereal Phonts to create VRML that uses 3D fonts. You can also learn to hand code simple VRML worlds.

Aereal Phonts

To give you a feeling for what VRML looks like, here’s a short VRML world (see Listing 31.1), created with Aereal Phonts, a simple Web-based publicly accessible VRML authoring tool (see Figure 34.5) (

FIGURE 34.5.

Creating a simple VRML world with Aereal Phonts.

#VRML V1.0 ascii

Separator {

    Material { diffuseColor 0.89 0.47 0.20 }

    Scale { scaleFactor 5 5 5 }

    MatrixTransform { matrix 1 0 0 0 .3 1 0 0 0 0 1 0 0 0 0 1 }

    Separator {

        Translation { translation .1 .2 0 }

        Separator {

            Rotation { rotation 0 0 -1 -.4 }

            DEF a Cylinder { radius .05 height .45 }


        Translation { translation .2 0 0 }

        Separator {

            Rotation { rotation 0 0 -1 .4 }

            USE a



    Translation { translation .5 0 0 }

    Separator {

        Translation { translation .05 .2 0 }

        Cylinder { radius .05 height .4 }

        Translation { translation .15 .12 0 }

        Separator {

            Rotation { rotation 0 0 -1 1.57 }

            Cylinder { radius .05 height .25 }



    Translation { translation .5 0 0 }


When you load this world into your VRML browser and spin it around, you’ll see something similar to VRML World, shown in Figure 34.6.

FIGURE 34.6.

Wandering in VRML World created with Aereal Phonts.

Creating a Simple Home World

The MIME type for VRML is x-world/x-vrml. If you haven’t convinced your Web site administrator to add the VRML MIME type to your Web server yet, you can set up a simple CGI script that starts out with the following line (in Perl).

print “Content-type: x-world/x-vrml\n\n”;

Or, for a Java server-side CGI:

System.out.println(“Content-type: x-world/x-vrml”);


After that, you can have the code print-out the rest of your VRML world.

As we saw above, a VRML world starts off with the following first line:

#VRML V1.0 ascii

Anything after a # in a line of a VRML script is considered a comment. For transmission purposes, comments can be stripped out of a VRML file before it is transmitted across a network. If you want anything like a copyright or other information to get to the viewer, you should use an INFO node. However, at the current time, none of the HTTP servers have been configured to strip the comments out, so you can be a bit sloppy in the near future!

Each VRML world consists of one node. Typically, that one node will be a Separator node that includes a grouping of various nodes inside it. Nodes can represent shapes like cubes and cones, properties like colors and textures, or groupings. Nodes can also give World Wide Web references, such as hyperlinks or in-line worlds, similar to HREFs and in-line graphics in HTML (shouldn’t we call them in-space worlds?). As an example, the Material node is a property node that lets you assign colors and transparency properties.

For a detailed description of VRML nodes, refer to the VRML Specification at A VRML-enabled HTML version of the Specification is at

Let’s start by making a simple VRML home world from scratch by hand to illustrate how the language works. Figure 34.7 shows what it will look like in a VRML browser when we’re done.

FIGURE 34.7.

A simple, hand-created VRML world.

We start off with the VRML header and a Separator node to hold the nodes we soon will add. (See Listing 34.2.)

#VRML V1.0 ascii

Separator {


This is a valid VRML file. It will load into your VRML browser, but you won’t see anything. Let’s add a blue sphere. (See Listing 34.3.) We’ll use a Material node to set the color to a blue, and then add a Sphere node with a radius of five meters.

#VRML V1.0 ascii

Separator {

    # blue sphere

    Material { diffuseColor 0 0 .7 }  # sets the color to blue

    Sphere { radius 5 } # creates the sphere with radius 5 meters


Now that we have something showing up in the browser, let’s add something with more visual depth to it. Find an image file on your computer or on the Web. Your VRML browser should support JPEG, GIF, and maybe BMP formats. Let’s add a cube that uses the image as a texture. We’ll locate it seven meters to the right (positive x axis) of the blue sphere by adding in a Translation node. (See Listing 34.4.)

#VRML V1.0 ascii

Separator {

    # blue sphere

    Material { diffuseColor 0 0 .7 } # sets the color to blue

    Sphere { radius 5 } # creates the sphere with radius 5 meters

    # textured cube

    Translation { translation 7 0 0 } # moves away from the sphere

    Texture2 { filename “image.jpg” } # sets the texture to image.jpg

    Cube { } # creates the cube


In Listing 34.4, image.jpg is the URL or filename of your image file. Now your home world is starting to get somewhere. As the final touch, let’s add the VRML you created using Aereal Phonts. We do this using the WWWInline node and the URL for the VRML world you created with Aereal Phonts. We’ll also use another Translation node to move from the center of the cube to the area above and between the sphere and cube. The world now becomes Listing 34.5.

#VRML V1.0 ascii

Separator {

    # blue sphere

    Material { diffuseColor 0 0 .7 } # sets the color to blue

    Sphere { radius 5 } # creates the sphere with radius 5 meters

    # textured cube

    Translation { translation 7 0 0 } # moves away from the sphere

    Texture2 { filename “image.jpg” } # sets the texture to image.jpg

    Cube { } # creates the cube

    # WWWInline the Aereal Phonts world

    Translation { translation -3.5 6 0 } # move above the sphere & cube

    WWWInline { # render the following VRML world inside this world

        name “”



Just replace the name URL in the WWWInline node with the URL of your Aereal Phonts world and your simple VRML home world is ready. As you can see in this example, WWWInline is a very powerful feature that taps into the power of the World Wide Web as a whole and differentiates VRML from non-Web attempts at VR.

Authoring Tools and Converters

There are a variety of tools becoming available to ease VRML world development. Trying to create VRML worlds by hand in a text editor can take quite a while and give you a headache as you try to spatially imagine your world. There are two categories of tools: authoring tools and converters.

Authoring tools are software packages that let you create worlds described in VRML. The HTML equivalent is software programs such as HoTMetaL and HTML Assistant. Hopefully, VRML authoring tools will let you develop and test your worlds in 3D. Most VRML authoring tools are still in very preliminary versions, though you can expect to see an explosion of these tools in the near future. Some that have been announced include Virtual Home Builder from Paragraph, Fountain from Caligari, EZ3D from Radiance, and Aereal Phonts from Aereal. For the latest authoring tool information, the best bet is to check the VRML repository Web sites.

Converters let you create a world using CAD or 3D modeling software and then translate a file from the 3D file format into the VRML format. Converters exist, or are being developed, for formats like DXF, 3DS, OFF, and IV. There are also commercial converter programs such as Interchange from Syndesis that convert between several 3D file formats and support—or are planning to support—VRML.

There’s a problem with converters: they tend to generate huge, inefficient VRML files. In addition, the files may not be true, up-to-spec VRML. There are currently many .WRLs out on the Net that are not real VRML.

Optimizing Virtual Reality on the Web

In the beginning of VRML, many worlds took up large amounts of time to transfer on the Internet because their file sizes were so big. Then once you downloaded the file, it took forever to move around in it. If you would like to avoid these problems, you’ll want to optimize your VRML for file size, rendering speed, and ease of navigation.

File Size

File size is a key factor for transmission over the Internet. If your Java code is creating VRML on the client solely for rendering on the client, file size is not a huge concern. However, in advanced Java/VRML code, you might want to create VRML avatars with geometry that is transported across the Internet for multiuser applications. In this case you will want to minimize the file size of the VRML that is transmitted for speed.

Creating efficient and effective VRML worlds is quite different than using a standard CAD package, so a niche will develop for VRML-specific authoring tools. In addition, standard CAD and 3D modeling packages are starting to include an export capability that lets people save or convert their files to VRML format.

As part of working with the Interactive Multimedia Festival, James Waldrop developed a script that reduces file size by about 75 percent. One file was reduced from 2.3MB down to 570KB. Information on the script is located at It’s important to understand what this script does before you use it, as the special optimizations it does might or might not be appropriate for your world. The script was developed for a VRML version of the Interactive Media Festival. (See Figure 34.8.) You can use the same file size optimization techniques to write Java code that produces small VRML file sizes.

Using these techniques and gzip compression, James, Mark Meadows, and others with the Interactive Multimedia Festival ( managed to compress their files by 94 percent. The techniques they used were the following:

FIGURE 34.8.

Interactive Multimedia Festival in VRML.

Rendering Speed

The techniques above are useful for optimizing transmission time for users with low-speed network connections. The other main area for optimization is in rendering speed. These two concerns, transmission and rendering speeds, are sometimes at cross purposes, because improving rendering speed sometimes can result in a larger file.

Three important techniques for optimizing rendering time are the use of cameras, rendering hints, and levels of detail. Another concern is when to use texture maps.

The Future of VRML, Version 2.0 and Beyond

The four main enhancements that are expected for version 2.0 of Virtual Reality Modeling Language are interactivity, behaviors, 3D sound, and multiuser capabilities. The VRML community currently is considering proposals for VRML 2.0. Some of them, such as the Moving Worlds proposal from SGI/Sony/WorldMaker, build on VRML’s 1.0 Open Inventor-inspired format. Proposals from Apple, Microsoft, and others depart from it significantly. Let’s examine what these enhancements mean.


In an interactive virtual world, you can open doors, and watch them slowly open. You might move around the furniture in your apartment. Or hit the snooze button on your twitching, ringing alarm clock, after you get pulled out of a dream virtual world back into your home virtual world.

Designing this level of interactivity into VRML will be a challenge. It also might increase file sizes significantly.


Version 1.1 of VRML should include some limited capacity for animation. In version 2.0 and beyond you should be able to create behaviors, so that objects tend to have a minimal life of their own. Besides having some limited movements, such as a windmill turning, we might get objects that affect each other, so that when Don Quixote tries to joust with the windmill his horse shies away, or else the windmill shreds the tip of his lance. Behaviors are where Java will become most important, since most behaviors will be Java, with calls to an API that interfaces to the VRML browser. The interface mechanism is not defined yet. The behavior of an object will most likely be like a property of the geometry, with a URL link to the Java code. There is some discussion of including Java bytecodes in the VRML source.


3D sound gets very interesting and brings in a whole range of new possibilities. Sound has been a key feature in creating good immersive environments. In fact, people experimenting in VR have found that small improvements in sound will improve the immersive experience, as perceived by the user, more than small improvements in graphics quality.


Imagine playing football with a group of people in a virtual world in cyberspace, or imagine designing a new product with them. For these applications you need to have a multiuser capability in your virtual world. In multiuser VRML, people are shown using avatars, cyberspace representations people. VRML will allow support for multiuser worlds in the future. The initial multiuser support will most likely be through Java code, that actually sends the signals of avatar position and velocity. Some of the issues that need to be tackled include logging of who is currently in the world, including killing off vampires (people who have stopped being involved even if a message has not been sent to the server saying that they are signing off). Also, in some worlds you will want collision detection to prevent two avatars from existing in the same space. In addition, there needs to be a way to hand off avatars to other servers if someone chooses a hyperlink to another world. Other considerations will include how a person’s avatar (cyberspace-representation) is created, how it is logged and transmitted, and what rules it might need to follow in various worlds.

Other VRML 2.0 Issues

In addition to the technical issues, probably the biggest challenge for VRML 2.0 (as Mark Pesce alludes to later) is getting a consensus for what VRML 2.0 should be. At this point, there are a lot of companies, money, and people involved in VRML, each with their own interests. It will be interesting to see how things work out.

Java Meets VRML

Java will drive multiuser interactions and behaviors in VRML 2.0 worlds. It is likely that other languages will be used in VRML 2.0 in addition to Java.

How Java Will Interact with VRML

Java can interact with VRML in at least two ways: describing extension nodes and as scripts loaded in-line to describe the interactions of VRML objects.

The first work combining VRML and Java resulted in Liquid Reality, a VRML tool kit written in Java by Dimension X. In Liquid Reality, if the Liquid Reality browser does not recognize a node, it requests the Java code describing the node from the server that served the file.

In most of the approaches being drafted for VRML 2.0, software code can be used to animate VRML objects. The Java code can be referenced in a URL attached to the geometry. The VRML 2.0 proposals are also considering allowing Java bytecodes to be inserted directly into a VRML file.

Mark Pesce ( is one of the creators of VRML and is author of VRML-Browsing and Building Cyberspace (New Riders, 1995), a book about VRML. According to Mark, “Java and VRML are perfect complements. Java is all about how things behave but says very little about how they appear. VRML is all about appearances, without speaking to how things behave. You could say that VRML is, while Java does. They need each other.”

Mark sees Java and VRML developing, “Into a closer relationship—one where it becomes difficult to know where VRML ends and Java begins, and vice versa. I expect that when people want to talk about imaging Java, they’ll use VRML, and when they think of motivating VRML, they’ll use Java.”

Mitra, the Chief Technology Officer of WorldMaker, sees VRML and Java remaining distinct. “I believe they will remain distinguishable for the foreseeable future; the equivalent is HTML and Java, where the HTML provides the structure and Java the functionality. In fact, in 3D they are likely to remain more distinguishable because the only way for the Java applets to influence the world is by manipulating a VRML scene graph.”

Dimension X’s Liquid Reality

Liquid Reality is a VRML tool kit written in Java, from Dimension X. Using extension nodes, you can create worlds with flying birds (see Figure 34.9) and bouncing apples (see Figure 34.10)!

Karl Jacobs is CEO of Dimension X ( and Scott Fraize is Caffeinated Alchemist. Dimension X has developed Ice, a Java API for 3D, and Liquid Reality, a VRML tool kit for Java based on Ice.

Q: What is Liquid Reality?

Karl: It is a VRML tool kit. It provides everything you need to read in VRML and write out VRML and extend it with Java. It has all the mechanisms to do that on the fly. It’s wrapped around Intel’s 3DSound, which only took two days to add into Liquid Reality. You just use a Directed Sound node. Here’s where you are in space, here’s the sound file and there you are.

Liquid Reality is based on Ice, fully integrated with the tool kit. It differs from other APIs in that Liquid Reality is written in Java, so that it provides hardware independence. It’s not as fast as Renderware and Reality Labs [the APIs other PC VRML browsers are written in] yet.

We’ll be able to go to 2.0 relatively easily, whereas others will have to redesign. We can update the tool kit without re-releasing, by putting new Java classes up on the servers. Chris [Laurel of Dimension X, a Java/VRML guru] just ported Liquid Reality to SGI and Linux over the weekend.

Q: How will Sun’s efforts to add 3D support to Java affect Liquid Reality?

Karl: Sun’s 3D efforts are complementary to Liquid Reality. Rather than “canvas,” you’ll say “canvas3d.”

Q: Will people need to be able to program in Java to do Java-enabled VRML?

Scott: Right now, you do have to program a bit. However, there’s a library of plug-ins and effects, like Rotor node, that you can use.

Q: What business model do you foresee?

Karl: Ice is an API; we want to get it out there quickly and as widely as possible. The idea is that even if you want to put it up on your Web page as a free game, that’s fine.

Liquid Reality is a tool kit so you have to pay a fee for updates and so on. The viewer is free. It’s the try and buy that seems to be proven on the Internet.

FIGURE 34.9.

A Liquid Reality VRML world with flying birds, a flowing stream, and a spider that runs away from you when you get close to it.

FIGURE 34.10.

A bouncing apple in a Liquid Reality VRML world.

Listing 34.5 shows an example of a VRML world that has a rotating object in it, as referenced by the Rotor node.

#VRML V1.0 ascii

Separator {

   DEF BackgroundColor Info { string “0.5 0.5 0.5” }

   DEF Viewer Info { string “walk” }

   DEF ViewerSpeed Info { string “0.3” }

   Clock {}

#   PointLight { location 0 0 10 }

   PerspectiveCamera {

      position 0 0 8

      orientation 0 1 0 0


   DirectionalLight { direction 1 0 0 }

   Material {

      ambientColor [ 0 0 0 ]

      diffuseColor [0.1 0.5 0.2 ]

#      specularColor [0.8 0.8 0.8]

      shininess 0.25


   Separator {

#      Rotation { rotation 0 1 0 1.57 }

      Sphere { radius 1.1 }


   Translation { translation -3 0 0 }

   Material {

      ambientColor [ 0 0 0 ]

      diffuseColor [ 0.7 0.1 0.1 ]


   Cube { height 1.5 width 1.5 depth 1.5 }

   Translation { translation 6 0 0 }

   Material {

      ambientColor [ 0 0 0 ]

      diffuseColor [ 0.2 0.7 0.8 ]

#      specularColor [1 1 1]

      shininess 0.4


   Separator {

      Rotor { rotation 1 0 0 1 }

      Cone {}


#   Cylinder {}


Listing 34.6 shows the Java code that describes the Rotor extension node with calls to Liquid Reality’s API.



// Copyright  1995 Dimension X, Inc.

//   Chris Laurel 8-14-95

package ice.scene;

import ice.Matrix4;

//  Rotor {

//     rotation   0 0 1 0     # SFRotation

//     speed      1           # SFFloat

//  }

public class RotorNode extends ModelTransformationNode


   static String fieldnames[] = {




   static NodeField defaults[] = {

      new SFRotation(0, 0, 1, 0),

      new SFFloat(1)


   public SFRotation rotation = new SFRotation((SFRotation) defaults[0], this);

   public SFFloat speed = new SFFloat((SFFloat) defaults[1], this);

   NodeField fields[] = {

      rotation, speed


   public int numFields() { return fields.length; }

   public String fieldName(int n) { return fieldnames[n]; }

   public NodeField getDefault(int n) { return defaults[n]; }

   public NodeField getField(int n) { return fields[n]; }

   public void applyModelTransformation(Action a)





                (float) (rotation.getAngle() +

                     speed.getValue() *

                     a.state.getTime() % (2 * Math.PI)));



Paper Software

Paper Software is creating a Java API for VRML. The preliminary version is code-named Xpresso, and we’ll look at a simple example to see the direction it is heading in. Expect it to be different when it is released.

Mike McCue is the founder and CEO of Paper Software, creator of the WebFX VRML browser. Paper Software was acquired by Netscape for its VRML and VRML/Java technology. Paper Software is developing a Java API for VRML.

Q: How will world creators author Java-enabled VRML?

A: Our goal is that you will write a series of Java scripts that orchestrate behaviors. The behaviors themselves will probably be in DLLs initially. Right now the threading model is too slow for the performance people will want. Java will be an orchestrating mechanism for the overall world.

You kick off a canned behavior that exists native in our DLLs. That’s the short term. Longer term, I think there will be a set of Java classes that will give you canned behaviors. As a world author, maybe I’ll have a canned behavior that allows a man to run. I see that happening very soon after the first versions come out.

A few months later the canned Java behaviors will come out, and you will be able to drag and drop them onto VRML objects.

Longer term to that, eventually Java itself will become the behaviors engine, and you’ll have some physics such as collision detection, gravity, and elasticity in the browser, but you’ll have Java gradually implementing that too.

Q: How would you describe the future of Java and VRML? Will it even be possible to differentiate between Java and VRML?

A: Yes, I think it will be possible to differentiate between the two. That’s because VRML is a file format and Java is a programming language.

You’ll see VRML in OCXs and C++ APIs. There’s a life beyond Java for VRML in a big way. I think it will be incorporated into Microsoft PowerPoint and Excel. I think it will be incorporated into your mission-critical applications.

Our goal is to begin with Java but to make sure we don’t back ourselves into a corner by relying on it. We want to be language neutral.

On the Internet, Java and JavaScript will be the way to go.

Q: You’ve mentioned an interest in VRML as a starting point for multidimensional interfaces. What do you mean by that?

A: I gradually see the bulk of applications and operating systems today taking more advantage of 3D space to organize info rather than 2-D windows. I think 3D represents the next major user interface step. You will run all of these applications in a 3D environment. It will become a core, centralized part of the operating system.

This example is a bouncing ball, with the Java code It is referenced by putting the line

DEF BALL Sphere {}

in the VRML file. Figures 34.11 and 34.12 show screen shots of the ball in action.

FIGURE 34.11.

A bouncing ball in midair created with Paper's Java API.

FIGURE 34.12.

The bouncing ball is now squished on the ground.

This is what the Java code looks like. Notice that import xpresso brings in Paper’s VRML API. You can see the calls to the API that start with webfxObject. (See Listing 34.7.)

// Bring in some Java classes we will need

import java.awt.Graphics;

import java.util.Date;

import java.lang.Math;

import xpresso;

// A Java class that runs in its own thread as an applet

Âpublic class javaball extends java.applet.Applet implements Runnable {

    // variables

    Thread  ballThread;

    int     y = 0 ;

    float   fTemp = 0.0f;

    float   fHeight = 0.0f;

    int     object_id = 0 ;

    int     lSession = 0 ;

    int     lObjectID = 0 ;

    float   ff[] = new float[16] ;

    // Create an object to interface with VRML

    xpresso webfxObject = new xpresso() ;


// init method


    public void init()


        // Initialize the VRML interface

        while (lSession == 0)

            lSession = webfxObject.XpressoInit() ;

        // Get pointers to the Ball object

        if (lSession != 0)


            String strCube        = “Ball”;

            String strFloor    = “Floor”;

            while (lObjectID == 0)

                lObjectID = webfxObject.XpressoGetObject(lSession, 0, strCube) ;




// start method


    public void start()


        if (ballThread == null)


            ballThread = new Thread(this, “Ball”);



        // Initialize to Identity matrix

        ff[0]=   1.0f;

        ff[1]=   0.0f;

        ff[2]=   0.0f;

        ff[3]=   0.0f;

        ff[4]=   0.0f;

        ff[5]=   1.0f;

        ff[6]=   0.0f;

        ff[7]=   0.0f;

        ff[8]=   0.0f;

        ff[9]=   0.0f;

        ff[10]=  1.0f;

        ff[11]=  0.0f;

        ff[12]=  0.0f;

        ff[13]=  0.0f;

        ff[14]=  0.0f;

        ff[15]=  1.0f;



// run method


    public void run()


        while (ballThread != null)


            fHeight = 0.0f;

            // Ball falls down in 20 steps

            for (y = 1; y < 20; y++)


                fTemp   = (float) y ;

                fHeight = fHeight + (1/fTemp);

                ff[13]  = fHeight;

                if (y>0)


                    ff[0]   = 1f;

                    ff[5]   = 1f;

                    ff[10]  = 1f;


                // Transform this ball to its new location and squoosh factor

                // then .... render the scene so we see the results

                if (lObjectID != 0)


                   webfxObject.XpressoTransformObject(lSession, lObjectID, ff, 2) ;

                   webfxObject.XpressoRenderScene(lSession, 0) ;



            // Ball bounces up ... in 20 steps

            for (y = 20; y > 0; y—)


                fTemp   = (float)y;

                fHeight = fHeight - (1/fTemp);

                ff[13]  = fHeight ;

                if (y==1)


                    ff[0] = 1.2f;

                    ff[5] = .8f;

                    ff[10] = 1.2f;


                if (y>1)


                    ff[0] = 1f;

                    ff[5] = 1f;

                    ff[10] = 1f;


                // Transform this ball to its new location and squoosh factor

                // then .... render the scene so we see the results

                if (lObjectID != 0)


                   webfxObject.XpressoTransformObject(lSession, lObjectID, ff, 2) ;

                   webfxObject.XpressoRenderScene(lSession, 0) ;



            try {


            } catch (InterruptedException e){





// stop method


    public void stop()



        ballThread = null;




The explosion of interest in the World Wide Web has been incredible! VRML promises to ramp this exponential growth up to a new level of interactivity and feeling. Java will be the life force and pump to drive motion and interaction in advanced VRML worlds.

As VRML moves into its 2.0 version, and Java adds life to it, virtual reality on the Net will become as commonplace as HTML is today. Java-based interactivity, animations, and behaviors will enliven virtual worlds with personality and attitude.

Businesses will take advantage of virtual reality on the Web, starting with marketing efforts and graduating to original content.

Previous Page toc Index Next Page