Prev: Postscript: Isn't There a Better Way?

12. Appendix: Image Maps

The easiest way to make use of images in your procedures is to use the ImageOrColor and ImageOrValue classes. They provided their own user interface, as well methods for loading and saving themselves to files. In some cases, however, you may prefer to use the ImageMap class directly. In this case, you need to know how to obtain ImageMap objects, and how to reference them when saving and restoring your textures or materials.

The Scene object maintains a master list of all ImageMaps used by any texture or material in the Scene. That way, only a single copy of the image needs to be stored in memory, no matter how many textures there are that use it. The Scene's getImages() method returns a Vector of all the ImageMaps in the Scene.

In general, the best way of obtaining an ImageMap is through the ImagesDialog class. This is a dialog box in which the user can select any currently loaded image, load new images from disk, etc. Its getSelection() method will then return the ImageMap the user has selected.

When saving your texture or material to disk, you should save the index of the ImageMap within the Scene's master list of images: scene.getImages().indexOf(map). When reading it back in from disk, the ImageMap object is given by scene.getImages().elementAt(index).

Whether you use ImageMaps directly or indirectly (through ImageOrColor and ImageOrValue), be sure to implement the usesImage() method, so that the user will not be able to delete an image from the Scene that your texture or material is currently using.

Prev: Postscript: Isn't There a Better Way?