VRML Tech Talk

Last time, we looked at the basic syntax of VRML--the Virtual Reality Modeling Language. This issue, we're going to start looking at some of the different types of nodes that make up the language.

by Bernie Roehl

VRML nodes can be grouped into several categories. Some nodes describe shapes, like cubes or spheres. Others describe lights, and still others describe the surface properties of objects, such as their materials and textures. There are also nodes that allow you to position objects in space. This issue we'll be examining the shape nodes.

There are eight basic types of shape nodes in VRML 1.0. The next release of VRML (version 1.1, which is now in draft form) adds two others. Every visible object in a VRML world is created using one or more of these ten basic types of shapes.

Geometric Primitives

The easiest shape nodes to understand are the ones that create simple geometric primitives: Cone, Cube, Cylinder and Sphere. Each of these has certain parameters, or "fields". For example, a Cylinder node has a radius, a height, and a "parts" field that indicates which parts of the cylinder are actually present (see Listing 1).

This VRML file creates a single cylinder with a radius of two meters and a height of three meters. It has a bottom and sides, but is open on the top.

Lower Level Shape Nodes

The next group of shape nodes are used to create individual points, lines and faces. The PointSet node creates a cluster of individual points in space, the IndexedLineSet node creates a group of line segments, and an IndexedFaceSet creates a polygonal (or "faceted") object. The IndexedFaceSet node is one of the most important ones in VRML, since most objects are described in terms of their faces and not in terms of lines, points or geometric primitives. The IndexedFaceSet is used with a Coordinate3 node that gives the locations of vertices in an object. Listing 2 shows an example.

A VRML file consists of a single node; since an IndexedFaceSet requires a Coordinate3 node as well as an IndexedFaceSet, we combine them using a Separator node that contains them both. The Coordinate3 node stores the X, Y and Z values for each of five points that define the vertices of a pyramid. The IndexedFaceSet contains a coordIndex field that lists which vertices should be used for which faces; the first face consists of vertices 0, 4, and 1 from the list in the Coordinate3 node (computers always start counting from zero, so the "0th" vertex is the first one in the list, and the "4th" vertex is the fifth in the list). The -1s in the list mark the end of each face and the start of the next one.

What About Text?

One very common requirement in virtual worlds is text. You want to be able to create signs and other types of messages, and it's a nuisance to have to specify the vertices of each individual letter. Fortunately, VRML has a node for creating text; in version 1.0 it's called AsciiText, but in VRML 1.1 it will be renamed to simply Text. This is part of the "internationalization" of VRML, which involves moving away from an English-only ASCII character set and into a set called "utf8" which can represent characters from other languages.

An AsciiText node has a "string" field containing the text itself, and fields for specifying the spacing and justification (left, right, or center). There's also a FontStyle node that lets you select a typeface, style and size.

ElevationGrid and GeneralCylinder

Theoretically, any object can be represented by an IndexedFaceSet. However, there are times when it's much more concise to use a higher-level node such as a Sphere or a Cone. They're a kind of "shorthand" way of representing a shape that would otherwise require a large number of vertices. VRML 1.1 adds two shape nodes that can potentially save a lot of space.

The first is an ElevationGrid, which allows you to specify a rectangular array of height values and have them automatically turned into a set of faces that correspond to terrain. It takes much less file space (and download time) to list the heights rather than individual vertices and faces.

The second new node is the GeneralCylinder. It lets you specify a cross-section, an extrusion path, a "twist" and a varying scale; by using those fields in various combinations, you can produce surfaces of extrusion or revolution. For example, a doughnut could be easily expressed as a GeneralCylinder; so could a wine goblet, a (symmetrical) fir tree, a seashell or a corrugated steel roof.


These ten nodes (Cone, Cube, Cylinder, Sphere, PointSet, IndexedLineSet, IndexedFaceSet, Text, ElevationGrid and GeneralCylinder) can be used to create any object you can imagine. Next time, we'll take a look at how to give these shapes surface properties and textures.

If you need more details about VRML, a good starting point is the * VRML Repository, which has links to software, documentation and more. You may also want to check out Special Edition: Using VRML, a book I've co-authored with Stephen Matsuba. It discusses VRML in considerable detail, and gives you everything you need to start building complex and interesting worlds.

Bernie Roehl is probably best known for REND386, a freeware VR library for PCs. He is 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 is also active on the VRML mailing lists, and is maintaining a collection of proposed changes to the VRML spec. His e-mail address is