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 2, Advanced Java 3D

Learn more about Java 3D performance, 3D content loaders, and the Java 3D VRML97 browser

  • Print
  • Feedback

Page 4 of 6

This is the simplest possible case, however, and won't handle some of the details we would normally want to deal with (things like crease angles, which help the runtime determine how to render a scene). For a more robust OBJ loader application, we can turn to Sun's Java 3D demo app, ObjLoad. ObjLoad deals with crease angles and all the other details, sets a default background color, and provides a more mature interface to load and examine OBJ content. This demo is a good example of how Java 3D applications can take advantage of Sun's support for loaders.

cube.obj loaded in Sun's ObjLoad application

Loading more complicated scenes than cube.obj is then a simple matter of specifying the particular filename in your code or command-line parameters. Because of their ease of use coupled with their flexibility in design and implementation, loaders greatly increase the usefulness of Java 3D by increasing interoperability with other applications and runtimes.

VRML97 meets Java 3D

For Web-based 3D graphics, the standard to interoperate with is VRML. There has been a lot of discussion (which will likely continue) of how and where Java 3D competes with VRML. How do the two compare?

Java 3D will not replace VRML. In fact, the two are largely complementary. VRML is predominantly a file format for 3D data for the Web, while Java 3D is predominantly a 3D graphics runtime system. In fact, just like OBJ, DXF, and other loaders mentioned above, VRML loaders already exist to load a VRML scene from a file into a Java 3D runtime.

Java 3D is a runtime programming API, first and foremost. For a realistic and complicated 3D world, however, you probably want to build your geometry and models (or have someone else build them) using modeling programs. For this purpose, VRML is a decent choice.

Authoring programs from companies like Platinum Technologies help you create VRML content with thousands of nodes, then you can load that content into the Java 3D runtime using one of the various loaders available for free on the Web (listed in the Loaders Archive).

As noted previously, VRML is certainly not the only choice for content. But it is a good one: it is now an ISO standard (see the VRML97 standard listing in Resources) and it was designed with the Web in mind, so it's fairly compact and browser-friendly. If you deploy Java 3D apps that load VRML content, you can readily repurpose your content for Web sites.

In addition, the Java 3D and VRML working group (see Resources for a link) is building a VRML97-compliant browser in Java using the Java 3D API. The browser is a free, open-source browser, meant, in part, to illustrate how to build large and interesting applications using Java 3D. Sun's Java 3D team is heavily involved in the project: One of the cochairs of the working group is Henry Sowizral, Sun's lead for Java 3D API and implementation engineering.

If you would like take the Java 3D VRML97 browser out for a spin, you'll need one of the following (in addition to setting up your system for Java 3D as we discussed last month):

  • Print
  • Feedback

Resources
  • Sun has made its "Java 3D 1.1 Performance Guide" available on its product site. This guide provides some short tips and tricks developers can heed to speed up their Java 3D applications. http://www.sun.com/desktop/java3d/collateral/j3d_perfguide.html
  • The home page for the Java 3D and VRML working group provides links to download the Java 3D VRML browser. http://www.vrml.org/WorkingGroups/vrml-java3d/
  • You can download the Java 3D VRML97 browser from the Java Developer Connection (free registration required). http://developer.java.sun.com/developer/earlyAccess/java3D/index.html
  • VRML97 is an international standard, officially designated ISO/IEC 14772-1:1997. The complete standard specification is available from the VRML Consortium Web site. http://www.vrml.org/Specifications/VRML97/
  • Get information on Transform3D with the API spec and documentation. API specification
    javadocs
  • If you need more information on how transforms are actually applied using matrix mathematics, I recommend the classic computer graphics primer "Introduction to Computer Graphics" (Addison-Wesley, ISBN0201609215). http://www1.clbooks.com/asp/bookinfo/bookinfo.asp?theisbn=0201609215
  • The Java 3D Archive links to loaders and shapes for use with Java 3D. You can use Java 3D loader software to read in models from common 3D file formats and translate them into a scene graph that the Java 3D runtime can render. The archive was assembled through the efforts of Matt Robinson, who has since passed its maintenance on to me. http://reality.sgi.com/bday/Java3DArchives/index.html
  • NCSA's Portfolio provides a consistent interface for loading many popular 3D modeling formats into the Java 3D runtime. It also supports domain-specific loaders for formats such as Protein Data Bank (PDB). Portfolio provides an implementation of Canvas3D, which is able to save snapshots into JPEG files. These files can then be used to make MPEG movies of Java 3D worlds. http://havefun.ncsa.uiuc.edu/Java3D/portfolio/
  • For more on the Java 3D API performance-oriented features, see "Introduction to Programming with Java 3D." http://www.sdsc.edu/~nadeau/Courses/SDSCjava3d/
  • JavaWorld has published several good VRML-related articles. In addition to the two below, be sure to visit the JavaWorld Topical Index for more VRML-related information.
  • "3D computer graphicsGetting the hang of VRML"
  • "Why Java and VRML?"
  • http://www.javaworld.com/topicalindex/jw-ti-vrml.html
  • The Java 3D mailing list archive stores lots of useful tips and tricks. Please search here before posting new questions to the list. http://java.sun.com/products/java-media/mail-archive/3D/index.html
  • Allen McPherson has made some example code available to help in the visual debugging of normal problems. http://java.sun.com/products/java-media/mail-archive/3D/1860.html
  • Learn how to get the frame rate from the Java 3D rendering engine. http://java.sun.com/products/java-media/mail-archive/3D/0093.html
  • Tips on coaxing Java 3D applets to run inside your Web browser. Includes step-by-step instructions for installing and configuring the Java 2 platform (formerly Java 1.2) and Java 3D to work with Netscape's browser. http://java.sun.com/products/java-media/mail-archive/3D/1212.html
  • Need to know the bounding volumes used by the Java 3D VRML97 browser? Try this sample code. http://java.sun.com/products/java-media/mail-archive/3D/1063.html
  • Read about an interesting real-world use of Java 3D and VRML, Nearlife's Virtual Fishtank. The article contains a special sidebar on Java 3D and the fishtank. http://java.sun.com/features/1998/11/fishtank.html
  • Download source code and classes for this column. http://www.javaworld.com/jw-01-1999/media/jw-01-media.jar
  • I've archived Media Programming resources on my Web site. This archive contains the up-to-date media.jar file with code fixes for all the examples in the column. http://reality.sgi.com/bday/Work/index.html
  • Read all my previous Media Programming columns. http://www.javaworld.com/topicalindex/jw-ti-media.html