Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Java 3D: The New Kid on the Block


Virtual Worlds | Java 3D: The New Kid on the Block (Web Techniques, Oct 1997)

As programming languages go, Java is easy to learn and use, but its application programming interfaces (APIs) provide even easier access to its features. One API group, the Java Media and Communications APIs, provides an interface for creating applications involving graphics, telephony, media players and capture, and conferencing. Here, I'll focus on the Java 3D API, which provides higher-than-Java-level constructs for creating, manipulating, and rendering 3D geometry. These constructs allow you to write applications that create and manipulate virtual worlds more easily and quickly than possible with Java itself. Java 3D draws from and synthesizes the best concepts of the following 3D technologies: (Also see " Online".)

  • Direct3D, the realtime 3D graphics component of Microsoft's DirectX 2 interactive media technologies supported in Windows 95.
  • OpenGL, the software interface from Silicon Graphics used for creating applications that generate interactive 2D and 3D computer graphics.
  • QuickDraw 3D, Apple's API for creating and rendering workstation-class, 3D graphics in real time.
  • XGL, Sun's 2D and 3D graphics library for creating animation, simulation, modeling, and geographic-information applications.

Java 3D uses these low-level, platform-specific, 3D graphics libraries and APIs for high-performance rendering and other tasks where performance can be improved through platform-dependent programming calls.

Java 3D delivers on Java's "write once, run anywhere" promise and is also somewhat extensible. Although optimization constraints dictate that most methods be declared "final" and not extensible (they cannot be overridden), programmers can use their own rendering code rather than Java 3D's renderer. Furthermore, implementing dynamics and behaviors requires that you extend the Behavior object and override its methods with your own Java code.

The Java 3D Scene Graph

Java 3D uses a scene graph as its internal representation of a virtual world, the objects in the world, their attributes and relationships to one another, viewpoint data, and so on.

The scene graph is an upside-down tree view of the object hierarchy, starting with the Virtual Universe (the root of the scene graph), and progressing down through the branches to the leaves. The objects are called "nodes" (bits of scene information).

A node lower in the scene-graph hierarchy is a child of the object directly above it (the "parent"). Children have one parent, and parents can have zero, one, or many children.

Java 3D nodes are either Group nodes or Leaf nodes. Group nodes group together one or more child nodes and, like any child node, can have only one parent. They can also have zero, one, or many children. Leaf nodes describe the geometry and attributes of the objects in the scene: shapes, fog, sound, lighting, and so on. Leaf nodes have one parent and no children.

When to Use Java 3D

The applicability of Java 3D will depend on the virtual environment, the available resources, and the interactivity level of a given project. According to Sun, Java 3D applications can include objects created with different systems (CAD, for instance), as long as the other system's external file format can be read and translated to Java 3D primitives. For example, VRML loaders can read and translate VRML code into Java 3D objects and Java code.

It may be argued that, coupled with its scripting interface (the Script node), VRML can accomplish nearly anything possible with Java 3D. Before you choose Java 3D, VRML, or another similar technology, consider the following issues:

Performance. One way to achieve high performance is to optimize with special hardware-specific tricks; alternatively, you can use Java 3D. Although Sun specifies that the API was not designed specifically for game developers, Java 3D can provide the performance necessary for many game applications. A Java 3D application is a single, dynamic entity, so performance should be considerably better for most applications than it would be within a VRML world manipulated from an external program or script via the Script node.

However, the highest-possible performance is still generally achieved using lower-level programming languages and low-level, hardware-specific optimizations that access platform-dependent 3D libraries and APIs.

It's important to note that using platform-specific optimization precludes most opportunities for a Web-based application.

Platform independence. VRML and Java 3D are both platform independent. VRML worlds can be viewed on any system for which there is a VRML browser, while Java 3D is designed to take advantage of any native, low-level API available on the end-user's system and optimize for a wide range of 3D-capable hardware and software platforms. In fact, Java 3D's rendering capabilities use these underlying, hardware-specific APIs for rendering.

Level of interactivity. For simple worlds with a fairly low level of interactivity, VRML will probably suffice.

However, for highly interactive virtual environments that require changes based on complex user interaction, Java 3D will likely be simpler and more elegant. Because it is an API, you develop an application to create and manipulate your virtual environment. Although complex, interactive environments can be created with VRML as well, authoring those environments requires Java or JavaScript applications or scripts that may be more difficult to develop than a Java 3D application. It's worth investigating the Java 3D specification for the details of the API to determine which approach makes most sense for your application.

Project resources. As it gains in popularity, programmers will likely write and make available bits and pieces of code that a less-technical 3D artist, content developer, or multimedia author can cobble together to create a virtual environment. At this point, however, Java 3D is definitely for programmers.

Java 3D Features

Java 3D offers many features familiar to VRML aficionados: grouping, positioning, rotating, scaling, lighting, sound, fog, backgrounds, primitive shapes (implemented differently than in VRML), and concepts of appearance, material, textures, and bounding boxes.

Sun's technology further offers coplanar objects, objects built in order based on indexed lists, an ambient-light object, built-in morphing capability, and the ability to specify image depth and 3D textures.

Java 3D also includes an extensive set of math classes that it uses internally, which can be used by developers as well. The math objects include: vector objects used to store colors, texture coordinates, vertices, and so on; matrix objects, which define a complete three-by-three or four-by-four floating-point transform matrix; and quaternion objects, which store four-component x, y, z, and w coordinates.

Java 3D also provides a view model somewhat different from many 3D technologies. It enables you to write an application that can not only be run anywhere, but can also be viewed with many different devices: computer displays, head-mounted displays and other six-degrees-of-freedom devices, multiple-projection displays, and so on. The Java 3D view model enables a distinction between how an application transforms a viewpoint (called a ViewPlatform in Java 3D), and how the renderer draws or builds that view from the viewpoint's position and orientation. You supply the viewpoint's position and orientation; Java 3D controls what to render based on that information.

Other 3D Technologies

Within any given technology, you're likely to see various uses and implementations depending upon the implementer. In addition to the technologies discussed here, you may want to read about and keep an eye on Cosmo3D, SGI's platform-independent graphics toolkit for high-performance, realtime 3D Internet and desktop applications. Cosmo3D supports many graphics file formats, including VRML, and is accessible to Java applications via Java bindings implemented with the C++-based library.

The Future of 3D on the Web

One potential feature of VRML 3.0'an effort that will probably begin in 1998'is inherent collaboration. I asked JavaSoft's Henry Sowizral, senior engineer working on the Java 3D API, and Vicki Shipkowitz, senior product manager, why Java 3D does not include support for multiuser and collaborative virtual environments. Their answers raise issues I suspect few of us have considered.

In fact, they are poised to add such support, but they are waiting for the social rules to be worked out, because multiuser and collaborative virtual environments require more than technological support. For example, if you bring an item'say, a book'into a virtual world, put it down, and leave the world, does the book remain in that world or does it leave with you? If it remains, as it would in the real world, when, if ever, is it removed, and by whom? If your virtual mother doesn't frequent your cyberspace haunts, who will clean up after you?


Andrea is co-author of The VRML 2.0 Sourcebook, second edition (John Wiley & Sons, 1997) with David R. Nadeau and John L. Moreland. She is a Junior Fellow of the San Diego Supercomputer Center and principal technical writer at Informix Software. You can visit her Web page at www.sdsc.edu/~andrea/ or email her at [email protected].


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.