Archives
 
 
 
  Special
 
 
 
  About Us
 
 
 

Newsletter
Free E-mail Newsletter from BYTE.com

 
    
           
Visit the home page Browse the four-year online archive Download platform-neutral CPU/FPU benchmarks Find information for advertisers, authors, vendors, subscribers Request free information on products written about or advertised in BYTE Submit a press release, or scan recent announcements Talk with BYTE's staff and readers about products and technologies

ArticlesVRML and Java


August 1997 / Javatalk / Write Cosmic Code / VRML and Java

The acronym VRML stands for Virtual Reality Modeling Language; it's a language used to describe 3-D worlds for display on a 2-D computer screen. VRML is based on Silicon Graphics' Open Inventor, a library of C++ routines and an associated language syntax for describing 3-D objects.

Actually, it would be more accurate to say that VRML lets you build 3-D scenes. A scene is more than just its component objects. For example, a scene also has a light source and might have a background. (VRML even lets you specify "fog"; the entire scene can be shrouded in haze.) VRML has bee n extended from its roots as a language for describing complex 3-D scenes and now includes features that allow those scenes to support animation.

That VRML Look

A VRML program is nothing more than an ASCII file. (VRML is an interpreter; you don't compile VRML programs.) The fundamental building block of a VRML program is called a "node." In a sense, a node describes a kind of object, but it serves more to aggregate than to encapsulate. A node is composed of fields, which are named entries holding data that describes the characteristics of a node. This is best illustrated by an example:

Cube {
width 20
height 5
depth 3
}

The above node describes a cube object. It contains three fields: width, height, and depth. (VRML reminds me of the NewtonScript language: VRML nodes correspond to NewtonScript frames, while VRML fields correspond to NewtonScript slots.)

VRML nodes are typed; each type of node performs a different function. Shape nodes describe 3-D objects that make up a scene--spheres, cones , cubes, and so forth. (The example above is a shape node.) Property nodes give objects their specific traits--color, texture, size, and so forth. Grouping nodes serve to gather other nodes so that the collection is treated as a single unit.

It's the grouping of nodes that allows the VRML programmer to build complex shapes from simple ones. A robot, for example, would consist of grouped nodes that define its head, torso, arms, and legs. As you might guess, grouping can be nested. Therefore, the robot's arms would in turn consist of grouped nodes defining the upper arm, forearm, and hand; its hand would consist of nodes defining palm and fingers; and so on.

In this way, operations applied to the robot affect the entire robot. If, for example, you wanted the robot to change color, you could apply that operation to the robot node as a single unit rather than painstakingly changing the color for each component shape.

VRML 2.0

VRML 1.0 defined static worlds. It enabled you to create 3-D objects constructed from elementary shapes, as well as define colors, textures, light sources, and so forth. But it was like creating a 3-D still life. Users could "enter" such a 3-D world and roam through it, viewing it from various angles. But what does any of this have to do with Java?

VRML 2.0 has added script nodes, which can contain executable code, and route statements, which send events from node to node. This combination allows programmers to build dynamic VRML worlds. And here is where Java comes in.

Currently, script nodes can include VRMLScript code (which is similar to JavaScript) or JavaScript code, or they can point to Java class files. In the last case, a script node can call a Java method, and--with the help of the VRML 2.0 Java API--the Java code can access nodes and their fields in the VRML world. In short, a programmer can manipulate the VRML world from Java. Java becomes a deus ex machina ("a god from a machine").

Hearkening back to the robot example, not only c an the robot move, but with Java in control, it can move intelligently. The robot can also navigate doorways and halls. It might even chase you.


Author's note: A number of VRML plug-ins are already available on the Internet. I used Silicon Graphics' Cosmo Player, which is available for Windows 95, NT, and Irix running Netscape Navigator 2.0 or higher and Microsoft Internet Explorer 3.0 or higher. Look for it at http://vrml.sgi.com . Also, the VRML 2.0 specification was close to being finalized at the time of this writing. Look for the final specification at http://vag.vrml.org .


Up to the Javatalk section contentsGo to previous article: VRML and JavaSearchSend a comment on this articleSubscribe to BYTE or BYTE on CD-ROM  
Flexible C++
Matthew Wilson
My approach to software engineering is far more pragmatic than it is theoretical--and no language better exemplifies this than C++.

more...

BYTE Digest

BYTE Digest editors every month analyze and evaluate the best articles from Information Week, EE Times, Dr. Dobb's Journal, Network Computing, Sys Admin, and dozens of other CMP publications—bringing you critical news and information about wireless communication, computer security, software development, embedded systems, and more!

Find out more

BYTE.com Store

BYTE CD-ROM
NOW, on one CD-ROM, you can instantly access more than 8 years of BYTE.
 
The Best of BYTE Volume 1: Programming Languages
The Best of BYTE
Volume 1: Programming Languages
In this issue of Best of BYTE, we bring together some of the leading programming language designers and implementors...

Copyright © 2005 CMP Media LLC, Privacy Policy, Your California Privacy rights, Terms of Service
Site comments: webmaster@byte.com
SDMG Web Sites: BYTE.com, C/C++ Users Journal, Dr. Dobb's Journal, MSDN Magazine, New Architect, SD Expo, SD Magazine, Sys Admin, The Perl Journal, UnixReview.com, Windows Developer Network