Class TerrainGrid
- All Implemented Interfaces:
- HasLocalTransform,- CloneableSmartAsset,- Collidable,- Savable,- Terrain,- JmeCloneable,- Cloneable
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 | 3 | Four terrainQuads that make up the grid | *..|..* | with the cameraCell in the middle, covering |----|--|--|----| all four quads. | *..|..* | | 2 | 4 | +-------+-------+
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 grid 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:
- tile Attached
- tile Detached
- grid moved.
These allow physics to update, and other operation (often needed for loading the terrain) to occur at the right time.
- 
Nested Class SummaryNested ClassesNested classes/interfaces inherited from class com.jme3.terrain.geomipmap.TerrainQuadTerrainQuad.LocationHeightNested classes/interfaces inherited from class com.jme3.scene.SpatialSpatial.BatchHint, Spatial.CullHint, Spatial.DFSMode
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected LRUCache<Vector3f,TerrainQuad> protected ExecutorServiceprotected intprotected Vector3fprotected int[]protected Set<TerrainGridListener>protected static final Loggerprotected Materialprotected Vector3f[]protected intprotected intprotected booleanFields inherited from class com.jme3.terrain.geomipmap.TerrainQuadneighbourFinder, offset, offsetAmount, patchSize, quadrant, size, stepScale, totalSizeFields inherited from class com.jme3.scene.SpatialbatchHint, controls, cullHint, frustrumIntersects, key, localLights, localOverrides, localTransform, name, parent, queueBucket, queueDistance, refreshFlags, RF_BOUND, RF_CHILD_LIGHTLIST, RF_LIGHTLIST, RF_MATPARAM_OVERRIDE, RF_TRANSFORM, shadowMode, userData, worldBound, worldLights, worldOverrides, worldTransform
- 
Constructor SummaryConstructorsConstructorDescriptionTerrainGrid(String name, int patchSize, int maxVisibleSize, Vector3f scale, TerrainGridTileLoader terrainQuadGrid) TerrainGrid(String name, int patchSize, int maxVisibleSize, Vector3f scale, TerrainGridTileLoader terrainQuadGrid, Vector2f offset, float offsetAmount) TerrainGrid(String name, int patchSize, int maxVisibleSize, TerrainGridTileLoader terrainQuadGrid) 
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddListener(TerrainGridListener listener) voidadjustHeight(List<Vector2f> xz, List<Float> height) Raise/lower the height at many points.protected voidattachQuadAt(TerrainQuad q, int quadrant, Vector3f quadCell, boolean shifted) Runs on the rendering threadprotected ExecutorServiceThis will print out any exceptions from the threadgetCamCell(Vector3f location) Get the location in cell-coordinates of the specified location.protected floatgetHeightmapHeight(int x, int z) This will just get the heightmap value at the supplied point, not an interpolated (actual) height value.getMaterial(Vector3f worldLocation) Returns the material that this terrain uses.intprotected intgetQuadrant(int quadIndex) getTerrainAt(Vector3f worldLocation) Get the terrain tile at the specified world location, in XZ coordinates.getTerrainAtCell(Vector3f cellCoordinate) Get the terrain tile at the specified XZ cell coordinate (not world coordinate).getTileCell(Vector3f location) Centered at 0,0.protected booleanisCenter(int quadIndex) voidread(JmeImporter im) voidremoveListener(TerrainGridListener listener) protected voidvoidsetMaterial(Material mat) Applies the given material to the Spatial, this will propagate the material down to the geometries in the scene graph.voidsetQuadSize(int quadSize) toCellSpace(Vector3f worldLocation) Convert the world location into a cell location (integer coordinates)toWorldSpace(Vector3f cellLocation) Convert the cell coordinate (integer coordinates) into world coordinates.protected voidupdateChildren(Vector3f camCell) Called when the camera has moved into a new cell.voidwrite(JmeExporter ex) Methods inherited from class com.jme3.terrain.geomipmap.TerrainQuadadjustHeight, attachBoundChildren, cacheTerrainTransforms, calculateLod, clearCaches, clone, clone, cloneFields, collideWith, createHeightSubBlock, createQuad, createQuadPatch, findDownPatch, findDownQuad, findLeftPatch, findLeftQuad, findNeighboursLod, findPick, findRightPatch, findRightQuad, findTopPatch, findTopQuad, fixEdges, fixNormalEdges, fixNormals, generateDebugTangents, generateEntropy, getAllTerrainPatches, getAllTerrainPatchesWithTranslation, getHeight, getHeight, getHeightMap, getHeightmapHeight, getMaterial, getMaxLod, getMeshNormal, getNormal, getNormal, getPatch, getPatchSize, getQuad, getQuadrant, getTerrainSize, getTotalSize, isPointOnTerrain, isRootQuad, needToRecalculateNormals, recalculateAllNormals, reIndexPages, resetCachedNeighbours, setHeight, setHeight, setHeight, setHeight, setLocked, setNeedToRecalculateNormals, setNeighbourFinder, setNormalRecalcNeeded, setParent, setQuadrant, setSupportMultipleCollisions, split, updateNormalsMethods inherited from class com.jme3.scene.NodeattachChild, attachChildAt, breadthFirstTraversal, deepClone, depthFirstTraversal, descendantMatches, descendantMatches, descendantMatches, detachAllChildren, detachChild, detachChildAt, detachChildNamed, getChild, getChild, getChildIndex, getChildren, getQuantity, getTriangleCount, getVertexCount, hasChild, oldDeepClone, setLightListRefresh, setLodLevel, setMatParamOverrideRefresh, setModelBound, setTransformRefresh, swapChildren, updateGeometricState, updateLogicalState, updateModelBound, updateWorldBoundMethods inherited from class com.jme3.scene.SpatialaddControl, addControlAt, addLight, addMatParamOverride, breadthFirstTraversal, center, checkCulling, clearMatParamOverrides, depthFirstTraversal, forceRefresh, getBatchHint, getControl, getControl, getCullHint, getKey, getLastFrustumIntersection, getLocalBatchHint, getLocalCullHint, getLocalLightList, getLocalMatParamOverrides, getLocalQueueBucket, getLocalRotation, getLocalScale, getLocalShadowMode, getLocalToWorldMatrix, getLocalTransform, getLocalTranslation, getName, getNumControls, getParent, getQueueBucket, getShadowMode, getUserData, getUserDataKeys, getWorldBound, getWorldLightList, getWorldMatParamOverrides, getWorldRotation, getWorldScale, getWorldTransform, getWorldTranslation, hasAncestor, jmeClone, localToWorld, lookAt, matches, move, move, oldClone, removeControl, removeControl, removeFromParent, removeLight, removeMatParamOverride, rotate, rotate, rotateUpTo, runControlRender, scale, scale, setBatchHint, setBoundRefresh, setCullHint, setKey, setLastFrustumIntersection, setLocalRotation, setLocalRotation, setLocalScale, setLocalScale, setLocalScale, setLocalTransform, setLocalTranslation, setLocalTranslation, setName, setQueueBucket, setRequiresUpdates, setShadowMode, setUserData, toString, updateMatParamOverrides, updateWorldLightList, updateWorldTransforms, worldToLocal
- 
Field Details- 
log
- 
currentCamCell
- 
quarterSizeprotected int quarterSize
- 
quadSizeprotected int quadSize
- 
quadIndex
- 
listeners
- 
material
- 
cache
- 
cellsLoadedprotected int cellsLoaded
- 
gridOffsetprotected int[] gridOffset
- 
runOnceprotected boolean runOnce
- 
cacheExecutor
 
