com.jmex.terrain.util
Class ProceduralTextureGenerator

java.lang.Object
  extended by com.jmex.terrain.util.ProceduralTextureGenerator
Direct Known Subclasses:
ProceduralSplatTextureGenerator

public class ProceduralTextureGenerator
extends java.lang.Object

ProceduralTexture generates an ImageIcon using an AbstractHeightMap and one or more ImageIcons as input textures. The final texture is built based on a pixel's current height and the values associated with each input image. When adding an input texture, a low, optimal and high value is given to denote how much of the RGB value to use for a given output pixel. For example, if a texture is added with (0, 10, 20), and a pixel is denoted as having a height of 5 50% of the texture will be used for the output texture. When combining multiple input textures with overlapping values, you can create a smooth blending for the output texture. Currently, the output texture will have the same dimensions as the input heightmap.

Version:
$Id: ProceduralTextureGenerator.java 4133 2009-03-19 20:40:11Z blaine.dev $
Author:
Mark Powell

Field Summary
protected  javax.swing.ImageIcon proceduralTexture
           
protected  int size
           
 
Constructor Summary
ProceduralTextureGenerator(AbstractHeightMap heightMap)
          Constructor instantiates a new ProceduralTexture object initializing the list for textures and the height map.
 
Method Summary
 void addTexture(javax.swing.ImageIcon image, int low, int optimal, int high)
          addTexture adds an additional texture to the list of input textures.
 void clearTextures()
           
 void createTexture(int textureSize)
          createTexture takes the current height map and the current loaded textures and produces an ImageIcon which can be retrieved with a call to getImageIcon.
 javax.swing.ImageIcon getImageIcon()
          getImageIcon retrieves the procedural texture that has been created.
 boolean saveTexture(java.lang.String filename)
          Saves the final texture this class has created to the given filename as a png.
 void setHeightMap(AbstractHeightMap hm)
          setHeightMap sets the input heightmap to use for the texture generation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

proceduralTexture

protected javax.swing.ImageIcon proceduralTexture

size

protected int size
Constructor Detail

ProceduralTextureGenerator

public ProceduralTextureGenerator(AbstractHeightMap heightMap)
Constructor instantiates a new ProceduralTexture object initializing the list for textures and the height map.

Parameters:
heightMap - the height map to use for the texture generation.
Method Detail

createTexture

public void createTexture(int textureSize)
createTexture takes the current height map and the current loaded textures and produces an ImageIcon which can be retrieved with a call to getImageIcon.


saveTexture

public boolean saveTexture(java.lang.String filename)
Saves the final texture this class has created to the given filename as a png. Note that this function will fail if createTexture is not called first.

Parameters:
filename - The filename to save the texture too.
Returns:
False if the texture could not be written.
See Also:
createTexture(int)

addTexture

public void addTexture(javax.swing.ImageIcon image,
                       int low,
                       int optimal,
                       int high)
addTexture adds an additional texture to the list of input textures. Each texture has a low, optimal and high value associated with it. This determines how much of the texture color to use for a particular pixel. Where optimal is 100% of the color, less than low is 0% and higher than high is 0%. For example if the values are (0, 10, 20), and the height is 5, then 50% of the color will be used.

Parameters:
image - the input texture.
low - the low color value for this texture.
optimal - the optimal color value for this texture.
high - the high color value for this texture.

clearTextures

public void clearTextures()

setHeightMap

public void setHeightMap(AbstractHeightMap hm)
setHeightMap sets the input heightmap to use for the texture generation.

Parameters:
hm - the new heightmap.
Throws:
JmeException - if hm is null.

getImageIcon

public javax.swing.ImageIcon getImageIcon()
getImageIcon retrieves the procedural texture that has been created. Note that this will return null until createTexture has been called.

Returns:
the ImageIcon of the output texture.