Package com.jme3.terrain.geomipmap
Class TerrainPatch
java.lang.Object
com.jme3.scene.Spatial
com.jme3.scene.Geometry
com.jme3.terrain.geomipmap.TerrainPatch
- All Implemented Interfaces:
- HasLocalTransform,- CloneableSmartAsset,- Collidable,- Savable,- JmeCloneable,- Cloneable
A terrain patch is a leaf in the terrain quad tree. It has a mesh that can change levels of detail (LOD)
 whenever the view point, or camera, changes. The actual terrain mesh is created by the LODGeomap class.
 That uses a geo-mipmapping algorithm to change the index buffer of the mesh.
 The mesh is a triangle strip. In wireframe mode you might notice some strange lines, these are degenerate
 triangles generated by the geoMipMap algorithm and can be ignored. The video card removes them at almost no cost.
 Each patch needs to know its neighbour's LOD so it can seam its edges with them, in case the neighbour has a different
 LOD. If this doesn't happen, you will see gaps.
 The LOD value is most detailed at zero. It gets less detailed the higher the LOD value until you reach maxLod, which
 is a mathematical limit on the number of times the 'size' of the patch can be divided by two. However, there is a -1 to that
 for now until I add in a custom index buffer calculation for that max level, the current algorithm does not go that far.
 You can supply a LodThresholdCalculator for use in determining when the LOD should change. Its API will no doubt change
 in the near future. Right now it defaults to just changing LOD every two patch sizes. So if a patch has a size of 65,
 then the LOD changes every 130 units away.
