VRML Language Basics

A VRML file contains a file header, comments, and nodes. Nodes, which describe objects, may have names and contain fields and values. Comments and the file header begin with the pound sign, and curly brackets delimit the hierarchy of nodes and fields. Named nodes may be reused elsewhere in the scene.

VRML files measure distance in meters, angles in radians, time in seconds, and colors as RGB triplets with each value in the range [0.0,1.0]. It uses a Cartesian, right-handed three-dimensional coordinate system. By default, the viewer is positioned along the positive Z-axis so as to look along the -Z direction with +Y-axis up.

VRML files use the .wrl (world) extension and the model/vrml MIME type. The older x-world/x-vrml MIME type is still supported for backward compatibility. VRML source is normally encoded in UTF-8, which is a superset of standard ASCII. You can compress .wrl files for the web with GZIP; this can make a big difference in download times.

The basic node for defining visible VRML objects is the Shape, which in turn contains Geometry and Appearance nodes. So, for example, the following example defines a world containing one cylinder 2 meters high with a 1.5 meter radius with default material properties, meaning that the object will appear to be a glowing white:

#VRML V2.0 utf8
# A Cylinder
Shape {
    appearance Appearance {
        material Material { }
    }
    geometry Cylinder {
        height 2.0
        radius 1.5
    }
}

(Click here to view this example.)

The available geometry nodes are the Box, Cone, Cylinder, ElevationGrid, Extrusion, IndexedFaceSet, IndexedLineSet, PointSet, Sphere, and Text. In addition, you can use nodes created from PROTOs or EXTERNPROTOs, which are essentially custom nodes defined in terms of the primitive nodes.

The Box, Cone, Cylinder, and Sphere are geometric primitives (example; code). The Text node displays a string with a specified font style (example; code). The WorldInfo node holds the world's title and other information, such as author and copyright. The ElevationGrid node creates surfaces and terrains. The Extrusion node creates solids by sweeping a 2D cross-section though a 3D spine. The IndexedFaceSet, IndexedLineSet, and PointSet nodes use Coordinate nodes to create solid faces, lines, and points, respectively. These raw geometry nodes give you more flexibility than the geometric primitives, and can actually create more efficient VRML worlds.

You can control the diffuse (shading) color, emissive (glow) color, transparency, shininess, and the other optical properties of an object using its Appearance node's Material field. These optical properties interact with the scene lighting to determine the image presented to the viewer. Shadows are not generated automatically, but you can fake them (example).

Only some kinds of materials are well described by the optical properties specified in the Material field. Metal and glass are; wood, tile, and painted objects are not. You can override optical properties with Color nodes, or wrap textures -- two-dimensional images -- around the 3D shapes. VRML supports three kinds of texture mapping fields: ImageTexture (from JPEG, PNG, and GIF files), PixelTexture (from raw image data), and MovieTexture (from MPEG1 files). If you use an image with an alpha channel for texture, you can create "holes" in the texture mapping that allow the underlying material properties to show through.

Geometry nodes can be grouped several ways. The Group node combines its children, adding a bounding box for the whole. A Transform node is a group plus a geometric 3D transformation that applies to the group, consisting of (in order):

  1. a (possibly) non-uniform scale about an arbitrary point
  2. a rotation about an arbitrary point and axis
  3. a translation

Transform nodes are used extensively in VRML worlds, since all objects are by default constructed at the origin of the space.

An Anchor node is a group plus a target URL, which transfers control to the target when it is activated. A LOD node allows the VRML browser to automatically choose from several models of the same object with different levels of detail, based on the distance between the current viewpoint and the object. Additional grouping nodes allow for children external to the current file (Inline), collision detection (Collision), conditional object display (Switch), and always-visible content (Billboard).

DEF defines the name of a node. USE lets you refer to a named node. You can use a named node as many times as you wish.

Ground color, sky color, and background textures are defined by the Background node. Multiple backgrounds can be kept in a stack and bound dynamically. Atmosphere and an increased sense of depth can be created by using a Fog node. You can provide Viewpoint nodes to help the user navigate your world.

By default there is a headlight shining in front of the viewer. In addition, there can be three kinds of light source in the world: directional, point, and spot lights. These lights interact with the colors and material properties of the objects.

Introduction to VRML

VRML Language Basics

Advanced VRML Capabilities

Sample VRML "Worlds"

VRML Links

Up to Martin Heller Home

Last edited 05/15/00