Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
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
Page 3 of 6
For instance, modifying only the z coordinate of our view platform location from
myViewTransform.setTranslation(new Vector3f(2.0f,0.0f,11.0f));
in Example 4 to
myViewTransform.setTranslation(new Vector3f(2.0f,0.0f,12.0f));
in Example 5, we no longer see the word JavaWorld rotating. Keep this in mind as you develop more complicated and interactive worlds.

Moving our viewing location one unit in the +z direction
moves us out f the bounds, so the text no longer rotates.
We are now outside of the bounding region,
which may or may not be otherwise obvious.
If you were limited to using only content you could manually code into your Java 3D applications, you would either limit yourself to small scene graphs with a few nodes, or relinquish any hope of sleeping ever again. Writing Java 3D code to create complex 3D worlds from scratch is certainly nontrivial. Realizing that such limits aren't good for the success of Java 3D (not to mention your sanity), Sun has made it easy to import from standard 3D file formats into Java 3D using loaders.
Put simply, a loader knows how to read content from a standard 3D file format -- say, for instance, Wavefront's Object file format (OBJ) -- then construct a Java 3D scene from it. There are a variety of loaders available on the Web, including several provided by Sun within the Java 3D release itself. All of them are documented at the Java 3D Loaders archive (see Resources). As of this writing, 17 publicly known Java 3D file loaders are currently available, supporting such common formats as AutoCAD's Drawing Interchange File (DXF), LightWave's Scene Format (LWS) and Object Format (LWO), 3D-Studio's 3DS, and application-specific formats like the Protein Data Bank's PDB.
The world is full of free or commercial archives of 3D content. So, given that loaders and content exist, how do you use them?
Sun has included support for Wavefront's OBJ and LightWave's LightWave 3D file formats built into its implementation of Java 3D. Both formats are fairly prevalent in the modeling and animation community, and both are well specified and understood (again, please refer to the Loaders Archive URL for more information on these formats). I picked the OBJ format to provide a simple example of how to use a loader.
Wavefront OBJ is supported by Sun's com.sun.j3d.utils.loaders.objectfile package. The main class we will use to load and parse the content is ObjectFile, which encapsulates an OBJ file and provides methods to load its content into Java 3D. In the simplest case, we can load
in OBJ content with a few lines of code in a modified constructContentBranch() method, as illustrated in Example 6:
001 /**
002 * constructContentBranch() is where we specify the 3D graphics
003 * content to be rendered. Here we read in a cube using
004 * Sun's OBJ loader, then return this to be rendered. This
005 * cube could be replaced with more complicated content exported
006 * from 3D modeling programs supporting the OBJ format.
007 **/
008 private BranchGroup constructContentBranch() {
009 ObjectFile myOBJ = new ObjectFile();
010 Scene myOBJScene = null;
011
012 //Attempt to load in the OBJ content using ObjectFile.
013 try {
014 myOBJScene = myOBJ.load("cube.obj");
015 } catch (FileNotFoundException e) {
016 System.out.println("Could not open OBJ file...exiting");
017 System.exit(1);
018 }
019
020 //Construct and return branch group containing our OBJ scene.
021 BranchGroup contentBranchGroup = new BranchGroup();
022 contentBranchGroup.addChild(myOBJScene.getSceneGroup());
023 return(contentBranchGroup);
024 }
This method will load in the cube data, build a com.sun.j3d.utils.loaders.Scene from it, and use the scene to return a scene group that can be added to the content branch for rendering.