|
j3d.org Code | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.j3d.texture.procedural.TextureGenerator
public class TextureGenerator
Various utility methods for creating textures from procedural means.
An example usage of this code is:
int width = 256; int depth = 256; int passes = 5; float scale = 8; float freq = 4; float y_scale = 0.4f; float freq_diff = 6; float[] raw_img = new float[width * depth]; imageGen.generateSynthesisTexture(raw_img, freq, scale, width, depth); for(int i = 1; i < passes; i++) { freq += freq_diff; scale *= y_scale; imageGen.generateSynthesisTexture(raw_img, freq, scale, width, depth); } // find min and max values of the floats float min_y = raw_img[0]; float max_y = raw_img[0]; for(int i = 0; i < width * depth; i++) { if(raw_img[i] > max_y) max_y = raw_img[i]; else if(raw_img[i] < min_y) min_y = raw_img[i]; } byte[] pixels = new byte[width * depth]; float diff = 1 / (max_y - min_y); for(int i = 0; i < width * depth; i++) pixels[i] = (byte)(((raw_img[i] - min_y) * diff) * 255); WritableRaster raster = Raster.createPackedRaster(DataBuffer.TYPE_BYTE, width, depth, 1, 8, null); raster.setDataElements(0, 0, width, depth, pixels); BufferedImage img = new BufferedImage(width, depth, BufferedImage.TYPE_BYTE_GRAY); img.setData(raster);
Constructor Summary | |
---|---|
TextureGenerator()
Create a new instance of this generator with default values set. |
Method Summary | |
---|---|
byte[] |
generateMixedTerrainTexture(byte[] outputImage,
float[][] heightMap,
java.awt.image.BufferedImage[] colorTextures,
float[] textureHeight,
int numColorTextures)
From the given height map and input textures, generate a single mixed RGB texture that can be drapped over the terrain. |
byte[] |
generateMixedTerrainTexture(byte[] outputImage,
float[] heightMap,
int width,
int height,
java.awt.image.BufferedImage[] colorTextures,
float[] textureHeight,
int numColorTextures)
From the given height map and input textures, generate a single mixed RGB texture that can be drapped over the terrain. |
int[] |
generateMixedTerrainTexture(int[] outputImage,
float[][] heightMap,
java.awt.image.BufferedImage[] colorTextures,
float[] textureHeight,
int numColorTextures)
From the given height map and input textures, generate a single mixed RGB texture that can be drapped over the terrain. |
int[] |
generateMixedTerrainTexture(int[] outputImage,
float[] heightMap,
int width,
int height,
java.awt.image.BufferedImage[] colorTextures,
float[] textureHeight,
int numColorTextures)
From the given height map and input textures, generate a single mixed RGB texture that can be drapped over the terrain. |
float[] |
generateSynthesisTexture(float[] outputImage,
float freq,
float zScale,
int width,
int height)
Generate a texture using spectral synthesis techniques into a height field of floats. |
void |
setRandomSeed(long seed)
Reset the random number generator using the new seed value. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TextureGenerator()
Method Detail |
---|
public void setRandomSeed(long seed)
seed
- The new seed value to usepublic float[] generateSynthesisTexture(float[] outputImage, float freq, float zScale, int width, int height)
outputImage
- An optional array to write the output values tofreq
- The number of passes to add to the imagezScale
- A scaling factor for the heights (0, 1]width
- The width in pixels for the output imageheight
- The height in pixels for the output image
public int[] generateMixedTerrainTexture(int[] outputImage, float[] heightMap, int width, int height, java.awt.image.BufferedImage[] colorTextures, float[] textureHeight, int numColorTextures)
FractalTerrainGenerator
.
There must be at least one more textureHeight
than there is
numColorTextures
. Each index in the array represents where
the texture for that index is blended at 0%. The last value indicates
where the highest texture is blended at 100%.
Height values must be monotonically increasing.
The height colour textures are not required to be the same size as the height map. If they are not, then the pixels are retrieved using a wrapping function.
heightMap
- The list of heights in [height][width] ordercolorTextures
- Images to read color values from for mixingtextureHeight
- List of heights that each texture applies tonumColorTextures
- The number of textures to use in heights
public byte[] generateMixedTerrainTexture(byte[] outputImage, float[] heightMap, int width, int height, java.awt.image.BufferedImage[] colorTextures, float[] textureHeight, int numColorTextures)
FractalTerrainGenerator
.
There must be at least one more textureHeight
than there is
numColorTextures
. Each index in the array represents where
the texture for that index is blended at 0%. The last value indicates
where the highest texture is blended at 100%.
Height values must be monotonically increasing.
The height colour textures are not required to be the same size as the height map. If they are not, then the pixels are retrieved using a wrapping function.
heightMap
- The list of heights in [height][width] ordercolorTextures
- Images to read color values from for mixingtextureHeight
- List of heights that each texture applies tonumColorTextures
- The number of textures to use in heights
public int[] generateMixedTerrainTexture(int[] outputImage, float[][] heightMap, java.awt.image.BufferedImage[] colorTextures, float[] textureHeight, int numColorTextures)
FractalTerrainGenerator
.
There must be at least one more textureHeight
than there is
numColorTextures
. Each index in the array represents where
the texture for that index is blended at 0%. The last value indicates
where the highest texture is blended at 100%.
Height values must be monotonically increasing
heightMap
- The list of heights in [height][width] ordercolorTextures
- Images to read color values from for mixingtextureHeight
- List of heights that each texture applies tonumColorTextures
- The number of textures to use in heights
public byte[] generateMixedTerrainTexture(byte[] outputImage, float[][] heightMap, java.awt.image.BufferedImage[] colorTextures, float[] textureHeight, int numColorTextures)
FractalTerrainGenerator
.
There must be at least one more textureHeight
than there is
numColorTextures
. Each index in the array represents where
the texture for that index is blended at 0%. The last value indicates
where the highest texture is blended at 100%.
Height values must be monotonically increasing
heightMap
- The list of heights in [height][width] ordercolorTextures
- Images to read color values from for mixingtextureHeight
- List of heights that each texture applies tonumColorTextures
- The number of textures to use in heights
|
j3d.org Code | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |