An Overview of LoaderInfo3D


Chapter 16. Loading and Manipulating External Models

It's possible to build complex geometries in Java 3D by using the GeometryArray class or one of its subclasses (e.g., a QuadArray or TRiangleStripArray). This amounts to calculating 3D coordinates for yourself and ensuring they're ordered correctly inside the geometry objects. This is almost impossible to do manually for anything but the simplest shapes (such as boxes or cones). It makes much more sense to create an object using 3D modeling software and then load that object into your Java 3D application at runtime. I'll refer to objects as external models since their geometry and appearance (e.g., their color and texture) are created outside of Java 3D.

This chapter describes two Java 3D programs that load external models, and then details placing those models into the checkerboard scene (discussed in Chapter 15). This illustrates many of the typical tasks a Java 3D program will perform: analyzing the contents of a model, adjusting its appearance, and repositioning the model in a scene.

LoaderInfo3D.java shows how a loaded object can be examined and its component shapes manipulated to change color, transparency, texture, and other attributes. Figure 16-1 shows two screenshots: the left one a robot with its original colors, the right one the same model after being turned blue.

Loader3D.java, the other application examined in this chapter, shows how a loaded model's position, orientation, and size can be adjusted. This information can be saved to a text file and applied to the model when it's next loaded.

Figure 16-2 shows two screenshots: the one on the left is of a small castle that, when first loaded, is half hidden below the checkered floor. The screenshot on the right is after the castle has been moved, rotated, and scaled. I've moved the viewpoint back a considerable distance so all of the model can be seen.

Figure 16-1. A robot turned blue


Figure 16-2. A repositioned and scaled castle


This chapter will discuss the following Java 3D techniques:


External model loading (using NCSA Portfolio)

Portfolio collects several loaders for different 3D file formats into a single, convenient package.


Shape modification

You'll see five different modifications to a shape's appearance: changing its color, rendering the shape as a wireframe, setting a transparency level, wrapping a texture around it, and modulating (combining) a texture with the shape's color.


Scene graph traversal

This is required by the shape modification code since a shape node has to be found in the graph before its appearance can be changed.


Integrating GUI controls with the Java 3D canvas

This follows on from the brief discussion at the start of Chapter 15 about the care needed in combining Java 3D's Canvas3D class with Swing components. Loader3D uses several Swing components, as shown in Figure 16-2.


Shape positioning, scaling, and rotation

These operations are often required for shapes loaded from external models, which may appear in the Java 3D scene in the wrong position, may be badly orientated, or scaled incorrectly.



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