VRML Tech Talk

by Bernie Roehl

By now you've no doubt heard of VRML -- the Virtual Reality Modeling Language. Designed to bring real-time 3D interaction to the World Wide Web, VRML is rapidly becoming the most important standard in the VR industry.

For people already involved with the VR industry, VRML represents the first serious attempt to bring some order to the chaos of 3D graphics file formats. For Web users, it represents a challenging new medium of expression.

Basic Concepts

In the beginning, there was text -- and it was good. Text is a very expressive medium, and for many types of information it's the ideal choice. However, text is inherently one-dimensional; it's a linear series of words strung together to express ideas and information.

One of the things that makes the Web so powerful is that it isn't restricted to text; it also allows images to be embedded in a page. Images are two-dimensional, and are capable of expressing certain types of information much more concisely than text can.

VRML is the next step; it's a three-dimensional medium. Instead of storing images composed of pixels, objects in VRML are stored as mathematical descriptions of their geometry (along with lights and viewpoints). Once retrieved from the Web, a VRML scene can be viewed from any angle; you can also move around inside the scene at will.

Similarities to HTML . . . and Differences

If you're familiar with the Web as it exists today, then you're already far along the learning curve for VRML.

Like HTML, VRML is an ASCII file format; this ensures that it's platform-independent, and avoids problems with things like byte ordering that are encountered in binary formats. It also makes it easy for developers to create files (even using a text editor), and to write translators and scene generators.

VRML is retrieved from standard Web servers, just as HTML is; it uses a MIME content type of world/vrml (or x-world/x-vrml), and a file extension of ``.wrl'' (for ``world''). The reason ``.wrl'' was chosen instead of ``.vrml'' is that three-character extensions are useful for DOS and Windows compatibility, thereby avoiding the ``.htm''/``.html'' confusion.

It's also possible to put ``anchors'' into a VRML document, analogous to the <a>...</a> tags in HTML. The anchors used in VRML can link the user to another virtual world, or to any other type of document. For example, by clicking on a door the user might be transported to another world; by clicking on a book, the user might be taken to a conventional Web browser to view the text of that book.

VRML worlds can also reference resources elsewhere on the Web. Like HTML, VRML can embed a bitmap; the difference is that VRML takes that two-dimensional image and uses it as a ``texture map'' on a three-dimensional surface. For example, you can apply a photograph of a brick wall as a texture map on a wall in the virtual world. You can even build a gallery of paintings, each of which is an image from somewhere on the Web that is texture mapped into the picture frame.

Size and Speed

One problem with VRML worlds is that they're potentially quite large. Bitmapped images used for textures can be very bandwidth-intensive. Even in the absence of such images, the long lists of three-dimensional coordinates that are commonly found in VRML files can take a long time to transfer.

Fortunately, those lists of coordinates are almost ideal candidates for compression; it's anticipated that almost all VRML files will eventually be stored using a compressed format such as gzip.

Syntax

Despite all these similarities to HTML, VRML really is a different beast altogether. There are no syntactic similarities, which is not surprising given that VRML and HTML are describing fundamentally different types of data.

A VRML file begins with a header, consisting of the characters ``#VRML V1.0 ascii''. This allows VRML files to be easily identified, as well as giving their version number. The # at the beginning of the line indicates that the remainder of the line is a comment.

Following the header line is a single VRML node'', which will almost always contain the remainder of the nodes making up the file. That node, called a Separator, serves to ``contain'' the file's contents. This is similar to the way that the <html>...</html> tags surround the contents of an HTML file.

Nodes

The fundamental data structure in VRML is a node. A node is represented by a node type, followed by a pair of curly braces which surround information about the node. For example, Sphere { radius 5.0 } creates a Sphere node with a radius of five meters.

Within the curly braces are a series of fields. A field consists of a field name (like radius in the case of a Sphere) followed by a value (in the case of our Sphere, the value was ``5.0''). Values aren't just numbers; they can be strings, vectors, enumerated types, and more. They can also be single-valued, or multi-valued; if they're multi-valued, the list of values is surrounded by square brackets.

For certain types of nodes (classified as ``grouping'' nodes), the list of fields can be followed by additional nodes which are considered to be children of that node. The VRML file therefore describes a Directed Acyclic Graph, or DAG.

A node can be given a name using the DEF keyword; for example, DEF my_sphere Sphere { radius 5.0 }. This name can subsequently be referenced using the USE keyword.

Summary

This has been a quick and cursory look at the VRML file format. If you need more details about VRML, a good starting point is http://vrml.wired.com.

Bernie Roehl is probably best known for REND386, a freeware VR library for PC's. He's also the author of two books on virtual reality, including the popular ``Playing God: Creating Virtual Worlds''. Bernie is currently a regular columnist for both VR Special Report and VR News. He's also active on the VRML mailing lists, and is maintaining a collection of proposed changes to the VRML spec. His email address is broehl@sunee.uwaterloo.ca