Package com.jme3.terrain.heightmap
Class AbstractHeightMap
java.lang.Object
com.jme3.terrain.heightmap.AbstractHeightMap
- All Implemented Interfaces:
- HeightMap
- Direct Known Subclasses:
- CombinerHeightMap,- FaultHeightMap,- FluidSimHeightMap,- FractalTileLoader.FloatBufferHeightMap,- HillHeightMap,- ImageBasedHeightMap,- MidpointDisplacementHeightMap,- ParticleDepositionHeightMap,- RawHeightMap
AbstractHeightMap provides a base implementation of height
 data for terrain rendering. The loading of the data is dependent on the
 subclass. The abstract implementation provides a means to retrieve the height
 data and to save it.
 It is the general contract that any subclass provide a means of editing
 required attributes and calling load again to recreate a
 heightfield with these new parameters.- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected floatThe filter is used to erode the terrain.protected float[]Height data information.protected floatAllows scaling the Y height of the map.static floatThe range used to normalize terrainprotected intThe size of the height map's width.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoiderodeTerrainis a convenience method that applies the FIR filter to a given height map.float[]Find the minimum and maximum height values.voidflatten(byte flattening) Flattens out the valleys.float[]getHeightMapreturns the entire grid of height data.floatgetInterpolatedHeight(float x, float z) getInterpolatedHeightreturns the height of a point that does not fall directly on the height posts.floatgetScaledHeightAtPoint(int x, int z) getScaledHeightAtPointreturns the scaled value at the point provided.float[]Build a new array of height data with the scaled values.intgetSize()getSizereturns the size of one side the height map.floatgetTrueHeightAtPoint(int x, int z) getTrueHeightAtPointreturns the non-scaled value at the point provided.voidnormalizeTerrain(float value) normalizeTerraintakes the current terrain data and converts it to values between 0 andvalue.booleansavewill save the heightmap data into a new RAW file denoted by the supplied filename.voidsetHeightAtPoint(float height, int x, int z) setHeightAtPointsets the height value for a given coordinate.voidsetHeightScale(float scale) setHeightScalesets the scale of the height values.voidsetMagnificationFilter(float filter) setFiltersets the erosion value for the filter.voidsetSize(int size) setSizesets the size of the terrain where the area is size x size.voidsmooth(float np) Smooth the terrain.voidsmooth(float np, int radius) Smooth the terrain.voidunloadHeightMapclears the data of the height map.
- 
Field Details- 
heightDataprotected float[] heightDataHeight data information.
- 
sizeprotected int sizeThe size of the height map's width.
- 
heightScaleprotected float heightScaleAllows scaling the Y height of the map.
- 
filterprotected float filterThe filter is used to erode the terrain.
- 
NORMALIZE_RANGEpublic static float NORMALIZE_RANGEThe range used to normalize terrain
 
- 
- 
Constructor Details- 
AbstractHeightMappublic AbstractHeightMap()
 
- 
- 
Method Details- 
unloadHeightMappublic void unloadHeightMap()unloadHeightMapclears the data of the height map. This insures it is ready for reloading.- Specified by:
- unloadHeightMapin interface- HeightMap
 
- 
setHeightScalepublic void setHeightScale(float scale) setHeightScalesets the scale of the height values. Typically, the height is a little too extreme and should be scaled to a smaller value (i.e. 0.25), to produce cleaner slopes.- Specified by:
- setHeightScalein interface- HeightMap
- Parameters:
- scale- the scale to multiply height values by.
 
- 
setHeightAtPointpublic void setHeightAtPoint(float height, int x, int z) setHeightAtPointsets the height value for a given coordinate. It is recommended that the height value be within the 0 - 255 range.- Specified by:
- setHeightAtPointin interface- HeightMap
- Parameters:
- height- the new height for the coordinate.
- x- the x (east/west) coordinate.
- z- the z (north/south) coordinate.
 
