Dept.
Computer Science
SUNY Stony Brook
CSE391 Special Topics:
Solid Modeling
Fall, 2004
Prof. George W.
Hart
Notes on Using Java3D
To write a software project which allows 3D objects to dynamically
change
as the program runs, and display them in real time, there are four
logical
approaches you can choose from:
- use openGL and C or C++ (This makes sense if you are
familiar with openGL from taking a graphics course.)
- use
openGL and Java (There is currently no standard binding for this.
GL4Java
or JOGL are two popular but unsupported bindings. Sun and SGI announced
over a year ago that they are working on a new official binding, but I
don't know when it will be available.)
- write your own 3D rendering software (Fun, but distracting from
the main course material, and probably much slower.)
- use Java3D and Java (Discussed here.)
The Java3D approach is the fastest to learn, I believe, so I will
go over this in class. It is also worthwhile because there are other
object-oriented scene graph approaches to 3D modeling that one might
encounter in the future. The disadvantage of this method is that
currently Sun is not doing any further development work on Java3D, so
you will be learning something that is temporarily
a dead language. However, it is likely that Sun will license the code
to
some company that will continue to maintain it (or make it open source)
since there is a large base of Java3D users.
Java3D is installed in the transaction lab machines. Below
is a sample torus generation and display project which you can use as a
project
starting point and to test if you have Java3D installed properly.
To learn about Java3D
The Java3D tutorial is here. Chapter 1 and 2 give all the information
you need for basic purposes.
And here are the JavaDocs:
To install Java3D on your own PC
If you want to set up your own environment for running and developing
with
Java3D, install it (the SDK openGL version) from Sun's pages:
http://java.sun.com/products/java-media/3D/
(Currently this gives ver. 1.3.1 and since development has stopped, it
may always be so...)
This puts these two dll files in the .../jre/bin/
J3D.dll
j3daudio.dll
And puts four jar files in .../jre/lib/ext/
j3daudio.jar
j3dcore.jar
j3dutils.jar
vecmath.jar
The installer seems able to find more than one version of Java to put
these
in (and tells you about them), but it may not find all copies of java,
e.g.,
inside every development environment and browser. So you may also need
to
copy these files yourself if you have multiple Java versions.
To use the Java3D library in a project with JBuilder
To access the jar files in JBuilder, you need to create a "library",
using
Tools|Configure Libraries. Make a new library, name it "J3D-ext" and
browse
to include the four jar files. Then in any project using Java3D,
include
your J3D-ext library in the list of required library paths when
creating
the project. (Or add it afterwards with Project|ProjectProperties
(Paths
tab, then Required Libraries tab, and Add.)
A good test to see if JBuilder is configured and can find everything is
to
make a new project from existing code (File|New|ProjFromExisting) and
point
it to .../demo/java3D/GearTest/ or to run the following demo:
Torus Demo Program
This screen shot shows
the execution of the program described in class for the rotating torus,
to
demonstrate how you can easily display a dynamically changing rotating
3D
object. Here are the files individually:
- J3Dviewer.java (main class, creates
3D viewing window)
- controls.java (frame with control
sliders. mostly JBdesigner output)
- makeTorus.java (methods for creating
torus geometry as array of triangles)
- makeJ3DObj.java (creates a Java3D
object from array of triangles)
- xyz.java (3D vector routines, analogous to
vecmath.jar but leaner)
Here is the whole JBuilder project file for you to play with, packed in
a zip format:
And here is the compiled code packed in an executable jar file:
You should be able to run it from the command prompt by typing:
java -jar <path>/torus.jar