The Web in 3D:
An Intro to VRML
by Jay Lorenzo
VRML files are delivered by Web servers in much the same way that HTML files are. The server processes a given request, and if configured correctly, it detects that the file is mapped with a .wrl extension, and returns a MIME content type of x-world/x-vrml prepended to the contents of the requested file itself. The Web browser, in turn, parses the content type, and if it supports a VRML plug-in or helper application, the 3D scene is displayed. Unlike standard Web browsers, though, VRML viewers require 3D navigational controls to allow the user to explore the document.
VRML documents describe geometric models and their corresponding relationships and properties as they are defined within that document. Many of the definitions used in the VRML1.0 file specification are actually a subset of the ASCII file format of Open Inventor, a C++ graphics library created at Silicon Graphics that describes three-dimensional objects and their environment. Much to their credit, Silicon Graphics released both the ASCII file format of Open Inventor and code examples for parsing these files into the public domain, allowing the creators of VRML access to a stable production 3D description language as well as the software necessary to create a VRML viewer.
VRML uses text descriptions to define the concept of nodes, which describe the shape, properties, or logical grouping of three-dimensional objects. More specifically, nodes may represent geometry, material, texture, lighting, scale, rotation, positioning, lighting, and perspective data that is used to describe the objects that comprise a static three-dimensional world, referred to in VRML-speak as a scene description. The actual collection of nodes in a VRML document are referred to as a scene graph.
Real-World Code
It is probably easier to understand VRML by looking at some simple VRML code that defines some 3D objects and their behavior--in this case, a blue cube and a red cylinder. We will specify the positions in space for the two objects, and while we're at it, let's illuminate these objects with a directional light source (much like a headlight). We will also include the VRML equivalent of hypertext links to each object so that when an object is pointed at, a text reference to its link will be displayed, and when selected, it will retrieve a hypertext document.
In the print magazine, you can see what the code generates, as viewed on a Windows NT machine running Netscape using the WebFx (now called Live 3D) plug-in.
Let's take a look at this code and see what we can learn. We can see that a VRML document is first defined by the "#VRML V1.0 ascii" tag, which tells the browser to parse the following code as a VRML 1.0 document and render the objects described within. The VRML code is grouped hierarchically within braces and uses constructs called Separator nodes (which are usually used to logically group nodes that share common attributes). Separators prevent the nodes within it from being aware of other nodes outside of that particular Separator. Note that multiple Separators can exist hierarchically within the scene graph, each creating a subgrouping of common elements (nodes).
Light On The Subject
We start by establishing a node that describes the directional light source to be used for this scene description. When you rotate the model in a VRML browser, you will see that the illuminated area of the objects does not change, as the scene that we are describing is static.
The next node that we encounter is the WWWAnchor node. This too is a group node, but it also provides the VRML equivalent of the HTML <A HREF> tag, and it references a URL for the link. One of the more intriguing characteristics in VRML is the use of URL linking for inline and anchor references. Although we have intentionally omitted it in this column, VRML also has an equivalent of <IMG SRC> called the WWWInline node, which allows other 3D objects to be referenced and included within the scene description.
It is important to realize that the various attributes of a particular 3D object are ordered, meaning that the attributes of a node defined in a scene graph influence subsequent nodes defined after it. As a case in point, notice how all of the various attributes of both the cylinder and the square are defined prior to the description of the geometric shape itself.
In the case of the red cylinder, we start by specifying the current surface material as being diffuse (meaning that it absorbs light), and we assign the RGB values in a range from 0 to 1 for each primary color. VRML uses an additive color model when describing colors.
This particular example is pretty simplistic. It is much more common to also include texture maps that define more complex surfaces.
Next, we specify a transform node, which changes the positioning with respect to the Cartesian origin. Lastly, we define the geometric primitive, including the dimensions of the cylinder, specifying a radius and height. Just for the record, one unit in VRML is meant to be equivalent to one meter.
The cube follows the same logic of description, but adds a rotation parameter that defines the axis of rotation and the amount of right-handed rotation about that axis. As you may guess, the rotation is measured in radians.
Admittedly, this is a very rudimentary example of 3D objects in VRML. Most useful 3D models are defined by thousands of nodes and texture maps when attempting to describe a complex object. In the real world, most complex models are created with 3D modeling programs that provide VRML output. We will use a 3D modeling package in the next column when describing more complex objects.
Thinking in 3D
As we have discovered, VRML describes static scene descriptions, which limit the total amount of interaction that can be achieved. Given that, there is much potential in the use of interactive "walk-through" models for interface design (such as cyber malls, cyber libraries, etc.). In these, the user navigates to an appropriate location within the model, and then interacts with information linked to that location.
Additionally, 3D models can represent easily recognized objects. Consider a hypothetical intranet Web server that is responsible for reporting the international sales figures for a multinational corporation. It's likely that a 3D representation of the Earth would serve as a convenient way to select a particular continent, and then zoom in to greater detail of a particular region, ultimately selecting a link that returns the sales reports for the area you have chosen.
Well, that's about all we can fit into this month's column, and we have barely scratched the surface of what VRML is capable of. Next time around, we will dig a bit deeper and create a model or two for some potential Web uses. In the meantime, if the spirit moves you, I strongly suggest you pay a visit to the VRML Foundry and read a copy of the VRML specifications, to get a better understanding of the Web design possibilities with VRML.
Cube/Cylinder Code
#VRML V1.0 ascii
Separator {
#Logical grouping of everything in this document
DirectionalLight {
direction 0 0 1
#Creates a direction light shining into scene
}
DEF RedCylinder WWWAnchor {
name "http://pubs.internet.com/mayjun96/redcyl.html"
description "A red cylinder linked to a HTML document"
Material { diffuseColor 1 0 0 } # Red
Transform { translation 4 4 1 }
Cylinder {
parts ALL
radius 1.5
height 3
}
}
DEF BlueCube WWWAnchor {
name "http://pubs.internet.com/mayjun96/bluecube.html"
description "A blue cube linked to a HTML document"
Material {
diffuseColor 0 0 1 # Blue
}
Transform {
translation -2.4 .2 1
rotation 0 1 1 .9
}
Cube {
width 2
height 2
depth 2
}
}
}
Jay Lorenzo currently spends his time overseeing administration of the internal and external Web servers at Walker Richer & Quinn, Inc. He is a partner in Strings, a Seattle-based Internet consulting company.
Reprinted from Web Developer® magazine, Vol. 2 No. 2 May/June 1996 (c) 1996 internet.com Corporation. All rights reserved.
Web Developer® Site Feedback
Web Developer®
Copyright © 2000 internet.com Corporation. All rights reserved.