vkmEngine 1.0.15
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
Vkm::Engine::TerrainBrush Namespace Reference

The edits a brush makes to a terrain, one dab at a time: raise, smooth and flatten its heights, paint a layer's share, and grow or thin a plant layer. More...

Classes

struct  Dab
 One application of a brush: where, how wide, how much. More...
struct  Region
 Grid vertices [i0, i1] by [j0, j1], inclusive: what a dab touched. More...

Functions

float falloff (const Dab &dab, float distance)
 How much of a dab's effect reaches distance from its centre.
Region reach (const TerrainAsset &terrain, const Dab &dab)
 The grid vertices within dab, clamped to terrain's grid.
bool hit (const TerrainAsset &terrain, const glm::vec3 &origin, const glm::vec3 &direction, float range, float &t)
 Where a ray first meets terrain's surface, over its grid.
Region raise (TerrainAsset &terrain, const Dab &dab, float metres)
 Raise the heights under dab, metres at its centre; negative lowers.
Region smooth (TerrainAsset &terrain, const Dab &dab)
 Pull each height under dab toward its neighbours' mean.
Region flatten (TerrainAsset &terrain, const Dab &dab, float height)
 Pull each height under dab toward height.
Region paint (TerrainAsset &terrain, const Dab &dab, uint32_t layer)
 Move each vertex's layer shares under dab toward all of layer.
Region grow (TerrainAsset &terrain, const Dab &dab, uint32_t foliage, float target)
 Move the density of plant layer foliage under dab toward target.

Detailed Description

The edits a brush makes to a terrain, one dab at a time: raise, smooth and flatten its heights, paint a layer's share, and grow or thin a plant layer.

Each changes the asset in place and returns the grid vertices it touched; the caller commits the asset (ResourceManager::commit), which redraws the touched chunks and rebuilds the terrain's collider and plants. A dab's effect fades from its centre to its rim, so strokes made of many dabs blend.

Function Documentation

◆ falloff()

float Vkm::Engine::TerrainBrush::falloff ( const Dab & dab,
float distance )

How much of a dab's effect reaches distance from its centre.

Parameters
dabThe dab.
distanceMetres from its centre.
Returns
1 within its hard core, falling smoothly to 0 at its radius.

◆ reach()

Region Vkm::Engine::TerrainBrush::reach ( const TerrainAsset & terrain,
const Dab & dab )

The grid vertices within dab, clamped to terrain's grid.

Parameters
terrainThe terrain.
dabThe dab.
Returns
Their region; empty when the dab misses the grid.

◆ hit()

bool Vkm::Engine::TerrainBrush::hit ( const TerrainAsset & terrain,
const glm::vec3 & origin,
const glm::vec3 & direction,
float range,
float & t )

Where a ray first meets terrain's surface, over its grid.

Marched a half grid step at a time, then narrowed to the crossing, so a ray grazing a ridge thinner than that may pass it.

Parameters
terrainThe terrain.
originLocal metres.
directionUnit, local.
rangeMetres along it to look.
[out]tMetres along it to the surface; untouched on false.
Returns
False when it meets none within range.

◆ raise()

Region Vkm::Engine::TerrainBrush::raise ( TerrainAsset & terrain,
const Dab & dab,
float metres )

Raise the heights under dab, metres at its centre; negative lowers.

Parameters
terrainThe terrain.
dabWhere.
metresHow far its centre moves.
Returns
What it touched.

◆ smooth()

Region Vkm::Engine::TerrainBrush::smooth ( TerrainAsset & terrain,
const Dab & dab )

Pull each height under dab toward its neighbours' mean.

Parameters
terrainThe terrain.
dabWhere; its strength is the share of the way each height moves.
Returns
What it touched.

◆ flatten()

Region Vkm::Engine::TerrainBrush::flatten ( TerrainAsset & terrain,
const Dab & dab,
float height )

Pull each height under dab toward height.

Parameters
terrainThe terrain.
dabWhere; its strength is the share of the way each height moves.
heightLocal metres: the level a path or a plot is cut to.
Returns
What it touched.

◆ paint()

Region Vkm::Engine::TerrainBrush::paint ( TerrainAsset & terrain,
const Dab & dab,
uint32_t layer )

Move each vertex's layer shares under dab toward all of layer.

The shares still add up to 255 after.

Parameters
terrainThe terrain.
dabWhere; its strength is the share of the way each vertex moves.
layerBelow MaterialAsset::MAX_LAYERS.
Returns
What it touched.

◆ grow()

Region Vkm::Engine::TerrainBrush::grow ( TerrainAsset & terrain,
const Dab & dab,
uint32_t foliage,
float target )

Move the density of plant layer foliage under dab toward target.

Gives the layer a density map first if it has none.

Parameters
terrainThe terrain.
dabWhere; its strength is the share of the way each vertex moves.
foliageBelow terrain.foliage.size().
target0 thins it out, 1 grows it full.
Returns
What it touched.