display | more...

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*:
  1. Create a Canvas3D object
  2. Create a VirtualUniverse object
  3. Create a Locale object, attaching it to the VirtualUniverse object
  4. Construct a view branch graph
    • 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
  5. Construct content branch graph(s)
  6. Compile branch graph(s)
  7. Insert subgraphs into the Locale
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:
  1. Create a Canvas3D Object
  2. Create a SimpleUniverse object which references the earlier Canvas3D object
    • Customize the SimpleUniverse object
  3. Construct content branch
  4. Compile content branch graph
  5. Insert content branch graph into the Locale of the SimpleUniverse

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
    • http://www.javaworld.com/javaworld/jw-01-1999/jw-01-media.html
  • '3D User Interfaces with Java 3D'
    • http://developer.java.sun.com/developer/Books/Java3D/
  • A-Z Index of java.sun.com
    • http://java.sun.com/a-z/?frontpage-AtoZlink_head
    • http://archives.java.sun.com/archives/java3d-interest.html
  • Java3D Community Site
    • http://www.j3d.org/
  • Java 3D FAQ
    • http://www.j3d.org/faq/
  • J3D.ORG Site Listings
    • http://www.j3d.org/sites.html
  • Various Java3D tutorials at J3D.ORG
    • http://www.j3d.org/tutorials/
  • Raw J3D tutorial
    • http://www.j3d.org/tutorials/raw_j3d/
  • Java 3D(TM) API Collateral
    • http://java.sun.com/products/java-media/3D/collateral/
  • Java 3D(TM) API Home Page
    • http://java.sun.com/products/java-media/3D/index.html
  • Java 3D(TM) API In Action -- Application Examples
    • http://java.sun.com/products/java-media/3D/in_action/application.html
  • NCSA Java 3D Home page
    • http://www.ncsa.uiuc.edu/~srp/Java3D/
  • Petros Komodromos - Computing - Java3D
    • http://www.mit.edu/people/petros/java3d_body.html
  • Simple3D
    • http://www.acm.org/crossroads/xrds5-2/ovp52.html
  • Package javax.media.j3d summary
    • http://java.sun.com/products/java-media/3D/forDevelopers/j3dapi/javax/media/j3d/package-summary.html
  • _anim (an animation engine in Java3D)
    • http://zero.monoid.net/projects/_anim/downloads/javadoc/index.html

Node your homework
(re-writing where necessary)

Log in or register to write something here or to contact authors.