Click or drag to resize
DigitalRuneTerrainTile Class
Defines the geometry (height, normals, holes) and material of a rectangular terrain region.
Inheritance Hierarchy
SystemObject
  DigitalRune.GraphicsTerrainTile

Namespace: DigitalRune.Graphics
Assembly: DigitalRune.Graphics (in DigitalRune.Graphics.dll) Version: 1.2.0.0 (1.2.1.14562)
Syntax
public class TerrainTile : IDisposable, 
	IInternalTerrainLayer

The TerrainTile type exposes the following members.

Constructors
  NameDescription
Public methodTerrainTile(IGraphicsService)
Initializes a new instance of the TerrainTile class with a default material.
Public methodTerrainTile(IGraphicsService, Material)
Initializes a new instance of the TerrainTile class with the specified material.
Top
Methods
  NameDescription
Public methodDispose
Releases all resources used by an instance of the TerrainTile class.
Protected methodDispose(Boolean)
Releases the unmanaged resources used by an instance of the TerrainTile class and optionally releases the managed resources.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodInvalidate
Invalidates the terrain tile in the data cached by the renderer.
Public methodInvalidate(TerrainLayer)
Invalidates the specified terrain layer in the data cached by the renderer.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodOnCreateMaterial
Called when a new TerrainTile is created without explicitly specifying a Material.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Properties
  NameDescription
Public propertyAabb
Gets the axis-aligned bounding box of the terrain tile. (Vertical min and max values are not set!)
Public propertyCellSize
Gets or sets the world space size of one cell in the height texture.
Public propertyHeightTexture
Gets or sets the height texture which stores absolute height values in the Red channel.
Public propertyHoleTexture
Gets or sets the hole texture which stores hole information in the Alpha channel.
Public propertyIsDisposed
Gets a value indicating whether this instance has been disposed of.
Public propertyLayers
Gets the terrain layers.
Public propertyMaterial
Gets or sets the material that is used to render the geometry of this terrain tile.
Public propertyMaterialInstance
Gets the material instance.
Public propertyNormalTexture
Gets or sets the normal texture which stores normal vectors.
Public propertyOriginX
Gets or sets the world space origin of this terrain tile on the x-axis.
Public propertyOriginZ
Gets or sets the world space origin of this terrain tile on the z-axis.
Public propertyTerrain
Gets the terrain that owns this terrain tile.
Public propertyWidthX
Gets the world space size of this terrain tile along the x-axis.
Public propertyWidthZ
Gets the world space size of this terrain tile along the z-axis.
Top
Remarks

A terrain is split into one or more tiles. The terrain tiles defines the geometry (height, normals, holes) of the terrain. Each tile has a set of material layers (dirt, grass, decals, roads) that define the appearance. The material layers are applied (blended) one after the other, which means that a layer can override previous layers.

Geometry textures:
The HeightTexture defines height values (absolute heights in world space) of the terrain.

NormalTexture contains the terrain normal vectors. This texture encodes the normal vectors like a standard "green-up" normal map, i.e. the world space +x component of the normal is stored in the red channel. The world space up (+y) component is stored in the blue channel. The negative world space z component is stored in the green channel.

HoleTexture defines holes in the terrain. The texture is used like an alpha mask texture. If the alpha channel contains 0, then there is a hole in the terrain.

Tile dimensions:
OriginX and OriginZ define the tile origin in world space - which corresponds to center of the first texel of the textures. CellSize defines the horizontal distance between two height values. The texture coordinate u is aligned with the positive x-axis. The texture coordinate v is aligned with the positive z-axis. This means, if the cell/texel size is 1 world space unit and the texture is 1025 x 513 texels large, then the terrain tile covers the area between (OriginX, *, OriginZ) and (OriginX + 1024, *, OriginZ + 512).

Mipmaps:
All textures should contain mipmaps. Ideally, the mipmaps are generated using 3 x 3 downsampling instead of the usual 2 x 2 downsampling. - Suitable textures can be created using the TerrainHelper class.

Miscellaneous:
Please notes that the normal vectors depend on the scale of the terrain. That means, if height values in the HeightTexture are scaled, then the normal map has to be updated too. The normal map also needs to be updated if the CellSize is changed! (This is not done automatically. Normal textures can be created using the TerrainHelper.)

OriginX and OriginZ should always be an integer multiple of the CellSize. For example, if the cell size is 0.5, valid origin values are -0.5, 0, 0.5, 1, etc.

Cache invalidation:
When the Terrain is used with the TerrainNode, then the terrain data is cached in clipmaps. Therefore, it is important to notify the terrain system when a tile or layer has changed and the cached data is invalid. When tiles or layers are added to or removed from the terrain, this happens automatically. But when the properties or the contents of tiles/layers are changed, the affected region needs to be invalidated explicitly by calling the appropriate Invalidate method of the Terrain or the TerrainTile. For example, when the contents of a height map is changed, the affected region on the terrain needs to be invalidated by calling Invalidate(Aabb) or Invalidate(TerrainTile).

See Terrain and TerrainLayer for more information.

See Also