Loaders in Java 3D


An Overview of LoaderInfo3D

The class diagrams for LoaderInfo in Figure 16-3 show only the classes' public methods.

Figure 16-3. Class diagrams for LoaderInfo3D


CheckerFloor and ColouredTile are unchanged from Chapter 15: CheckerFloor creates the floor using ColouredTile objects. LoaderInfo3D is the top-level JFrame for the application and is similar to Checkers3D, except that it takes two arguments from the command line (the name of the file to load and an adaptation number) and passes them to WrapLoaderInfo3D:

     java -cp "%CLASSPATH%;ncsa\portfolio.jar" LoaderInfo3D Coolrobo.3ds 0

This renders the robot model stored in Coolrobo.3ds in blue, as in Figure 16-1. The classpath argument is used to include the loaders package stored in portfolio.jar.

The source code for this example can be found in LoaderInfo3D/ directory.


You may be wondering about the mysterious adaptation number; it's an integer representing the appearance modification that should be applied to the model. The meaning of the integer values are:

0 Makes the shape blue

1 Draws the shape in outline

2 Renders the shape almost transparent

3 Lays a texture over the shape

4 Makes the shape blue and adds a texture


Anything else

Makes no changes at all

WrapLoaderInfo3D creates the scene in a similar way to the WrapCheckers3D class in Chapter 15. I always use a Wrap class to build the scene in the chapters on Java 3D. WrapLoaderInfo3D performs two other tasks: examining the model and modifying the shape according to the user's supplied adaptation number.

The methods for WrapLoaderInfo3D are shown in Figure 16-4, grouped into three categories:


Create Scene methods

These methods build the scene by adding the checkerboard floor, lights, background, and viewer's OrbitBehavior. There are methods for loading the model (loadModel( ) and calcScaleFactor( )).


Examine Model methods

These methods traverse the model's scene graph and save the collected information into a text file. The information is about what shapes are present in the loaded model (a model may be made from multiple shapes), together with geometry and appearance details.

The details are sent to a text file rather than the screen because of the quantity of information generated. Placing it in a text file makes it easier to examine later.



Change Model Shapes methods

These methods traverse the scene graph looking for Shape3D nodes and modify them according to the adaptation number supplied on the command line. Once a shape is found, it's turned blue (makeBlue( )), drawn in outline (drawOutline( )), made almost transparent (makeAlmostTransparent( )), draped with a texture (addTexture( )), or turned blue and given a texture (makeBlue( ) and addTexture( )).

Figure 16-4. WrapLoaderInfo3D methods




Killer Game Programming in Java
Killer Game Programming in Java
ISBN: 0596007302
EAN: 2147483647
Year: 2006
Pages: 340

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net