Terrains are the basic building stone of all kinds of geological formations as well as buildings or other kinds of structures. Terrains are created usually in an external application devoted to 3D modeling and texturing but can also be done in editors if supported. In the Drag[en]gine visible terrain composes of two components involved: a Terrain and a Terrain Mesh.
Terrain Meshes contain the actual geometry information and are stored in separate Terrain Mesh files. This way they can be edited in an external application, loaded into the world editor and especially reused. Not all terrain meshes are suitable for reuse but especially static props or generic structures like caves or buildings can be reused this way without wasting a lot of disk space and memory. Terrain Meshes exist in two flavors depending on their usage: Triangle Meshes or Height Maps. A terrain mesh can only be one of the two and if both are used in the same terrain the behavior is undefined. For both kinds textures can be defined. Depending on the type the usage of the textures though differs. For each texture only the skin file path is stored. The actual texture definition is delivered by the Terrain Object which allows to reuse Terrain Meshes but with different texturing parameters if required.
Triangle Meshes are similar to Models and consist of a triangle soup. They are best used for buildings and other kinds of structure including static props and concave gological formations. The mesh is defined by a list of vertices and a list of faces. The vertices store the (x,y,z) position in local space. The faces store the vertex, normal and tangent indices and optionally a pair of texture coordinates for each of their corner. Only the total count of normals and tangents is stored in the triangle mesh itself. The actual normals and tangents are calculated by the Graphic Module. This is done by calculating first the normal and tangent for each face. Then the face normals and tangents are added to the ones indicated by the corner indices. Eventually the normals and tangents are normalized. In addition each face also stores the index of the texture used. Each face can have only one texture assigned which is also the case for Models. If you need complex texture work use Decals.
Height Maps are best used for landscapes especially ground, mountains, valleys and other vast geological formations. Height maps do not store triangles but use a height image requiring less disk space and memory than a Triangle Mesh with the same content. A Height Map is defined by a point count, size, scaling and a height image. The point count indicates the number of points in the X and Z direction of a uniformly spaced grid. The grid defaults to have 1m extend in each direction. Using the size parameter the Height Map is scaled up to have its extends match the size. The height for each grid point is taken from the height image. The base range of height values is -0.5m to 0.5m and is multiplied by the scaling factor. Hence the scaling factor represents half the height of the entire terrain. The height image is required to match in width and height with the point count and requires to have 1 component. The bit count is free and can be chosen according to the required precision. The top left pixel in the height image maps to the top left point in the Height Map ( which is along the negative X and positive Z axis ). The textures are used a bit differently here than in the Triangle Mesh case. All textures apply to all faces in the Height Map. Each texture is considered to be one material layer and are applied in the order they are defined.
Terrain Objects are used to display a Terrain Mesh in the world. They specify a position, orientation and scaling in addition to textures and modifiers. The position, orientation and scaling should not be changed during the existence of a terrain since they are considered to be static. Editors though can do this since speed is not a major concern there. Textures and modifiers on the other hand can be changed without speed penalty with the default Graphic Module.
Terrain Meshes only define what textures they use but the actual texture definition is supplied by the Terrain Object to allow for better reuse of geometry as well as allowing to change those parameters on the fly if required. Textures are assigned a Skin object. The used texture inside the Skin objects depends on the Terrain Mesh type ( currently only the first one is used but this is going to changed to allow for optimizations like LOD textures ). In addition to the Skin object projection parameters are provided. In contrary to Components there exists additional texture coordinate projection modes to avoid having to UV texture huge amount of geometry.
The projection type indicates how the texture coordinates are calculated from the underlaying Terrain Mesh. For Height Maps this is locked to planar projection no matter what you specify. The default is planar projection.
Planar
The texture coordinates are projected along the given projection axis. This is the typical projection type for ground type geometry and used by the Height Map. As long as the geometry does not get concave or has huge slopes this projection type produces good results and is easy to handle.
Cube
Cube mapping is best known from brush type mapping applications like Hammer ( WorldCraft back in Quake days ). This project type takes the normal of the face to texture into account. Image this mapping as if a cube with each side containing a planar projection of the texture is located around the face. The cube face the normal pokes through is used to texture the face. This mapping type is best used for buildings and other structures with flat and sharp walls.
UV
Sometimes automatic mapping simply does not work well at all like for example caves or other geological formations. In this case UV coordinates can be placed manually. Using this projection mode the UV coordinates stored in the Triangle Mesh are used. This is usually the way to go for complex geometry and is in general a good option if your 3D modeling application supports good automatic unwrapping.
If the projection type is planar a projection axis has to be designated along which the texture coordinates are projected. It would have been possible to allow any kind of direction but most of the time one of the 3 major axes ( in positive or negative direction ) are enough. If you need more complex projection the UV projection mode is a good solution. Possible values for the axis therefore are: X-Positive, X-Negative, Y-Positive, Y-Negative, Z-Positive, Z-Negative. The default is Y-Negative.
The default projection ( except for UV mapping ) maps the texture to a 1x1m grid. Using the projection parameters this can be altered. You can add an offset to the calculated coordinates, scale them or rotate them around the projection direction. These parameters are well known from brush mapping applications. Furthermore messing around with the values in the editor is better than trying to calculate the required values by hand.
Texture masks are only used by Height Maps. The mask image has to match in width and height with the point count of the Height Map and requires to have 1 component ( again the bit count is free ). The pixel values map the same way to the Height Map as the height image does and indicate the opacity of the material at this location. Values of 0 indicate full transparency while 1 indicates full opacity with values in between resulting in a linear blend. The number of layers is not restricted.
Height Modifiers are used by Height Maps and allow to dynamically alter the height at elected places. This allows to carve into the ground or raise it for additional gameplay effects. Height Modifiers are defined by a modifier image and a position. The position located the image on the Height Map and can be outside the grid. The modifier image has to be a 1 component image with any bit count as in the case of height images. The size of the image is unrestricted and indicates the number of grid points this image stretches across. Each pixel maps to one pixel measured relative to the position. All pixels outside the Height Map grid are discarded. This way you do not have to worry about clipping yourself unless you wish to do so. The scaling parameter works the same as in the Height Map and scales the pixel values from the range of -0.5m to 0.5m upwards. The height values obtained are added to the existing height of the Height Map. Therefore the order of Height Modifiers is irrelevant. For the majority of applications relative alteration of height values is required which is why this system has been adopted ( note: maybe there will be a flag to indicate if the value is added or set but currently only adding is supported ). The number of modifiers is not restricted and the can be also changed after being added to a terrain. They can though not be reused on another Terrain Object. Therefore one Height Modifier belongs to at most one Terrain Object.