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 6 of 6

Finally, unordered rendering allows the Java 3D runtime to pick the optimum rendering path through the scene graph. A great deal of effort has been expended in determining how to optimize rendering speeds when the order of objects to be rendered can be controlled. Sun's Java 3D takes advantage of this previous work to speed things up.

For more information on all of these API performance-oriented features, please refer to Resources.

Compiling Java 3D branch groups

When a developer calls BranchGroup.compile(), Java 3D checks which capability bits are set and compiles those portions of the branch group. That is, it rearranges the applicable portion(s) of the scene graph for optimum rendering performance. The runtime may, in fact, do all sorts of weird things to the geometry and other nodes of the scene graph unbeknownst to you. The net result is that things speed up without your needing to understand all of the "magic" behind the process.

But without some statistics to back it up, this is just cheap talk. I added compile() methods to our previous Java 3D examples to see what effect, if any, they would have. For instance, I added the line


contentBranchGroup.compile();


to Example 4 to generate Example 7.

I did not, however, see any noticeable performance differences in any of the previous examples. All loaded and executed in roughly the same time with and without the compile statement.

I ascribe this to the fact that I do not have very complicated content branches that would allow Java 3D to optimize their performance. If you have more complicated applications of Java 3D, I suggest trying compilation to speed things up. But as always, your mileage may vary.

Loose ends

Java 3D is an interesting technology with a broad scope and an equally broad range of tips and tricks. I have endeavored to provide you with good examples with which to get started exploring the API, but as always, there just isn't enough room or time to go into all the nuances in great enough detail. I have included more information on tips and tricks in the Resources section to help you find your away around this exciting API.

You'll find pointers to:

  • Sample code for visually debugging normal problems in Java 3D;
  • Information on getting the frame rate from the Java 3D rendering engine; and
  • A how-to for running Java 3D applets in Web browsers.


One more thing to note: I've received several questions on the applicability of Java 3D to collaborative world building and interaction. I believe Java 3D to be more than capable of handling 3D rendering tasks for building collaborative virtual worlds. There is no fundamental restriction to building collaborative virtual worlds in Java 3D. In fact, some of Sun's customers are building, demoing, and deploying large scale simulations and collaborative apps using the technology today (see Sun's Java 3D product site for examples of this).

The networking support inherent to the Java platform makes the communication aspects of collaboration easier than many other languages and APIs. You might have difficulties with client-side availability, however, because Java 3D is not installed in browsers or on desktops by default, and it is not currently available beyond Win32 and Solaris. But if your problem domain and customer base allows you to install software onto participating users' systems and to deal with a Win32 and Solaris-only solution, Java 3D is worthy of further investigation.

Conclusions

In this column and the last, we've seen how to create and manipulate Java 3D scene graphs, how to load in content from popular file formats and external programs, and how to use VRML97 and Java 3D together.

Next month, we'll shift our attention from Java 3D and VRML to Java bindings for OpenGL, the current frontrunner in cross-platform graphics APIs. I'll give a quick review of the publicly available Java-OpenGL bindings, then settle in for a discussion of one of the most popular bindings -- and the likely starting point for the OpenGL ARB's Java binding standard -- Magician. As always, if you have questions or ideas for upcoming columns, please let me know.

Until then, happy hacking and merry media. (I know, I know...gratuitous holiday puns are never successful, are they?)

About the author

Bill Day is a software engineer at Silicon Graphics Computer Systems and an ACM Distinguished Lecturer. In addition to writing for JavaWorld, Bill is authoring a book entitled Java Media Players for O'Reilly & Associates. When Bill is not writing or programming, he loves to mountain bike, travel with his wife, and speak French. Java, c'est magnifique!

Read more about Core Java in JavaWorld's Core Java section.

  • 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