Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

3D computer graphics: Getting the hang of VRML

Learn about VRML and how you can use it to define your own virtual world

  • Print
  • Feedback
Until fairly recently the Internet and its vast resources were the domain of academics and government agencies. However, by the spring of 1994, that had all changed. With the combination of a universal addressing scheme for resources on the Internet (the URL or Universal Resource Locator), a structured hypertext system for documents on the Internet (the HTML or HyperText Markup Language), and a protocol that tied them together (the HTTP or HyperText Transfer Protocol), the Internet -- via the World Wide Web -- became a very accessible medium for the average person.

The combination of a URL, HTML, and HTTP made the Internet look like a vast universe of electronic pages -- flat, two-dimensional documents containing text, images, and links to other locations.

Most of us were satisfied with this new-found means of data gathering. Two dimensions, however, left a few folks feeling, well, a bit flat. While HTML was quickly gaining ground, several adventurous individuals, perhaps having digested a few too many Gibson-esque cyberpunk novels, were looking to add a third dimension to the Web.

The eventual result was the Virtual Reality Modeling Language (VRML). Based on the Open Inventor ASCII format from Silicon Graphics, VRML made it possible to describe three-dimensional scenes, complete with shapes, lights, textures, and other effects. VRML provided Web surfers with the added ability to interact with the Web via objects in the virtual world.

Java, as it turns out, it ideally suited for the task of implementing VRML. It is reasonably fast, portable, and, like VRML, tightly coupled with the Internet.

Let's begin our journey into three dimensions with a look at how a VRML document is structured.

The structure of a VRML document

The information provided in this section is based on the VRML 1.0 specification. We'll be focusing on the overall structure of a VRML document, but you can find more detailed information in the Resources section of this article.

Scene descriptions in VRML are made up of entities called nodes. Nodes can be shapes, properties, transformations, cameras, and lights. Nodes can also be clusters of other nodes, as we'll see a bit later.

A VRML description isn't just a haphazard collection of nodes; rather, the nodes are organized hierarchically in a structure called a scene graph. A VRML description consists of a single top-level node. That top-level node may contain other nodes, called children, as illustrated in the diagram below.

A hierarchy of nodes

In this case, the top-level node is A, and nodes B, C, and F are its children. We can rearrange the figure to indicate containment, with descending line segments between adjacent nodes. This top-down arrangement is illustrated below.

A node graph

The nodes that make up a scene graph are ordered -- a fact that has important implications during processing. Take a look at Traversing a node graph. The dotted line indicates the order in which nodes are processed, or traversed. Note that nodes E and G will be affected by the transformations indicated by nodes B and D. This order may seem odd because node D is in a different subtree than node G, but it is important to realize that nodes processed earlier affect nodes processed later no matter what subtree of the scene graph they are in. If node D defines a rotation, that rotation will be applied to all subsequent nodes, including both node E and G.

  • Print
  • Feedback

Resources
  • The VRML 1.0 specification http://www.3dsite.com/cgi/arch-VRML/VRML_1.0_Specification.txt
  • Yahoo provides a convenient way to start your search on 3D graphics http://www.yahoo.com/Computers_and_Internet/Graphics/3D/
  • 3DSite offers a little bit of everything related to 3D graphics http://www.3dsite.com/3dsite/
  • Washington University's graphics software archive is full of source code and tools http://wuarchive.wustl.edu/graphics/graphics/
  • Silicon Graphics' vrml.sgi.com really helped get the ball rolling for this project http://vrml.sgi.com/intro.html
  • Download this article and the complete source code as a gzipped tar file /javaworld/jw-08-1997/howto/jw-08-howto.tar.gz
  • Download this article and the complete source code as a zip file /javaworld/jw-08-1997/howto/jw-08-howto.zip
  • Previous How-To Java articles