Vixen
02b45cc4
csharp
public sealed class TerrainSamples

One grid of 16-bit height samples covering a whole terrain.

Read the guide page for this →

Remarks

One grid, not one per tile, and that is what makes [docs/plan/31 § D2]'s warning structural. The warning says tile boundaries are shared vertices and that storing them twice is how a terrain grows a seam which appears only after somebody edits one side. Storing the terrain as an array of per-tile grids makes that a rule every tool has to remember; storing it as one grid that tiles are windows into makes it impossible to break, because there is only ever one copy of the sample to write.

The cost is that a tile is not contiguous, which matters to exactly one consumer — the thing uploading a tile's texture, which copies row by row. That is a loop in the renderer rather than a class of bug in every tool.

16-bit unsigned over the description's own range, so the quantum is MetresPerStep and a 40 m landscape gets sub-millimetre precision rather than the centimetres a fixed window would give it.

Fields and properties (7)

  • public const int MaxHeight

    The largest a stored sample can be.

  • public TerrainDescription Description

    The terrain's shape.

  • public int Width

    How many samples there are along X.

  • public int Height

    How many samples there are along Z.

  • public TerrainRect Bounds

    Everything covered by the grid.

  • public Span<ushort> Span

    The raw samples, row-major in Z then X.

  • public ushort this[int x, int z]

    One sample.

Methods (7)

  • public TerrainSamples(TerrainDescription description, ushort fill = 0)

    Allocates a grid, every sample at .

  • public float MetresAt(int x, int z)

    One sample, in metres.

  • public int Read(TerrainRect rect, Span<ushort> destination)

    Copies a rectangle out.

  • public void Write(TerrainRect rect, ReadOnlySpan<ushort> source)

    Copies a rectangle in.

  • public (ushort Minimum, ushort Maximum) RangeOf(TerrainRect rect)

    The lowest and highest sample in a rectangle.

  • public TerrainSamples Clone()

    A copy of this grid.

  • public void FillCollisionSamples(int tileX, int tileZ, TerrainHoles? holes, float noCollision, Span<float> destination)

    Fills a tile's samples for a physics height field, in metres, with holes punched out.

Used by (19)

  • TerrainVixen.Terrain
  • TerrainDescriptionVixen.Terrain
  • TerrainDescriptionTestsVixen.Terrain.Tests
  • TerrainHeightmapPngVixen.Terrain
  • TerrainHeightmapPngTestsVixen.Terrain.Tests
  • TerrainHeightmapTestsVixen.Terrain.Tests
  • TerrainLayerTestsVixen.Terrain.Tests
  • TerrainLodTreeVixen.Terrain
  • TerrainPickVixen.Terrain
  • TerrainPickTestsVixen.Terrain.Tests
  • TerrainResizeTestsVixen.Terrain.Tests
  • TerrainSculptVixen.Terrain
  • TerrainSculptTestsVixen.Terrain.Tests
  • TerrainStoreTestsVixen.Terrain.Tests
  • TerrainStrokeTestsVixen.Terrain.Tests
  • GroundVixen.Editor.Terrain.Tests
  • SculptSessionTestsVixen.Editor.Terrain.Tests
  • TerrainEditTestsVixen.Editor.Terrain.Tests
  • TerrainLayerCommandTestsVixen.Editor.Terrain.Tests