- 
- 
Constructor Details- 
TerrainGridpublic TerrainGrid(String name, int patchSize, int maxVisibleSize, Vector3f scale, TerrainGridTileLoader terrainQuadGrid, Vector2f offset, float offsetAmount) 
- 
TerrainGridpublic TerrainGrid(String name, int patchSize, int maxVisibleSize, Vector3f scale, TerrainGridTileLoader terrainQuadGrid) 
- 
TerrainGridpublic TerrainGrid(String name, int patchSize, int maxVisibleSize, TerrainGridTileLoader terrainQuadGrid) 
- 
TerrainGridpublic TerrainGrid()
 
- 
- 
Method Details- 
isCenterprotected boolean isCenter(int quadIndex) 
- 
getQuadrantprotected int getQuadrant(int quadIndex) 
- 
getCamCellGet the location in cell-coordinates of the specified location. Cell coordinates are integer coordinates, usually with y=0, each representing a cell in the world. For example, moving right in the +X direction: (0,0,0) (1,0,0) (2,0,0), (3,0,0) and then down the -Z direction: (3,0,-1) (3,0,-2) (3,0,-3)
- 
getTileCellCentered at 0,0. Get the tile index location in integer form:- Parameters:
- location- world coordinate
 
- 
getGridTileLoader
- 
getTerrainAtGet the terrain tile at the specified world location, in XZ coordinates.
- 
getTerrainAtCellGet the terrain tile at the specified XZ cell coordinate (not world coordinate).- Parameters:
- cellCoordinate- integer cell coordinates
- Returns:
- the terrain tile at that location
 
