Class TCastleTerrain

Unit

Declaration

type TCastleTerrain = class(TCastleTransform)

Description

Terrain.

Assign Data to provide some non-trivial height map, you can use there:

  • TCastleTerrainNoise to generate a height map using a dedicated algorithm for terrain generation, using smooth noise and special tricks to have smooth and heteregeneous terrain.

  • TCastleTerrainImage to generate a height map from intensities of a simple 2D image.

  • TCastleTerrainCombine to combine the above options in any expression (take minimum, maximum, sum, multiply).

The terrain starts as a standard mesh with a TPhysicalMaterialNode material. We apply on it a special affect to mix 4 layers, where each layer has a separate color and texture.

  • Each layer has a color (white by default), texture (none by default, that behaves like white) and UV scale. See TCastleTerrainLayer. Each layer is a property like Layer1, Layer2, Layer3, Layer4.

  • Only the RBG channels of textures matter, alpha is ignored.

  • Layer 1 is used for flat terrain on lower heights.

  • Layer 2 is used for steep terrain on lower heights.

  • Layer 3 is used for flat terrain on higher heights.

  • Layer 4 is used for steep terrain on higher heights.

  • The meaning of "lower" and "higher" heights is determined by Height1 and Height2. Below Height1 we show only layers 1+2, above Height2 we show only layers 3+4, between we show a smooth interpolation between them.

  • The meaning of "flat" and "steep" is determined by looking at terrain normals emphasized by SteepEmphasize.

  • The influence of this effect can be controlled by LayersInfluence.

Hierarchy

Overview

Fields

Public nested const LayersCount = 4;
Public nested const HeightsCount = 2;
Public nested const DefaultSubdivisions = 64;
Public nested const DefaultSize = 100;
Public nested const DefaultHeight1 = 4.0;
Public nested const DefaultHeight2 = 8.0;
Public nested const DefaultHeight: array [1..HeightsCount] of Single = ( DefaultHeight1, DefaultHeight2 );
Public nested const DefaultLayersInfluence = 1.0;
Public nested const DefaultSteepEmphasize = 2.0;

Methods

Protected procedure Loaded; override;
Public constructor Create(AOwner: TComponent); override;
Public destructor Destroy; override;
Public function PropertySections(const PropertyName: String): TPropertySections; override;

Properties

Public property Subdivisions: TVector2 read FSubdivisions write SetSubdivisions;
Public property Size: TVector2 read FSize write SetSize;
Published property RenderOptions: TCastleRenderOptions read GetRenderOptions;
Published property Layer1: TCastleTerrainLayer index 1 read GetLayer;
Published property Layer2: TCastleTerrainLayer index 2 read GetLayer;
Published property Layer3: TCastleTerrainLayer index 3 read GetLayer;
Published property Layer4: TCastleTerrainLayer index 4 read GetLayer;
Published property Data: TCastleTerrainData read FData write SetData;
Published property Triangulate: Boolean read FTriangulate write SetTriangulate default true;
Published property SteepEmphasize: Single read FSteepEmphasize write SetSteepEmphasize default DefaultSteepEmphasize;
Published property Height1: Single index 1 read GetHeight write SetHeight default DefaultHeight1;
Published property Height2: Single index 2 read GetHeight write SetHeight default DefaultHeight2;
Published property LayersInfluence: Single read FLayersInfluence write SetLayersInfluence default DefaultLayersInfluence;
Published property PreciseCollisions: Boolean read FPreciseCollisions write SetPreciseCollisions default true;
Published property SizePersistent: TCastleVector2Persistent read FSizePersistent ;
Published property SubdivisionsPersistent: TCastleVector2Persistent read FSubdivisionsPersistent ;

Description

Fields

Public nested const LayersCount = 4;

Texture layers to render this terrain.

Public nested const HeightsCount = 2;
 
Public nested const DefaultSubdivisions = 64;
 
Public nested const DefaultSize = 100;
 
Public nested const DefaultHeight1 = 4.0;
 
Public nested const DefaultHeight2 = 8.0;
 
Public nested const DefaultHeight: array [1..HeightsCount] of Single = ( DefaultHeight1, DefaultHeight2 );

Default values for Height1, Height2 etc.

Note: This array duplicates information in constants DefaultHeight1, DefaultHeight2 etc. Unfortunately we need the simple constants too, to specify properties default values like "default DefaultHeight0". Using "default DefaultHeight[0]" doesn't work in FPC (nor in Delphi, but that's because Delphi cannot handle Single defaults at all).

Public nested const DefaultLayersInfluence = 1.0;
 
Public nested const DefaultSteepEmphasize = 2.0;
 

Methods

Protected procedure Loaded; override;
 
Public constructor Create(AOwner: TComponent); override;
 
Public destructor Destroy; override;
 
