Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

3D graphics programming in Java, Part 1: Java 3D

Get a head start with this introduction to the Java 3D API

  • Print
  • Feedback
In order to build a true Java platform, Sun realized early on that it needed to fill out the API picture beyond the limited functionality available in the Java 1.0 core platform. Sun has grown the core a great deal with the 1.1 and impending 1.2 releases, but there are still some pieces missing from the Java puzzle.

Sun and its partners developed the Java Media and Communication APIs to provide the missing multimedia programming pieces. Two of the biggest pieces, 2D and 3D graphics, are targeted with the Java 2D and 3D APIs, respectively. Java 2D is a core platform API beginning with Java 1.2, while Java 3D will be released as an Extension API shortly after the 1.2 platform becomes available. We have recently finished a series of columns on Java 2D; now we turn our attention to Java 3D.

Java 3D is meant to give Java developers the ability to write applets and applications that provide three dimensional, interactive content to users. Sun has some heavy competition from other 3D graphics technologies in this arena, and Java 3D has an uphill battle ahead of it if it's to defeat the incumbent graphics standard, OpenGL.

A request for reader comments on 3D graphics APIs for Java indicated serious interest in Java 3D and Java OpenGL bindings, so I've decided to concentrate my efforts on these technologies in the coming months.

A more limited amount of interest was expressed in VRML. Consequently, I am going to deal with VRML by demonstrating its use in Java 3D with VRML97 content loaders and Sun's Java 3D VRML97 browser. Direct3D received very little interest, so I've decided not to pursue this path, except to mention where one of the other technologies may support or interoperate with it.

Pros and cons of Java 3D

This month we begin our tour of 3D graphics APIs for Java by exploring Java 3D. We'll start by discussing some of the API's major strengths and weaknesses. 3D graphics can seem at times rather obtuse and, thus, can be difficult to explain. If you have any lingering confusion about my examples or explanations, please feel free to write me with your questions or comments, and I'll do my best to address them.

Selling points for Java 3D:

  • It provides a high-level, object-oriented view of 3D graphics. Java 3D accomplishes this in part by using a scene graph-based 3D graphics model. (We'll discuss this concept in more detail later in the article.) This approach is intended to help programmers without much graphics or multimedia programming experience use 3D in their applications. In stark contrast to lower-level, procedural 3D APIs like OpenGL, which are designed to optimize for the best possible speed and give programmers the greatest possible control over the rendering process, Java 3D is meant to be straightforward enough for any experienced Java programmer to learn.

  • If you don't need low-level access to rendering operations, Java 3D may be an option. Rendering access is limited to requests via attributes and capability bits, similar in form and function to Java 2D's rendering hints. (See Resources for links to my previous series on Java 2D, which included discussion and examples of 2D's rendering hints).

  • Java 3D is optimized for speed where possible. The runtime uses rendering capability bits, in fact, to optimize the scene graph for the fastest possible renders. This approach makes Java 3D more applicable to interactive graphics environments (games, simulations, low-latency situations) than to offline, high-quality graphics applications (like render farms).

  • A large and growing number of 3D loaders are available to import content into the Java 3D runtime. Sun has made a Java 3D VRML97 file loader and browser freely available with code. Look for next month's Media Programming column to explore Java 3D loaders in more detail.

  • Java 3D requires vector math capabilities not available elsewhere in the Java platform. These math operations are currently located in the javax.vecmath package and may be moved into the core platform in the future.

  • Java 3D supports a number of exotic devices (wands, data gloves, and headsets, for example). The com.sun.j3d.utils.trackers package included with Sun's implementation provides classes for Fakespace, Logitech, and Polhemus devices. These devices are not widely used, however, so I will not discuss them in great detail. If you're interested in finding out more about device support, please refer to Sun's Java 3D sites and the Java 3D mailing list archive (both available from the main Sun Java 3D URLs included in the Resources below).



Java 3D has a lot of pros, but what about the cons? They include:

  • Print
  • Feedback

Resources
  • A good place to start is the Introduction to Programming with Java 3D course tutorial put together by Sun and the San Diego Supercomputer Center. http://www.sdsc.edu/~nadeau/Courses/SDSCjava3d/
  • Sun's Java 3D API page documents the API and its use. It contains javadocs for the API, the mailing list archive, Sun's Java 3D FAQ, and more. http://java.sun.com/products/java-media/3D/
  • The API is specified in Sun's Java 3D API Specification document. http://java.sun.com/products/java-media/3D/forDevelopers/j3dguide/j3dTOC.doc.html
  • The specification is also available in book format from Addison-Wesley's Java Series. Please note that the version of the API this printed specification corresponds to may be somewhat out of date The online specification is always kept up to date for the latest API release. http://www.amazon.com/exec/obidos/ASIN/0201325764/billday/
  • Sun makes its Win32 and Solaris implementations (as opposed to the API specification itself) available from a separate, product Web site. This site also contains the example code for Sun Java 3D training courses, demos from the Java 3D programming contest Sun hosted earlier in 1998, case studies with Sun's Java 3D customers, and lists of Java 3D related papers and Web pages. http://www.sun.com/desktop/java3d/index.html
  • Sun's Java 3D product site links to the course notes for its "Java 3D Roadshow." This is the crash course Sun representatives have been teaching to interested developers around the world in 1998. http://www.sun.com/desktop/java3d/collateral/j3d_clas.pdf
  • The OpenGL Consortium's Web site is the complete resource for OpenGL. http://www.opengl.org/
  • The Java 3D FAQ is maintained by Steve Pietrowicz, a project manager of the Java 3D group at NCSA. It is an excellent third-party resource for Java 3D information. http://tintoy.ncsa.uiuc.edu/~srp/java3d/faq.html
  • Read more about Java 3D's heavyweight components and Sun's thoughts on integrating them with Swing lightweight components. http://java.sun.com/products/java-media/mail-archive/3D/1520.html
  • Follow-up on Sun's plans for Java 3D vis-a-vis lightweight components and Swing. http://java.sun.com/products/java-media/mail-archive/3D/1557.html
  • "Progress on the media front at Siggraph '98" sizes up the state of Java Media in general and Java 3D in particular at this year's premier computer graphics conference. http://www.javaworld.com/javaworld/jw-10-1998/jw-10-media.html
  • Download source code and classes for this column. http://www.javaworld.com/jw-12-1998/media/jw-12-media.jar
  • Bill has archived Media Programming resources on his Web site. This archive contains the up-to-date media.jar file with code fixes for all of the examples in the column. http://reality.sgi.com/bday/Work/index.html
  • Read Bill's previous Media Programming columns. http://www.javaworld.com/topicalindex/jw-ti-media.html