|
||||||||||
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.Geometry
com.jme3.terrain.geomipmap.TerrainPatch
public class TerrainPatch
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. It's 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 Summary |
---|
Nested classes/interfaces inherited from class com.jme3.scene.Spatial |
---|
Spatial.BatchHint, Spatial.CullHint |
Field Summary | |
---|---|
protected TerrainPatch |
bottomNeighbour
|
protected LODGeomap |
geomap
|
protected TerrainPatch |
leftNeighbour
|
protected int |
lod
|
protected int |
lodBottom
|
protected float[] |
lodEntropy
|
protected int |
lodLeft
|
protected int |
lodRight
|
protected int |
lodTop
|
protected Vector2f |
offset
|
protected float |
offsetAmount
|
protected int |
previousLod
|
protected short |
quadrant
|
protected TerrainPatch |
rightNeighbour
|
protected boolean |
searchedForNeighboursAlready
|
protected int |
size
|
protected Vector3f |
stepScale
|
protected TerrainPatch |
topNeighbour
|
protected int |
totalSize
|
protected Vector3f |
worldScaleCached
|
protected Vector3f |
worldTranslationCached
|
Fields inherited from class com.jme3.scene.Geometry |
---|
batchNode, cachedOffsetMat, cachedWorldMat, ignoreTransform, lodLevel, material, mesh, prevBatchTransforms, SAVABLE_VERSION, startIndex |
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 | |
---|---|
TerrainPatch()
|
|
TerrainPatch(java.lang.String name)
|
|
TerrainPatch(java.lang.String name,
int size)
|
|
TerrainPatch(java.lang.String name,
int size,
Vector3f stepScale,
float[] heightMap,
Vector3f origin)
Constructor instantiates a new TerrainPatch object. |
|
TerrainPatch(java.lang.String name,
int size,
Vector3f stepScale,
float[] heightMap,
Vector3f origin,
int totalSize,
Vector2f offset,
float offsetAmount)
Constructor instantiates a new TerrainPatch object. |
Method Summary | |
---|---|
protected void |
averageNormalsTangents(Vector3f topPoint,
Vector3f rootPoint,
Vector3f leftPoint,
Vector3f bottomPoint,
Vector3f rightPoint,
Vector3f normal,
Vector3f tangent,
Vector3f binormal)
|
protected void |
cacheTerrainTransforms()
Caches the transforms (except rotation) so the LOD calculator, which runs on a separate thread, can access them safely. |
TerrainPatch |
clone()
This version of clone is a shallow clone, in other words, the same mesh is referenced as the original geometry. |
int |
collideWith(Collidable other,
CollisionResults results)
Check collision with another Collidable. |
protected void |
ensurePositiveVolumeBBox()
|
protected 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. |
void |
generateLodEntropies()
This calculation is slow, so don't use it often. |
Triangle[] |
getGridTriangles(float x,
float z)
Get the triangles at the specified grid point. |
protected float |
getHeight(int x,
int z,
float xm,
float zm)
|
java.nio.FloatBuffer |
getHeightmap()
Deprecated. |
float[] |
getHeightMap()
|
float |
getHeightmapHeight(float x,
float z)
|
int |
getLod()
|
protected int |
getLodBottom()
|
float[] |
getLodEntropies()
|
protected int |
getLodLeft()
|
protected int |
getLodRight()
|
protected int |
getLodTop()
|
int |
getMaxLod()
The maximum lod supported by this terrain patch. |
protected Vector3f |
getMeshNormal(int x,
int z)
|
Vector2f |
getOffset()
Returns the current offset amount. |
float |
getOffsetAmount()
Returns the offset amount this terrain patch uses for textures. |
int |
getPreviousLod()
|
short |
getQuadrant()
|
int |
getSize()
Returns the size of this terrain patch. |
Vector3f |
getStepScale()
Returns the step scale that stretches the height map. |
Vector2f |
getTex(float x,
float z,
Vector2f store)
|
int |
getTotalSize()
Returns the total size of the terrain. |
Triangle |
getTriangle(float x,
float z)
Get the triangle of this geometry at the specified local coordinate. |
Vector3f |
getWorldScaleCached()
|
Vector3f |
getWorldTranslationCached()
|
void |
lockMesh()
Locks the mesh (sets it static) to improve performance. |
void |
read(JmeImporter im)
|
protected void |
reIndexGeometry(java.util.HashMap<java.lang.String,UpdatedTerrainPatch> updated,
boolean useVariableLod)
|
protected void |
setHeight(java.util.List<TerrainQuad.LocationHeight> locationHeights,
boolean overrideHeight)
|
void |
setLod(int lod)
|
protected void |
setLodBottom(int lodBottom)
|
protected void |
setLodLeft(int lodLeft)
|
protected void |
setLodRight(int lodRight)
|
protected void |
setLodTop(int lodTop)
|
void |
setOffset(Vector2f offset)
Sets the value for the current offset amount to use when building texture coordinates. |
void |
setOffsetAmount(float offsetAmount)
Sets the offset of this terrain texture map. |
void |
setPreviousLod(int previousLod)
|
void |
setQuadrant(short quadrant)
|
void |
setSize(int size)
Sets the size of this terrain patch. |
void |
setStepScale(Vector3f stepScale)
Sets the step scale of this terrain patch's height map. |
void |
setTotalSize(int totalSize)
Sets the total size of the terrain . |
void |
unlockMesh()
Unlocks the mesh (sets it dynamic) to make it editable. |
protected void |
updateNormals()
recalculate all of the normal vectors in this terrain patch |
protected Vector3f |
worldCoordinateToLocal(Vector3f loc)
|
void |
write(JmeExporter ex)
|
Methods inherited from class com.jme3.scene.Geometry |
---|
batch, breadthFirstTraversal, clone, computeOffsetTransform, computeWorldMatrix, deepClone, depthFirstTraversal, getLodLevel, getMaterial, getMesh, getModelBound, getTriangleCount, getVertexCount, getWorldMatrix, isBatched, isIgnoreTransform, removeFromParent, setIgnoreTransform, setLodLevel, setMaterial, setMesh, setModelBound, setParent, unBatch, updateModelBound, updateWorldBound, updateWorldTransforms |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected LODGeomap geomap
protected int lod
protected int previousLod
protected int lodLeft
protected int lodTop
protected int lodRight
protected int lodBottom
protected int size
protected int totalSize
protected short quadrant
protected Vector3f stepScale
protected Vector2f offset
protected float offsetAmount
protected TerrainPatch leftNeighbour
protected TerrainPatch topNeighbour
protected TerrainPatch rightNeighbour
protected TerrainPatch bottomNeighbour
protected boolean searchedForNeighboursAlready
protected Vector3f worldTranslationCached
protected Vector3f worldScaleCached
protected float[] lodEntropy
Constructor Detail |
---|
public TerrainPatch()
public TerrainPatch(java.lang.String name)
public TerrainPatch(java.lang.String name, int size)
public TerrainPatch(java.lang.String name, int size, Vector3f stepScale, float[] heightMap, Vector3f origin)
TerrainPatch
object. The
parameters and heightmap data are then processed to generate a
TriMesh
object for rendering.
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.public TerrainPatch(java.lang.String name, int size, Vector3f stepScale, float[] heightMap, Vector3f origin, int totalSize, Vector2f offset, float offsetAmount)
TerrainPatch
object. The
parameters and heightmap data are then processed to generate a
TriMesh
object for renderering.
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 TerrainQuad
tree.offset
- the offset for texture coordinates.offsetAmount
- the total offset amount. Used for texture coordinates.Method Detail |
---|
public void generateLodEntropies()
public float[] getLodEntropies()
@Deprecated public java.nio.FloatBuffer getHeightmap()
public float[] getHeightMap()
public int getMaxLod()
protected void reIndexGeometry(java.util.HashMap<java.lang.String,UpdatedTerrainPatch> updated, boolean useVariableLod)
public Vector2f getTex(float x, float z, Vector2f store)
public float getHeightmapHeight(float x, float z)
public Triangle getTriangle(float x, float z)
x
- local to the terrain patchz
- local to the terrain patch
public Triangle[] getGridTriangles(float x, float z)
x
- local to the terrain patchz
- local to the terrain patch
protected void setHeight(java.util.List<TerrainQuad.LocationHeight> locationHeights, boolean overrideHeight)
protected void updateNormals()
protected void fixNormalEdges(TerrainPatch right, TerrainPatch bottom, TerrainPatch top, TerrainPatch left, TerrainPatch bottomRight, TerrainPatch bottomLeft, TerrainPatch topRight, TerrainPatch topLeft)
protected void averageNormalsTangents(Vector3f topPoint, Vector3f rootPoint, Vector3f leftPoint, Vector3f bottomPoint, Vector3f rightPoint, Vector3f normal, Vector3f tangent, Vector3f binormal)
protected Vector3f getMeshNormal(int x, int z)
protected float getHeight(int x, int z, float xm, float zm)
public void lockMesh()
public void unlockMesh()
public float getOffsetAmount()
public Vector3f getStepScale()
public int getTotalSize()
public int getSize()
public Vector2f getOffset()
public void setOffset(Vector2f offset)
offset
- The new texture offset.public void setSize(int size)
size
- The new size.public void setTotalSize(int totalSize)
totalSize
- The new total size.public void setStepScale(Vector3f stepScale)
stepScale
- The new step scale.public void setOffsetAmount(float offsetAmount)
offsetAmount
- The new texture offset.public short getQuadrant()
public void setQuadrant(short quadrant)
quadrant
- The quadrant to set.public int getLod()
public void setLod(int lod)
public int getPreviousLod()
public void setPreviousLod(int previousLod)
protected int getLodLeft()
protected void setLodLeft(int lodLeft)
protected int getLodTop()
protected void setLodTop(int lodTop)
protected int getLodRight()
protected void setLodRight(int lodRight)
protected int getLodBottom()
protected void setLodBottom(int lodBottom)
public int collideWith(Collidable other, CollisionResults results) throws UnsupportedCollisionException
Collidable
collideWith
in interface Collidable
collideWith
in class Geometry
other
- The object to check collision againstresults
- Will contain the list of CollisionResult
s.
UnsupportedCollisionException
protected Vector3f worldCoordinateToLocal(Vector3f loc)
public void write(JmeExporter ex) throws java.io.IOException
write
in interface Savable
write
in class Geometry
java.io.IOException
public void read(JmeImporter im) throws java.io.IOException
read
in interface Savable
read
in class Geometry
java.io.IOException
public TerrainPatch clone()
Geometry
clone
in interface CloneableSmartAsset
clone
in class Geometry
Mesh.cloneForAnim()
protected void ensurePositiveVolumeBBox()
protected void cacheTerrainTransforms()
public Vector3f getWorldScaleCached()
public Vector3f getWorldTranslationCached()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |