time, and as for material and coloring attributes, the inclusion of texturing can be carried
out through an appearance object (Meyer, 2006).
The following four steps are involved for applying textures to a geometry:
Prepare texture image.
Set texture through an appearance object.
Specify texture coordinates.
The preparation of the best texture image is best performed using a good imaging
editing software. However, it should be noted that the sides of the image must be integer
powers of two such as 128 by 256, failing which may result in a runtime exception. Java
3D accepts a variety of picture formats, including gif and jpg.
The loading of the texture image can be done from files or through URLs. Lines 1 and
2 in Figure 1 give an example on how this can be performed. Basically, the first line loads
the file, picture1.gif, to create an ImageComponent2D object, which can then be used by an
appearance object. Note that image loading in Java 3D requires an image observer, which
can be any of the AWT components and is specified in the second argument in line 1. The
image observer is for the purpose of monitoring the image load process and can be queried
on details concerning this process.
In addition to the previous method, the loading of images can also be performed by using
the NewTextureLoader class, which is an extension of the TextureLoader class. This new
class eliminates the need to specify an image observer component every time TextureLoader
is instantiated. Rather, the image observer only needs to be specified once.
Figure 1. Loading texture
TextureLoader loader = new Texture Loader(“picture1.gif”, this);
ImageComponent2D image = loader.getImage();
Texture2D texture = new Texture2D();
Appearance appear = new Appearance();
Search WWH ::