Vixen
02b45cc4
csharp
public readonly record struct TerrainDescription

The shape of a terrain: how many tiles, how big they are, and what a height means.

Read the guide page for this →

Remarks

[docs/plan/31 § D2]. A value rather than an object, because it is the thing a create dialog is bound to and the thing a derived-cost readout is computed from — and because two terrains with the same shape should compare equal whatever their heights are.

⚠ TileSamples is a count of samples and must be a power of two, so a tile spans one less than a power of two quads. That is not a stylistic choice. Jolt's height field needs the sample count to be a multiple of its block size and needs the resulting block count to be a power of two, and it reports a violation by returning nothing at all — see PhysicsShapes.HeightField. Unreal states the same constraint from the other end, as section sizes that are "a power of two value minus one" quads.

The height range is the author's, not a constant. Unreal spends the same sixteen bits over a fixed −256…256 window whether the terrain is a dune field or the Himalayas; a 40 m landscape here gets 0.6 mm of vertical precision instead of 8 mm, for the same bytes.

Fields and properties (21)

  • public const int MinTileSamples

    The smallest tile a terrain can be made of, in samples.

  • public const int MaxTileSamples

    The largest tile, in samples.

  • public int TileSamples

    How many samples a tile is along each axis. A power of two.

  • public int TilesX

    How many tiles along X.

  • public int TilesZ

    How many tiles along Z.

  • public float MetresPerQuad

    How far apart two samples are, in metres.

  • public float MinHeight

    The height a stored sample of zero means, in metres.

  • public float MaxHeight

    The height a stored sample of MaxHeight means.

  • public static TerrainDescription Default

    A default terrain: four tiles of 127 quads at a metre, 200 m of vertical range.

  • public int TileQuads

    How many quads a tile spans along each axis.

  • public int SamplesX

    How many samples the whole terrain has along X.

  • public int SamplesZ

    How many samples the whole terrain has along Z.

  • public long SampleCount

    How many samples there are altogether.

  • public int TileCount

    How many tiles there are.

  • public float WidthX

    How wide the terrain is, in metres.

  • public float WidthZ

    How deep the terrain is, in metres.

  • public float HeightRange

    How much vertical range the sixteen bits are spread over, in metres.

  • public float MetresPerStep

    How many metres one step of a stored sample is.

  • public long HeightBytes

    How many bytes the heights occupy.

  • public long WeightBytesPerLayer

    How many bytes one weight layer occupies.

  • public bool IsValid

    Whether the description is one a terrain can be built from.

Methods (8)

  • public Vector3 PositionOf(int x, int z, ushort height)

    Where a sample sits, in the terrain's own space.

  • public float HeightOf(ushort height)

    What a stored sample means in metres.

  • public ushort StoreHeight(float metres)

    What a height in metres stores as.

  • public (int TileX, int TileZ, int LocalX, int LocalZ) TileOf(int x, int z)

    Which tile a sample belongs to, and where in that tile it sits.

  • public TerrainRect TilesOf(TerrainRect rect)

    Which tiles a rectangle of samples touches.

  • public TerrainRect SamplesOf(int tileX, int tileZ)

    Which samples a tile covers, its last row included.

  • public string? Validate()

    Why this description cannot be built, or null if it can.

  • public override string ToString()

    Renders the shape and what it costs.

Used by (59, showing 40)

  • TerrainVixen.Terrain
  • TerrainAtlasVixen.Terrain
  • TerrainAtlasTestsVixen.Terrain.Tests
  • TerrainDescriptionTestsVixen.Terrain.Tests
  • TerrainEditLayerVixen.Terrain
  • TerrainHeightmapVixen.Terrain
  • TerrainHeightmapFormatVixen.Terrain
  • TerrainHeightmapPngVixen.Terrain
  • TerrainHeightmapPngTestsVixen.Terrain.Tests
  • TerrainHeightmapTestsVixen.Terrain.Tests
  • TerrainHolesVixen.Terrain
  • TerrainLayerTestsVixen.Terrain.Tests
  • TerrainLodTestsVixen.Terrain.Tests
  • TerrainLodTreeVixen.Terrain
  • TerrainMipTestsVixen.Terrain.Tests
  • TerrainMipsVixen.Terrain
  • TerrainPaintVixen.Terrain
  • TerrainPaintTestsVixen.Terrain.Tests
  • TerrainPickVixen.Terrain
  • TerrainPickTestsVixen.Terrain.Tests
  • TerrainRendererVixen.Rendering.Terrain
  • TerrainRendererTestsVixen.Rendering.Terrain.Tests
  • TerrainResizeVixen.Terrain
  • TerrainResizeTestsVixen.Terrain.Tests
  • TerrainSamplesVixen.Terrain
  • TerrainSculptVixen.Terrain
  • TerrainSculptTestsVixen.Terrain.Tests
  • TerrainSplatTestsVixen.Rendering.Terrain.Tests
  • TerrainSplineVixen.Terrain
  • TerrainSplineTestsVixen.Terrain.Tests
  • TerrainStoreVixen.Terrain
  • TerrainStoreTestsVixen.Terrain.Tests
  • TerrainStreamerVixen.Rendering.Terrain
  • TerrainStreamingTestsVixen.Rendering.Terrain.Tests
  • TerrainStrokeVixen.Terrain
  • TerrainStrokeTestsVixen.Terrain.Tests
  • TerrainSurfaceVixen.Rendering.Terrain
  • TerrainSurfaceTestsVixen.Rendering.Terrain.Tests
  • TerrainTileSourceVixen.Rendering.Terrain
  • TerrainWeightStrokeVixen.Terrain