- 
Nested Class SummaryNested classes/interfaces inherited from class com.jme3.scene.SpatialSpatial.BatchHint, Spatial.CullHint, Spatial.DFSMode
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected TerrainPatchprotected LODGeomapprotected TerrainPatchprotected intprotected intprotected float[]protected intprotected intprotected intprotected Vector2fprotected floatprotected intprotected shortprotected TerrainPatchprotected booleanprotected intprotected Vector3fprotected TerrainPatchprotected intprotected Vector3fprotected Vector3fFields inherited from class com.jme3.scene.GeometrycachedWorldMat, groupNode, ignoreTransform, lodLevel, material, mesh, SAVABLE_VERSION, startIndexFields 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 SummaryConstructorsConstructorDescriptionTerrainPatch(String name) TerrainPatch(String name, int size) TerrainPatch(String name, int size, Vector3f stepScale, float[] heightMap, Vector3f origin) Constructor instantiates a newTerrainPatchobject.TerrainPatch(String name, int size, Vector3f stepScale, float[] heightMap, Vector3f origin, int totalSize, Vector2f offset, float offsetAmount) Constructor instantiates a newTerrainPatchobject.
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidaverageNormalsTangents(Vector3f topPoint, Vector3f rootPoint, Vector3f leftPoint, Vector3f bottomPoint, Vector3f rightPoint, Vector3f normal, Vector3f tangent, Vector3f binormal) protected voidCaches the transforms (except rotation) so the LOD calculator, which runs on a separate thread, can access them safely.protected voidRemoves any references when the terrain is being removed.clone()This version of clone is a shallow clone, in other words, the same mesh is referenced as the original geometry.voidcloneFields(Cloner cloner, Object original) Called internally by com.jme3.util.clone.Cloner.intcollideWith(Collidable other, CollisionResults results) Check collision with another Collidable.protected voidprotected voidfixNormalEdges(TerrainPatch right, TerrainPatch bottom, TerrainPatch top, TerrainPatch left, TerrainPatch bottomRight, TerrainPatch bottomLeft, TerrainPatch topRight, TerrainPatch topLeft) Matches the normals along the edge of the patch with the neighbours.voidThis calculation is slow, so don't use it often.Triangle[]getGridTriangles(float x, float z) Get the triangles at the specified grid point.protected floatgetHeight(int x, int z, float xm, float zm) float[]floatgetHeightmapHeight(float x, float z) intgetLod()protected intfloat[]protected intprotected intprotected intintThe maximum lod supported by this terrain patch.protected Vector3fgetMeshNormal(int x, int z) Returns the current offset amount.floatReturns the offset amount this terrain patch uses for textures.intshortintgetSize()Returns the size of this terrain patch.Returns the step scale that stretches the height map.intReturns the total size of the terrain.getTriangle(float x, float z) Get the triangle of this geometry at the specified local coordinate.voidlockMesh()Locks the mesh (sets it static) to improve performance.voidread(JmeImporter im) protected voidreIndexGeometry(HashMap<String, UpdatedTerrainPatch> updated, boolean useVariableLod) protected voidsetHeight(List<TerrainQuad.LocationHeight> locationHeights, boolean overrideHeight) voidsetLod(int lod) protected voidsetLodBottom(int lodBottom) protected voidsetLodLeft(int lodLeft) protected voidsetLodRight(int lodRight) protected voidsetLodTop(int lodTop) voidSets the value for the current offset amount to use when building texture coordinates.voidsetOffsetAmount(float offsetAmount) Sets the offset of this terrain texture map.voidsetPreviousLod(int previousLod) voidsetQuadrant(short quadrant) voidsetSize(int size) Sets the size of this terrain patch.voidsetStepScale(Vector3f stepScale) Sets the step scale of this terrain patch's height map.voidsetTotalSize(int totalSize) Sets the total size of the terrain .voidUnlocks the mesh (sets it dynamic) to make it editable.protected voidRecalculates all normal vectors in this terrain patch.protected Vector3fvoidwrite(JmeExporter ex) Methods inherited from class com.jme3.scene.GeometryassociateWithGroupNode, breadthFirstTraversal, checkCulling, clone, computeWorldMatrix, deepClone, depthFirstTraversal, getFallbackMorphTarget, getLodLevel, getMaterial, getMesh, getModelBound, getMorphState, getMorphState, getNbSimultaneousGPUMorph, getTriangleCount, getVertexCount, getWorldMatrix, isBatched, isDirtyMorph, isGrouped, isIgnoreTransform, oldDeepClone, removeFromParent, setDirtyMorph, setFallbackMorphTarget, setIgnoreTransform, setLodLevel, setMaterial, setMesh, setModelBound, setMorphState, setMorphState, setNbSimultaneousGPUMorph, setParent, unassociateFromGroupNode, updateModelBound, updateWorldBound, updateWorldLightList, updateWorldTransformsMethods inherited from class com.jme3.scene.SpatialaddControl, addControlAt, addLight, addMatParamOverride, breadthFirstTraversal, center, 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, removeLight, removeMatParamOverride, rotate, rotate, rotateUpTo, runControlRender, scale, scale, setBatchHint, setBoundRefresh, setCullHint, setKey, setLastFrustumIntersection, setLightListRefresh, setLocalRotation, setLocalRotation, setLocalScale, setLocalScale, setLocalScale, setLocalTransform, setLocalTranslation, setLocalTranslation, setMatParamOverrideRefresh, setName, setQueueBucket, setRequiresUpdates, setShadowMode, setTransformRefresh, setUserData, toString, updateGeometricState, updateLogicalState, updateMatParamOverrides, worldToLocal
- 
Field Details- 
geomap
- 
lodprotected int lod
- 
previousLodprotected int previousLod
- 
lodLeftprotected int lodLeft
- 
lodTopprotected int lodTop
- 
lodRightprotected int lodRight
- 
lodBottomprotected int lodBottom
- 
sizeprotected int size
- 
totalSizeprotected int totalSize
- 
quadrantprotected short quadrant
- 
stepScale
- 
offset
- 
offsetAmountprotected float offsetAmount
- 
leftNeighbour
- 
topNeighbour
- 
rightNeighbour
- 
bottomNeighbour
- 
searchedForNeighboursAlreadyprotected boolean searchedForNeighboursAlready
- 
worldTranslationCached
- 
worldScaleCached
- 
lodEntropyprotected float[] lodEntropy
 
- 
- 
Constructor Details- 
TerrainPatchpublic TerrainPatch()
- 
TerrainPatch
- 
TerrainPatch
- 
TerrainPatchConstructor instantiates a newTerrainPatchobject. The parameters and heightmap data are then processed to generate aTriMeshobject for rendering.- Parameters:
- name- the name of the terrain patch.
- size- the size of the heightmap.
- stepScale- the scale for the axes.
- heightMap- the height data.
- origin- the origin offset of the patch.
 
