Contents Previous Next

Java 3D API Specification


A P P E N D I X F

VRML Support




THIS appendix is designed to help VRML browser developers design a VRML browser and runtime environment using the Java 3D API. Sun has already prototyped a VRML 1.0 and VRML 2.0 3D-only browser. This browser has limited browsing functionality but includes the ability to load worlds, navigate, and pick.

VRML files come in one of two formats: VRML 1.0 and VRML 2.0. These two file formats are sufficiently different that developers will most likely support them separately. In general, VRML 1.0 files allow the definition of static geometry, predefined "viewpoints," linking to other worlds, and some simple browser-specific semantics (pick to transport, menu to change viewpoint). The newer VRML 2.0 file format provides an improved facility for defining static geometry and includes support for representing a broader range of information, such as active components and sound.

A developer can use Java 3D functionality to build a VRML loader and browser much as he or she would use C and OpenGL to write a VRML loader and associated browser. The combination of Java and the Java 3D API-like the combination of C and the OpenGL API-provides programmers with sufficient functionality to write complete applications. The Java-based approach additionally allows the development of complete applets.

F.1 VRML 1.0

VRML 1.0 files describe geometry, the material properties associated with that geometry, and the placement of that geometry with respect to other geometry, all within a single virtual world. The file format also includes other properties such as lights, attach points (via cameras), and links to other files.

VRML 1.0 files also assume the existence of a browser and, over time, there have been some default browser semantics that have become a de facto standard. Specifically these include browser-constructed menus, gleaned from the VRML 1.0 file, that allow an end user to choose among a predefined set of viewpoints, browser controls that allow an end user to navigate within the virtual world, and mouse-based pick operations that allow an end user to gain access to other worlds.

F.1.1 Mapping VRML 1.0 Files onto Java 3D Objects

VRML 1.0 files do not map directly onto Java 3D objects. However, Java 3D objects support the complete functionality needed to support VRML 1.0 files. Thus, a developer can write a simple loader to parse a VRML 1.0 file, construct a Java 3D scene graph that represents the information contained in the VRML file, and let Java 3D render the scene. Unfortunately, this does not address the browser issue.

F.1.2 A VRML 1.0 Browsing Environment

VRML 1.0 browsers allow end users to navigate within a VRML world, to "pick" objects by using their mouse, to choose among viewpoints defined within the scene graph via menus, and perform other housekeeping tasks (such as loading a world).

By using Java, specifically Java's AWT package, developers can construct windows, menus, and buttons that allow end-user access to developer-written functionality. A developer would build a browser that would interface with the VRML 1.0 loader to load a VRML world and retrieve references to relevant scene graph information. The browser would interface with the Java 3D API to draw the world, to change viewpoints, to process pick operations, and to navigate within the world.

F.2 VRML 2.0

The VRML 2.0 file format allows the description of geometry, material properties, and object placement, but in an easier manner than the VRML 1.0 file format. In addition, the VRML 2.0 file format includes mechanisms for describing sensors, routes and fields, script nodes, interpolators, support for collision detection, and support for picking.

A similar approach to the one used for VRML 1.0 would have worked (a loader/browser combination) had there not been sensors, routes, fields, and script nodes. These new features require a different approach since information flow within a VRML 2.0 file is specified via routes: Java 3D does not include a similar structure.

F.2.1 VRML Support Requires a VRML Runtime Environment

VRML 2.0 files contain both geometry and behavior components. VRML 2.0 geometry components map straightforwardly onto Java 3D objects. VRML 2.0 behaviors (routes and scripting nodes), however, do not map directory onto Java 3D behaviors. The behaviors in a VRML 2.0 scene could be mapped onto a set of Java 3D classes that mimic the scene's functionality, but, unfortunately, this does not work in all cases. VRML 2.0's runtime semantics, specifically the ability to retarget routes to other fields and the ability to access all the descendants of a referenced VRML 2.0 object, require that the same structure that is specified in the VRML 2.0 file exists within the runtime environment.

Another problem area involves script nodes based on languages other than Java. We do not anticipate developers defining interpreters for other languages that run within the Java environment. We expect that developers will support only Java-based script nodes.

This mismatch between VRML 2.0 and Java 3D is bidirectional: There are Java 3D constructs and behaviors that do not map directly onto the VRML 2.0 file format.

F.2.2 An Approach

Developers can host a VRML 2.0 file within a Java 3D environment by constructing exactly the same scene graph structure as specified in a VRML 2.0 file. They can then use the Java 3D behavior system or its mixed-mode callback features to implement field value propagation. The remainder of this section defines one such approach.

F.2.2.1 The Scene Graph Structure

A developer defines a series of thin-layer Java objects that correspond to VRML 2.0 node types. These thin-layer objects contain references to a set of Java objects that represent VRML field objects and references to underlying Java 3D objects that implement the functionality of the VRML node. These objects also include code to propagate field value changes to their underlying Java 3D objects. Thus, a VRML 2.0 scene graph is represented as a thin layer of Java objects, associated Java 3D objects, and methods that manipulate the Java 3D scene graph whenever field values change in the thin-layer object.

The thin-layer objects (VRML nodes) exist only to translate VRML semantics into appropriate actions at runtime. If a VRML scene has subgraphs that cannot be accessed during runtime (because no routes connect into nodes within that subgraph) then the developer may choose not to retain-or even create-these thin-layer VRML node objects, constructing only the underlying Java 3D objects.

F.2.2.2 The Execution Environment

The developer of a VRML 2.0 runtime environment must also include code to propagate events along the routes specified in a VRML file. Either user interactions or VRML sensors, such as timers, can generate events that change field values. When a field's value changes, the thin-layer VRML node object that contains the field first updates its underlying Java 3D object(s), and then updates the field's associated output fields with the new value. The VRML runtime code then propagates the new output field values, through routes, to other fields. The resulting event cascade moves through the VRML route structure, resulting in an updated Java 3D scene graph.

The developer must somehow integrate event generation into the Java 3D execution environment. This can be done using the Java 3D behavior mechanism to generate events. For example, a WakeupOnElapsedTime or WakeupOnElapsedFrames wakeup criteria can trigger a VRML TimeSensor event, and a mouse-button WakeupOnAWTEvent wakeup criteria can trigger a VRML TouchSensor event. Other VRML sensors can be implemented in a similar manner.

F.2.3 A Browser

Much like implementing a VRML 1.0 browser, a developer can implement a VRML 2.0 browser using Java. A VRML 2.0 browser includes specific functionality, such as Viewpoint binding and a browser interface for use by Script nodes. Most of this latter functionality involves interaction with the thin-layer VRML node objects, but the browser may call Java 3D directly as well. For example, a VRML browser developer can implement VRML Viewpoints by associating Java 3D ViewPlatform nodes with each VRML Viewpoint. Then, to change VRML Viewpoints, the browser would detach the Java 3D View object from the current Java 3D ViewPlatform object and reattach it to the new Java 3D ViewPlatform object associated with the desired VRML Viewpoint.

F.2.4 Optimizing for Viewing versus Editing

A VRML browser need not provide access to the complete VRML 2.0 scene graph and, indeed, a developer can take advantage of this to minimize the number of thin-layer VRML 2.0 objects. If there is no way to reference a VRML 2.0 node, then its thin-layer object need not exist.

An environment that allows editing must keep the entire thin-layer-object scene graph in memory.

In either the viewing-only or the editing case, a developer can straightforwardly write a VRML 2.0 file to disk by traversing the thin-layer-object representation of the scene graph.



Contents Previous Next

Java 3D API Specification


Copyright © 1998, Sun Microsystems, Inc. All rights reserved.