Howdy all,
I've been using this list for a while and I wanted to contribute
something back to it. I've recently undertaken a project to try and load
some VRML models into my Java3D application. As part of this I sought to
use the XJ3D VRML97 loader. The FAQ was helpful, but a little out of
date, so I wanted to present what I did to get the loader running
here. If you're reading this and realize I've made and error, or wish to
contribute additional information, fell free.
There are a couple of ways to get VRML content into your Java3D
application. The simplest way, I feel, is to find a loader that conforms
to Sun's com.sun.j3d.loaders.Loader interface. I know of 3 such loaders
and this description focuses on the XJ3D loader.
1) Obtain the appropriate jar files.
You can find all of the files you need off of the XJ3D site.
http://www.web3d.org/TaskGroups/source/xj3d.html
Since I already have JDK1.4 and Java3D 1.3 I just downloaded the
smaller version. I got the tar ball even though I use a windows system
because all I wanted were the applicable jar files for VRML loading, not
the entire application. You can get them through the .exe file as well,
but there was an installation process involved and I didn't want to
install any applications, just get the tar files. The link I used to the
tar ball is here:
http://www.web3d.org/TaskGroups/source/Xj3D-unix-M5.tar.gz
I spent a long time determining which of the distributions jar files
that came with I needed, and I provided that list below. However,
if you want to be absolutely sure that you get all the functionality you
need to load the specific VRML file you're interested in, put *all*
of the jar files in your classpath. My application already included
all jar files for XML parsing, so I did not need to include them, and
haven't listed them below. Also I thought that in previous versions of
XJ3D there was a conflict with one of Apache's XML parser engines, but
this may have been cleaned up by now.
[If you know what jar files are specifically required just for loading a
VRML97 file please respond to this post, and update this information].
For compilation:
j3d-org.jar
xj3d-j3d.jar
For Running:
xj3d-common.jar
xj3d-render.jar
xj3d-parser.jar
xj3d-runtime.jar
xj3d-script-base.jar
xj3d-core.jar
xj3d-sav.jar
uri.jar
j3d-org.jar
xj3d-j3d.jar
Note: If you do not already have the appropriate jar files for XML
parsing in your project, you will need to include the XJ3D ones.
2) Writing the Code
Once you've found all of the appropriate jars, and included them
in your classpath, its a simple thing to attempt to use the loader. Here
is the code I used:
import all of the appropriate packages for Loader, Scene, BranchGroup etc
I didn't bother importing the Xj3D VRML loader but called it specifically.
[Begin Code Snippet]
Loader myFileLoader = null; //holds the file loader
Scene myVRMLScene = null; //holds the loaded scene
BranchGroup myVRMLModel = null; //BG of the VRML scene
try {
//create an instance of the Loader
myFileLoader = new org.web3d.j3d.loaders.VRML97Loader();
//Load the scene from your VRML97 file
myVRMLScene = myFileLoader.load("YOURFILENAMEHERE.wrl");
//Obtain the root BranchGroup for the Scene
myVRMLModel = myVRMLScene.getSceneGroup();
} catch (Exception e) {
//in case there was a problem, print the stack out
e.printTraceStack();
//we still need a model, even if we can't load the right
//one, I use a color cube just in case
myVRMLModel = new ColorCube();
}
[End Code Snippet]
This code is actually pretty standard for loading anything from a
Loader. Only the names of the loaders tend to change. The Scene
interface provides a lot of functionality to get at different types of
nodes within the VRML content that you loaded (such as lights, etc). I
recommend examining the Java3D API documentation for more info.
3) The Actual VRML File.
XJ3D Handles VRML97 files. It doesn't read
VRML1.0 files. If you need to read a simple VRML1.0 file I recommend the
application vrml1tovrml2 which you can download for free here:
http://synapses.bu.edu/tools/vrml2/vrml1to2.zip
I actually had a bit of difficulty getting some files I thought were
VRML97 compliant loaded via the XJ3D loader. The best experience I
actually had was converting a simple VRML1.0 file to VRML2.0 file using
the above filter and loading that. I urge you to go to the XJ3D project
home page and look at the formats and specific tags that XJ3D supports.
Anyway feel free to use this info as you like. Again, if you know
differently, please correct me. I hope folks find this useful.
Noah Ternullo
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".