- 
TerrainPatchpublic TerrainPatch(String name, int size, Vector3f stepScale, float[] heightMap, Vector3f origin, int totalSize, Vector2f offset, float offsetAmount) Constructor instantiates a newTerrainPatchobject. The parameters and heightmap data are then processed to generate aTriMeshobject for rendering.- Parameters:
- name- the name of the terrain patch.
- size- the size of the patch.
- stepScale- the scale for the axes.
- heightMap- the height data.
- origin- the origin offset of the patch.
- totalSize- the total size of the terrain. (Higher if the patch is part of a- TerrainQuadtree.)
- offset- the offset for texture coordinates.
- offsetAmount- the total offset amount. Used for texture coordinates.
 
 
- 
- 
Method Details- 
generateLodEntropiespublic void generateLodEntropies()This calculation is slow, so don't use it often.
- 
getLodEntropiespublic float[] getLodEntropies()
- 
getHeightMappublic float[] getHeightMap()
- 
getMaxLodpublic int getMaxLod()The maximum lod supported by this terrain patch. If the patch size is 32 then the returned value would be log2(32)-2 = 3 You can then use that value, 3, to see how many times you can divide 32 by 2 before the terrain gets too un-detailed (can't stitch it any further).- Returns:
- the maximum LOD
 
- 
reIndexGeometry
- 
getTex
- 
getHeightmapHeightpublic float getHeightmapHeight(float x, float z) 
- 
getTriangleGet the triangle of this geometry at the specified local coordinate.- Parameters:
- x- local to the terrain patch
- z- local to the terrain patch
- Returns:
- the triangle in world coordinates, or null if the point does intersect this patch on the XZ axis
 
- 
getGridTrianglesGet the triangles at the specified grid point. Probably only 2 triangles- Parameters:
- x- local to the terrain patch
- z- local to the terrain patch
- Returns:
- the triangles in world coordinates, or null if the point does intersect this patch on the XZ axis
 
- 
setHeight
- 
updateNormalsprotected void updateNormals()Recalculates all normal vectors in this terrain patch.
- 
fixNormalEdgesprotected void fixNormalEdges(TerrainPatch right, TerrainPatch bottom, TerrainPatch top, TerrainPatch left, TerrainPatch bottomRight, TerrainPatch bottomLeft, TerrainPatch topRight, TerrainPatch topLeft) Matches the normals along the edge of the patch with the neighbours. Computes the normals for the right, bottom, left, and top edges of the patch, and saves those normals in the neighbour's edges too. Takes 4 points (if it has a neighbour on that side) for each point on the edge of the patch: * | *---x---* | * It works across the right side of the patch, from the top down to the bottom. Then it works on the bottom side of the patch, from the left to the right.
- 
averageNormalsTangents
- 
getMeshNormal
- 
getHeightprotected float getHeight(int x, int z, float xm, float zm) 
- 
lockMeshpublic void lockMesh()Locks the mesh (sets it static) to improve performance. If it is not editable, then unlock to make it editable.
- 
unlockMeshpublic void unlockMesh()Unlocks the mesh (sets it dynamic) to make it editable. It will be editable but performance will be reduced. Call lockMesh to improve performance.
- 
getOffsetAmountpublic float getOffsetAmount()Returns the offset amount this terrain patch uses for textures.- Returns:
- The current offset amount.
 
- 
getStepScaleReturns the step scale that stretches the height map.- Returns:
- The current step scale.
 
- 
getTotalSizepublic int getTotalSize()Returns the total size of the terrain.- Returns:
- The terrain's total size.
 
- 
getSizepublic int getSize()Returns the size of this terrain patch.- Returns:
- The current patch size.
 
- 
getOffsetReturns the current offset amount. This is used when building texture coordinates.- Returns:
- The current offset amount.
 
- 
setOffsetSets the value for the current offset amount to use when building texture coordinates. Note that this does NOT rebuild the terrain at all. This is mostly used for outside constructors of terrain patches.- Parameters:
- offset- The new texture offset.
 
- 
setSizepublic void setSize(int size) Sets the size of this terrain patch. Note that this does NOT rebuild the terrain at all. This is mostly used for outside constructors of terrain patches.- Parameters:
- size- The new size.
 
- 
setTotalSizepublic void setTotalSize(int totalSize) Sets the total size of the terrain . Note that this does NOT rebuild the terrain at all. This is mostly used for outside constructors of terrain patches.- Parameters:
- totalSize- The new total size.
 
- 
setStepScaleSets the step scale of this terrain patch's height map. Note that this does NOT rebuild the terrain at all. This is mostly used for outside constructors of terrain patches.- Parameters:
- stepScale- The new step scale.
 
- 
setOffsetAmountpublic void setOffsetAmount(float offsetAmount) Sets the offset of this terrain texture map. Note that this does NOT rebuild the terrain at all. This is mostly used for outside constructors of terrain patches.- Parameters:
- offsetAmount- The new texture offset.
 
- 
getQuadrantpublic short getQuadrant()- Returns:
- Returns the quadrant.
 
- 
setQuadrantpublic void setQuadrant(short quadrant) - Parameters:
- quadrant- The quadrant to set.
 
- 
getLodpublic int getLod()
- 
setLodpublic void setLod(int lod) 
- 
getPreviousLodpublic int getPreviousLod()
- 
setPreviousLodpublic void setPreviousLod(int previousLod) 
- 
getLodLeftprotected int getLodLeft()
- 
setLodLeftprotected void setLodLeft(int lodLeft) 
- 
getLodTopprotected int getLodTop()
- 
setLodTopprotected void setLodTop(int lodTop) 
- 
getLodRightprotected int getLodRight()
- 
setLodRightprotected void setLodRight(int lodRight) 
- 
getLodBottomprotected int getLodBottom()
- 
setLodBottomprotected void setLodBottom(int lodBottom) 
- 
collideWithpublic int collideWith(Collidable other, CollisionResults results) throws UnsupportedCollisionException Description copied from interface:CollidableCheck collision with another Collidable.- Specified by:
- collideWithin interface- Collidable
- Overrides:
- collideWithin class- Geometry
- Parameters:
- other- The object to check collision against
- results- Will contain the list of- CollisionResults.
- Returns:
- how many collisions were found between this and other
- Throws:
- UnsupportedCollisionException
 
- 
worldCoordinateToLocal
- 
write- Specified by:
- writein interface- Savable
- Overrides:
- writein class- Geometry
- Throws:
- IOException
 
- 
read- Specified by:
- readin interface- Savable
- Overrides:
- readin class- Geometry
- Throws:
- IOException
 
- 
cloneDescription copied from class:GeometryThis version of clone is a shallow clone, in other words, the same mesh is referenced as the original geometry. Exception: if the mesh is marked as being a software animated mesh, (bind pose is set) then the positions and normals are deep copied.- Specified by:
- clonein interface- CloneableSmartAsset
- Overrides:
- clonein class- Geometry
- Returns:
- A clone of this Spatial, the scene graph in its entirety is cloned and can be altered independently of the original scene graph. Note that meshes of geometries are not cloned explicitly, they are shared if static, or specially cloned if animated.
- See Also:
 
- 
cloneFieldsCalled internally by com.jme3.util.clone.Cloner. Do not call directly.- Specified by:
- cloneFieldsin interface- JmeCloneable
- Overrides:
- cloneFieldsin class- Geometry
- Parameters:
- cloner- The cloner that is performing the cloning operation. The cloneFields method can call back into the cloner to make clones of its subordinate fields.
- original- The original object from which this object was cloned. This is provided for the very rare case that this object needs to refer to its original for some reason. In general, all of the relevant values should have been transferred during the shallow clone, and this object need only clone what it wants.
 
- 
ensurePositiveVolumeBBoxprotected void ensurePositiveVolumeBBox()
- 
cacheTerrainTransformsprotected void cacheTerrainTransforms()Caches the transforms (except rotation) so the LOD calculator, which runs on a separate thread, can access them safely.
- 
getWorldScaleCached
- 
getWorldTranslationCached
- 
clearCachesprotected void clearCaches()Removes any references when the terrain is being removed.
 
-