Interface Terrain

All Known Implementing Classes:
TerrainGrid, TerrainQuad

public interface Terrain
Terrain can be one or many meshes comprising a (probably large) piece of land. Terrain is Y-up in the grid axis, meaning gravity acts in the -Y direction. Level of Detail (LOD) is supported and expected as terrains can get very large. LOD can also be disabled if you so desire, however some terrain implementations can choose to ignore useLOD(boolean). Terrain implementations should extend Node, or at least Spatial.
  • Method Details

    • getHeight

      float getHeight(Vector2f xz)
      Get the real-world height of the terrain at the specified X-Z coordinate.
      Parameters:
      xz - the X-Z world coordinate
      Returns:
      the height at the given point
    • getNormal

      Vector3f getNormal(Vector2f xz)
      Get the normal vector for the surface of the terrain at the specified X-Z coordinate. This normal vector can be a close approximation. It does not take into account any normal maps on the material.
      Parameters:
      xz - the X-Z world coordinate
      Returns:
      the normal vector at the given point
    • getHeightmapHeight

      float getHeightmapHeight(Vector2f xz)
      Get the heightmap height at the specified X-Z coordinate. This does not count scaling and snaps the XZ coordinate to the nearest (rounded) heightmap grid point.
      Parameters:
      xz - world coordinate
      Returns:
      the height, unscaled and uninterpolated
    • setHeight

      void setHeight(Vector2f xzCoordinate, float height)
      Set the height at the specified X-Z coordinate. To set the height of the terrain and see it, you will have to unlock the terrain meshes by calling terrain.setLocked(false) before you call setHeight().
      Parameters:
      xzCoordinate - coordinate to set the height
      height - that will be set at the coordinate
    • setHeight

      void setHeight(List<Vector2f> xz, List<Float> height)
      Set 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.
      Parameters:
      xz - a list of coordinates where the height will be set
      height - the heights that match the xz coordinates
    • adjustHeight

      void adjustHeight(Vector2f xzCoordinate, float delta)
      Raise/lower the height in one call (instead of getHeight then setHeight).
      Parameters:
      xzCoordinate - world coordinate to adjust the terrain height
      delta - +- value to adjust the height by
    • adjustHeight

      void adjustHeight(List<Vector2f> xz, List<Float> height)
      Raise/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.
      Parameters:
      xz - a list of coordinates where the height will be adjusted
      height - +- value to adjust the height by, that matches the xz coordinates
    • getHeightMap

      float[] getHeightMap()
      Get the heightmap of the entire terrain. This can return null if that terrain object does not store the height data. Infinite or "paged" terrains will not be able to support this, so use with caution.
    • getMaxLod

      int getMaxLod()
      This is calculated by the specific LOD algorithm. A value of one means that the terrain is showing full detail. The higher the value, the more the terrain has been generalized and the less detailed it will be.
    • setLocked

      void setLocked(boolean locked)
      Lock or unlock the meshes of this terrain. Locked meshes are un-editable but have better performance. This should call the underlying getMesh().setStatic()/setDynamic() methods.
      Parameters:
      locked - or unlocked
    • generateEntropy

      void generateEntropy(ProgressMonitor monitor)
      Pre-calculate entropy values. Some terrain systems support entropy calculations to determine LOD changes. Often these entropy calculations are expensive and can be cached ahead of time. Use this method to do that.
    • getMaterial

      Material getMaterial()
      Returns the material that this terrain uses. If it uses many materials, just return the one you think is best. For TerrainQuads this is sufficient. For TerrainGrid you want to call getMaterial(Vector3f) instead.
    • getMaterial

      Material getMaterial(Vector3f worldLocation)
      Returns 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.
      Parameters:
      worldLocation - the location, in world coordinates, of where we are interested in the underlying texture.
    • getTerrainSize

      int getTerrainSize()
      Used for painting to get the number of vertices along the edge of the terrain. This is an un-scaled size, and should represent the vertex count (i.e. the texture coord count) along an edge of a square terrain. In the standard TerrainQuad default implementation, this will return the "totalSize" of the terrain (512 or so).
    • getNumMajorSubdivisions

      int getNumMajorSubdivisions()