- 
setSizesetSizesets the size of the terrain where the area is size x size.
- 
setMagnificationFiltersetFiltersets the erosion value for the filter. This value must be between 0 and 1, where 0.2 - 0.4 produces arguably the best results.- Specified by:
- setMagnificationFilterin interface- HeightMap
- Parameters:
- filter- the erosion value.
- Throws:
- Exception- if filter is less than 0 or greater than 1.
 
- 
getTrueHeightAtPointpublic float getTrueHeightAtPoint(int x, int z) getTrueHeightAtPointreturns the non-scaled value at the point provided.- Specified by:
- getTrueHeightAtPointin interface- HeightMap
- Parameters:
- x- the x (east/west) coordinate.
- z- the z (north/south) coordinate.
- Returns:
- the value at (x,z).
 
- 
getScaledHeightAtPointpublic float getScaledHeightAtPoint(int x, int z) getScaledHeightAtPointreturns the scaled value at the point provided.- Specified by:
- getScaledHeightAtPointin interface- HeightMap
- Parameters:
- x- the x (east/west) coordinate.
- z- the z (north/south) coordinate.
- Returns:
- the scaled value at (x, z).
 
- 
getInterpolatedHeightpublic float getInterpolatedHeight(float x, float z) getInterpolatedHeightreturns the height of a point that does not fall directly on the height posts.- Specified by:
- getInterpolatedHeightin interface- HeightMap
- Parameters:
- x- the x coordinate of the point.
- z- the y coordinate of the point.
- Returns:
- the interpolated height at this point.
 
- 
getHeightMappublic float[] getHeightMap()getHeightMapreturns the entire grid of height data.- Specified by:
- getHeightMapin interface- HeightMap
- Returns:
- the grid of height data.
 
- 
getScaledHeightMappublic float[] getScaledHeightMap()Build a new array of height data with the scaled values.- Specified by:
- getScaledHeightMapin interface- HeightMap
- Returns:
- a new array
 
- 
getSizepublic int getSize()getSizereturns the size of one side the height map. Where the area of the height map is size x size.
- 
savesavewill save the heightmap data into a new RAW file denoted by the supplied filename.- Parameters:
- filename- the file name to save the current data as.
- Returns:
- true if the save was successful, false otherwise.
- Throws:
- Exception- if filename is null.
 
- 
normalizeTerrainpublic void normalizeTerrain(float value) normalizeTerraintakes the current terrain data and converts it to values between 0 andvalue.- Parameters:
- value- the value to normalize to.
 
- 
findMinMaxHeightspublic float[] findMinMaxHeights()Find the minimum and maximum height values.- Returns:
- a float array with two value: min height, max height
 
- 
erodeTerrainpublic void erodeTerrain()erodeTerrainis a convenience method that applies the FIR filter to a given height map. This simulates water erosion.
- 
flattenpublic void flatten(byte flattening) Flattens out the valleys. The flatten algorithm makes the valleys more prominent while keeping the hills mostly intact. This effect is based on what happens when values below one are squared. The terrain will be normalized between 0 and 1 for this function to work.- Parameters:
- flattening- the power of flattening applied, 1 means none
 
- 
smoothpublic void smooth(float np) Smooth the terrain. For each node, its 8 neighbors' heights are averaged and will influence node's new height to the extent specified bynp. You must first load() the heightmap data before this will have any effect.- Parameters:
- np- To what extent neighbors influence the new height: Value of 0 will ignore neighbors (no smoothing). Value of 1 will ignore the node old height.
 
- 
smoothpublic void smooth(float np, int radius) Smooth the terrain. For each node, its X (determined by radius) neighbors' heights are averaged and will influence node's new height to the extent specified bynp. You must first load() the heightmap data before this will have any effect.- Parameters:
- np- To what extent neighbors influence the new height: Value of 0 will ignore neighbors (no smoothing). Value of 1 will ignore the node old height.
 
 
-