What is Java3D?
Java3D (usually, but not always, spelt without a space) is an add-on API for Java which uses the Java Native Interface (JNI) to access 3D hardware acceleration. There are two distinct but very similar versions available for Windows; one is built on DirectX, the other on OpenGL. Implementations also exist for Linux, Solaris, SGI Irix, HP-UX and AIX.
Java3D is higher-level than OpenGL, being built around scene graphs. It is sometimes described as being lower-level than VRML; both systems give the option of specifying objects either using primitives or vertex by vertex, but Java3D gives the programmer more control over the details of rendering. Graphical performance is typically somewhere between that of a pure OpenGL program and a VRML browser.
Setting up the Scene
The most common approach to creating Java3D scenes is to use the SimpleUniverse utility class provided by Sun. Almost all of the Java3D example programs on the Web use this, although it is not strictly necessary - and in fact it is not part of the core Java3D API, meaning that if anyone besides Sun ever implemented Java3D they would have the option of not including it, although its ubiquity in example programs would make this seem unwise.
To set up a Java3D scene without using the SimpleUniverse class means taking the following steps*:
- Create a Canvas3D object
- Create a VirtualUniverse object
- Create a Locale object, attaching it to the VirtualUniverse object
- Construct a view branch graph
Construct content branch graph(s)
Compile branch graph(s)
Insert subgraphs into the Locale
- Create a View object
- Create a ViewPlatform object
- Create a PhysicalBody object
- Create a PhysicalEnvironment object
- Attach ViewPlatform, PhysicalBody, PhysicalEnvironment, and Canvas3D objects to View object
SimpleUniverse simplifies the procedure by creating the Locale and a complete view branch graph. SimpleUniverse uses 'convenience classes' called Viewer and ViewingPlatform, in place of the core classes View, ViewPlatform and so on, which it uses only indirectly. Using SimpleUniverse, the recipe for creating a Java3D scene becomes:
- Create a Canvas3D Object
- Create a SimpleUniverse object which references the earlier Canvas3D object
Construct content branch
Compile content branch graph
Insert content branch graph into the Locale of the SimpleUniverse
- Customize the SimpleUniverse object
Adding objects, interaction and animation
Various geometric primitives are defined in the com.sun.j3d.utils.geometry package: Box, Cone, Cylinder, and Sphere. More complicated shapes may be built by combining several of these primitives, by defining the geometry on a per-vertex basis using one of the various GeometryArray subclasses, or by using a loader to import models from a 3D modelling package. Sun has designed a standard interface for Java3D model loaders, providing a consistent way for them to be included in Java3D programs; quite a few of these are freely available for download off the net, with support for a wide range of 3D formats. These are extremely useful, but tend not to support all the features of any format being imported.
Interaction and animation in Java3D are generally handled by means of behaviours assigned to objects. Behavior is an abstract class which provides a way for a program to change the scene graph in real time, in response to some stimulus - user input, collisions within the scene or the passing of time, for instance. Many useful sub-classes of Behavior are either built into Java3D or included among the example programs that come with the Java3D distribution; it is easy to add these to your own scenes and to customise them as necessary.
Java3D is a powerful and flexible API, which in various ways is easier to use than the C versions of OpenGL and DirectX; however, the requirement that anybody who wishes to view a Java3D application or applet must have the Java 2 platform installed along with an extension package of several megabytes limits its utility as a way of delivering 3D content on the Web, while the fact that OpenGL and DirectX used with C or C++ are far better-known and both allow for significantly faster programs will tend to make them a more obvious choice for software distributed on CD-Rom. With these disadvantages, and with Java's future looking somewhat doubtful as Microsoft remove Java support from Internet Explorer and incompatibilities between different VMs cause seemingly insurmountable problems for those trying to deliver Java applets to a mass market, Java3D may be set to fizzle and die. On the other hand, it is a fun API to use, capable of achieving many things and supported by a fairly active community of helpful users - so there is at least some hope for it yet.
* From 'Getting Started with the Java 3D API': http://java.sun.com/products/java-media/3D/collateral/
Other helpful Java3D links:
- '3D graphics programming in Java, Advanced Java 3D' - JavaWorld January 1999
- '3D User Interfaces with Java 3D'
- A-Z Index of java.sun.com
- Archives of JAVA3D-INTEREST@JAVA.SUN.COM
- Java3D Community Site
- Java 3D FAQ
- J3D.ORG Site Listings
- Various Java3D tutorials at J3D.ORG
- Raw J3D tutorial
- Java 3D(TM) API Collateral
- Java 3D(TM) API Home Page
- Java 3D(TM) API In Action -- Application Examples
- NCSA Java 3D Home page
- Petros Komodromos - Computing - Java3D
- Package javax.media.j3d summary
- _anim (an animation engine in Java3D)
Node your homework
(re-writing where necessary)