Public function PropertySections(const PropertyName: String): TPropertySections; override;
 

Properties

Public property Subdivisions: TVector2 read FSubdivisions write SetSubdivisions;

How dense is the mesh. By default this is (DefaultSubdivisions,DefaultSubdivisions).

Changing this requires rebuild of terrain geometry, so it's costly. Avoid doing it at runtime.

Public property Size: TVector2 read FSize write SetSize;

Size of the generated shape and also the underlying range to query the TCastleTerrainNoise data for heights.

Note that changing this does not just scale the same geometry, if TCastleTerrainNoise is used for Data. The TCastleTerrainNoise uses the size you set here to determine what heights to query from a smooth noise. This has a nice effect that increasing the size adds additional pieces of terrain adjacent to the previous terrain, and the previous terrain shape is still visible at the same place.

Be sure to increase also Subdivisions when increasing this field, to keep seeing the same detail.

By default this is (DefaultSize,DefaultSize).

Changing this requires rebuild of terrain geometry, so it's costly. Avoid doing it at runtime.

Published property RenderOptions: TCastleRenderOptions read GetRenderOptions;

Options used to render the terrain. Can be used e.g. to toggle wireframe rendering.

Published property Layer1: TCastleTerrainLayer index 1 read GetLayer;

1st layer is displayed on lower heights and more flat terrain. See TCastleTerrain for a full description how do we mix layers.

Published property Layer2: TCastleTerrainLayer index 2 read GetLayer;

2nd layer is displayed on lower heights and more steep terrain. See TCastleTerrain for a full description how do we mix layers.

Published property Layer3: TCastleTerrainLayer index 3 read GetLayer;

3rd layer is displayed on higher heights and more flat terrain. See TCastleTerrain for a full description how do we mix layers.

Published property Layer4: TCastleTerrainLayer index 4 read GetLayer;

4th layer is displayed on higher heights and more steep terrain. See TCastleTerrain for a full description how do we mix layers.

Published property Data: TCastleTerrainData read FData write SetData;

Data for terrain heights. Changing this requires rebuild of terrain geometry, so it's costly. Avoid doing it at runtime.

Published property Triangulate: Boolean read FTriangulate write SetTriangulate default true;

Do we generate as a set of triangles, or ElevationGrid. TODO: this is internal decision, should behave always like true?

Changing this requires rebuild of terrain geometry, so it's costly. Avoid doing it at runtime.

Published property SteepEmphasize: Single read FSteepEmphasize write SetSteepEmphasize default DefaultSteepEmphasize;

How much should we emphasize the "steep" layers (2nd and 4th layers) at the expense of "flat" layers (1st and 3rd).

SteepEmphasize = 0.0 means that only "flat" layers (1 and 3) are visible. SteepEmphasize = 1.0 means that flat vs steep is a linear interpolation based on normal Y coordinate (but, since most terrains are more flat than steep, in practice the "flat" layers are still more visible). As SteepEmphasize goes toward infinity, the "steep" layers (2 and 4) dominate.

Published property Height1: Single index 1 read GetHeight write SetHeight default DefaultHeight1;

Below Height1 we only display layers 1+2. See TCastleTerrain for a description when do we show show layers and how this property affects it.

Published property Height2: Single index 2 read GetHeight write SetHeight default DefaultHeight2;

Above Height2 we only display layers 3+4. See TCastleTerrain for a description when do we show show layers and how this property affects it.

Published property LayersInfluence: Single read FLayersInfluence write SetLayersInfluence default DefaultLayersInfluence;

How much do the layers affect the final color. 0.0 means that layes are ignored, and the terrain look is a regular mesh look with TPhysicalMaterialNode. 1.0 means maximum influence, the layers determine the base color (TODO: and normals in the future).

Published property PreciseCollisions: Boolean read FPreciseCollisions write SetPreciseCollisions default true;

Resolve collisions precisely with the terrain geometry. When this is False we will only consider the terrain bounding box for collisions, which prevents moving on terrain nicely, picking terrain points with mouse etc. This sets TCastleSceneCore.Spatial.

Published property SizePersistent: TCastleVector2Persistent read FSizePersistent ;

Size that can be visually edited in Castle Game Engine Editor, Lazarus and Delphi. Normal user code does not need to deal with this, instead read or write Size directly.

See also
Size
Size of the generated shape and also the underlying range to query the TCastleTerrainNoise data for heights.
Published property SubdivisionsPersistent: TCastleVector2Persistent read FSubdivisionsPersistent ;

Subdivisions that can be visually edited in Castle Game Engine Editor, Lazarus and Delphi. Normal user code does not need to deal with this, instead read or write Subdivisions directly.

See also
Subdivisions
How dense is the mesh.

Generated by PasDoc 0.16.0.