- 
toCellSpaceConvert the world location into a cell location (integer coordinates)
- 
toWorldSpaceConvert the cell coordinate (integer coordinates) into world coordinates.
- 
removeQuad
- 
attachQuadAtRuns on the rendering thread- Parameters:
- shifted- quads are still attached to the parent and don't need to re-load
 
- 
updateChildrenCalled when the camera has moved into a new cell. We need to update what quads are in the scene now. Step 1: touch cache LRU cache is used, so elements that need to remain should be touched. Step 2: load new quads in background thread if the camera has moved into a new cell, we load in new quads- Parameters:
- camCell- the cell the camera is in
 
- 
addListener
- 
getCurrentCell
- 
removeListener
- 
setMaterialDescription copied from class:SpatialApplies the given material to the Spatial, this will propagate the material down to the geometries in the scene graph.- Overrides:
- setMaterialin class- Node
- Parameters:
- mat- The material to set.
 
- 
setQuadSizepublic void setQuadSize(int quadSize) 
- 
adjustHeightDescription copied from interface:TerrainRaise/lower the height at many points. The two lists must be the same size. Each xz coordinate entry matches to a height entry, 1 for 1. So the first coordinate matches to the first height value, the last to the last etc.- Specified by:
- adjustHeightin interface- Terrain
- Overrides:
- adjustHeightin class- TerrainQuad
- Parameters:
- xz- a list of coordinates where the height will be adjusted
- height- +- value to adjust the height by, that matches the xz coordinates
 
- 
getHeightmapHeightprotected float getHeightmapHeight(int x, int z) Description copied from class:TerrainQuadThis will just get the heightmap value at the supplied point, not an interpolated (actual) height value.- Overrides:
- getHeightmapHeightin class- TerrainQuad
 
- 
getNumMajorSubdivisionspublic int getNumMajorSubdivisions()- Specified by:
- getNumMajorSubdivisionsin interface- Terrain
- Overrides:
- getNumMajorSubdivisionsin class- TerrainQuad
 
- 
getMaterialDescription copied from interface:TerrainReturns the material that this terrain uses. Terrain can have different materials in different locations. In general, the TerrainQuad will only have one material. But TerrainGrid will have a different material per tile. It could be possible to pass in null for the location, some Terrain implementations might just have the one material and not care where you are looking. So implementations must handle null being supplied.- Specified by:
- getMaterialin interface- Terrain
- Overrides:
- getMaterialin class- TerrainQuad
- Parameters:
- worldLocation- the location, in world coordinates, of where we are interested in the underlying texture.
 
- 
createExecutorServiceThis will print out any exceptions from the thread
- 
read- Specified by:
- readin interface- Savable
- Overrides:
- readin class- TerrainQuad
- Throws:
- IOException
 
- 
write- Specified by:
- writein interface- Savable
- Overrides:
- writein class- TerrainQuad
- Throws:
- IOException
 
 
-