|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jme3.scene.Spatial
com.jme3.scene.Node
com.jme3.terrain.geomipmap.TerrainQuad
com.jme3.terrain.geomipmap.TerrainGrid
public class TerrainGrid
TerrainGrid itself is an actual TerrainQuad. Its four children are the visible four tiles.
The grid is indexed by cells. Each cell has an integer XZ coordinate originating at 0,0. TerrainGrid will piggyback on the TerrainLodControl so it can use the camera for its updates as well. It does this in the overwritten update() method.
It uses an LRU (Least Recently Used) cache of 16 terrain tiles (full TerrainQuadTrees). The center 4 are the ones that are visible. As the camera moves, it checks what camera cell it is in and will attach the now visible tiles.
The 'quadIndex' variable is a 4x4 array that represents the tiles. The center four (index numbers: 5, 6, 9, 10) are what is visible. Each quadIndex value is an offset vector. The vector contains whole numbers and represents how many tiles in offset this location is from the center of the map. So for example the index 11 [Vector3f(2, 0, 1)] is located 2*terrainSize in X axis and 1*terrainSize in Z axis.
As the camera moves, it tests what cameraCell it is in. Each camera cell covers four quad tiles and is half way inside each one.
+-------+-------+ | 1 | 4 | Four terrainQuads that make up the grid | *..|..* | with the cameraCell in the middle, covering |----|--|--|----| all four quads. | *..|..* | | 2 | 3 | +-------+-------+
This results in the effect of when the camera gets half way across one of the sides of a quad to an empty (non-loaded) area, it will trigger the system to load in the next tiles.
The tile loading is done on a background thread, and once the tile is loaded, then it is attached to the qrid quad tree, back on the OGL thread. It will grab the terrain quad from the LRU cache if it exists. If it does not exist, it will load in the new TerrainQuad tile.
The loading of new tiles triggers events for any TerrainGridListeners. The events are:
These allow physics to update, and other operation (often needed for loading the terrain) to occur at the right time.
Nested Class Summary | |
---|---|
protected class |
TerrainGrid.UpdateQuadCache
|
Nested classes/interfaces inherited from class com.jme3.terrain.geomipmap.TerrainQuad |
---|
TerrainQuad.LocationHeight |
Nested classes/interfaces inherited from class com.jme3.scene.Spatial |
---|
Spatial.BatchHint, Spatial.CullHint |
Field Summary | |
---|---|
protected LRUCache<Vector3f,TerrainQuad> |
cache
|
protected java.util.concurrent.ExecutorService |
cacheExecutor
|
protected int |
cellsLoaded
|
protected Vector3f |
currentCamCell
|
protected int[] |
gridOffset
|
protected HeightMapGrid |
heightMapGrid
|
protected java.util.Set<TerrainGridListener> |
listeners
|
protected static java.util.logging.Logger |
log
|
protected Material |
material
|
protected Vector3f[] |
quadIndex
|
protected int |
quadSize
|
protected int |
quarterSize
|
protected boolean |
runOnce
|
Fields inherited from class com.jme3.terrain.geomipmap.TerrainQuad |
---|
neighbourFinder, offset, offsetAmount, patchSize, quadrant, size, stepScale, totalSize |
Fields inherited from class com.jme3.scene.Node |
---|
children |
Fields inherited from class com.jme3.scene.Spatial |
---|
batchHint, controls, cullHint, frustrumIntersects, key, localLights, localTransform, name, parent, queueBucket, queueDistance, refreshFlags, RF_BOUND, RF_LIGHTLIST, RF_TRANSFORM, shadowMode, userData, worldBound, worldLights, worldTransform |
Constructor Summary | |
---|---|
TerrainGrid()
|
|
TerrainGrid(java.lang.String name,
int patchSize,
int maxVisibleSize,
HeightMapGrid heightMapGrid)
Deprecated. |
|
TerrainGrid(java.lang.String name,
int patchSize,
int maxVisibleSize,
TerrainGridTileLoader terrainQuadGrid)
|
|
TerrainGrid(java.lang.String name,
int patchSize,
int maxVisibleSize,
Vector3f scale,
HeightMapGrid heightMapGrid)
Deprecated. |
|
TerrainGrid(java.lang.String name,
int patchSize,
int maxVisibleSize,
Vector3f scale,
HeightMapGrid heightMapGrid,
Vector2f offset,
float offsetAmount)
Deprecated. |
|
TerrainGrid(java.lang.String name,
int patchSize,
int maxVisibleSize,
Vector3f scale,
TerrainGridTileLoader terrainQuadGrid)
|
|
TerrainGrid(java.lang.String name,
int patchSize,
int maxVisibleSize,
Vector3f scale,
TerrainGridTileLoader terrainQuadGrid,
Vector2f offset,
float offsetAmount)
|
Method Summary | |
---|---|
void |
addListener(TerrainGridListener listener)
|
void |
adjustHeight(java.util.List<Vector2f> xz,
java.util.List<java.lang.Float> height)
Raise/lower the height at many points. |
protected void |
attachQuadAt(TerrainQuad q,
int quadrant,
Vector3f quadCell)
Runs on the rendering thread |
protected java.util.concurrent.ExecutorService |
createExecutorService()
|
Vector3f |
getCamCell(Vector3f location)
|
Vector3f |
getCurrentCell()
|
TerrainGridTileLoader |
getGridTileLoader()
|
protected float |
getHeightmapHeight(int x,
int z)
This will just get the heightmap value at the supplied point, not an interpolated (actual) height value. |
Material |
getMaterial(Vector3f worldLocation)
Returns the material that this terrain uses. |
int |
getNumMajorSubdivisions()
|
protected int |
getQuadrant(int quadIndex)
|
Vector3f |
getTileCell(Vector3f location)
Centered at 0,0. |
protected boolean |
isCenter(int quadIndex)
|
void |
read(JmeImporter im)
|
void |
removeListener(TerrainGridListener listener)
|
protected void |
removeQuad(int idx)
|
void |
setMaterial(Material mat)
Applies the given material to the Spatial, this will propagate the material down to the geometries in the scene graph. |
void |
setQuadSize(int quadSize)
|
protected void |
updateChildren(Vector3f camCell)
Called when the camera has moved into a new cell. |
void |
write(JmeExporter ex)
|
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final java.util.logging.Logger log
protected Vector3f currentCamCell
protected int quarterSize
protected int quadSize
protected HeightMapGrid heightMapGrid
protected Vector3f[] quadIndex
protected java.util.Set<TerrainGridListener> listeners
protected Material material
protected LRUCache<Vector3f,TerrainQuad> cache
protected int cellsLoaded
protected int[] gridOffset
protected boolean runOnce
protected java.util.concurrent.ExecutorService cacheExecutor
Constructor Detail |
---|
public TerrainGrid(java.lang.String name, int patchSize, int maxVisibleSize, Vector3f scale, TerrainGridTileLoader terrainQuadGrid, Vector2f offset, float offsetAmount)
public TerrainGrid(java.lang.String name, int patchSize, int maxVisibleSize, Vector3f scale, TerrainGridTileLoader terrainQuadGrid)
public TerrainGrid(java.lang.String name, int patchSize, int maxVisibleSize, TerrainGridTileLoader terrainQuadGrid)
@Deprecated public TerrainGrid(java.lang.String name, int patchSize, int maxVisibleSize, Vector3f scale, HeightMapGrid heightMapGrid, Vector2f offset, float offsetAmount)
@Deprecated public TerrainGrid(java.lang.String name, int patchSize, int maxVisibleSize, Vector3f scale, HeightMapGrid heightMapGrid)
@Deprecated public TerrainGrid(java.lang.String name, int patchSize, int maxVisibleSize, HeightMapGrid heightMapGrid)
public TerrainGrid()
Method Detail |
---|
protected boolean isCenter(int quadIndex)
protected int getQuadrant(int quadIndex)
public Vector3f getCamCell(Vector3f location)
public Vector3f getTileCell(Vector3f location)
location
- world coordinatepublic TerrainGridTileLoader getGridTileLoader()
protected void removeQuad(int idx)
protected void attachQuadAt(TerrainQuad q, int quadrant, Vector3f quadCell)
protected void updateChildren(Vector3f camCell)
camCell
- the cell the camera is inpublic void addListener(TerrainGridListener listener)
public Vector3f getCurrentCell()
public void removeListener(TerrainGridListener listener)
public void setMaterial(Material mat)
Spatial
setMaterial
in class Node
mat
- The material to set.public void setQuadSize(int quadSize)
public void adjustHeight(java.util.List<Vector2f> xz, java.util.List<java.lang.Float> height)
Terrain
adjustHeight
in interface Terrain
adjustHeight
in class TerrainQuad
xz
- a list of coordinates where the hight will be adjustedheight
- +- value to adjust the height by, that matches the xz coordinatesprotected float getHeightmapHeight(int x, int z)
TerrainQuad
getHeightmapHeight
in class TerrainQuad
public int getNumMajorSubdivisions()
getNumMajorSubdivisions
in interface Terrain
getNumMajorSubdivisions
in class TerrainQuad
public Material getMaterial(Vector3f worldLocation)
Terrain
getMaterial
in interface Terrain
getMaterial
in class TerrainQuad
worldLocation
- the location, in world coordinates, of where
we are interested in the underlying texture.protected java.util.concurrent.ExecutorService createExecutorService()
public void read(JmeImporter im) throws java.io.IOException
read
in interface Savable
read
in class TerrainQuad
java.io.IOException
public void write(JmeExporter ex) throws java.io.IOException
write
in interface Savable
write
in class TerrainQuad
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |