Vixen
02b45cc4
csharp
public static class TerrainWeightmap

One paint layer's coverage, as an 8-bit grayscale image.

Read the guide page for this →

Remarks

The weightmap half of [docs/plan/31 § The terrain panel]'s import and export. One layer at a time, one byte per sample, no header — the same bargain TerrainHeightmap makes for raw r16: bytes need no image library, so they live in the kernel, and PNG lives with the importer that already depends on Vixen.Core.Imaging.

⚠ An import restores the invariant rather than trusting the file. A weightmap painted in an external tool has no idea the other layers exist, so writing it verbatim leaves every sample it touched summing to something other than 255. What Import does is set the layer and let SetWeight take the difference from the rest — which is exactly what painting it by hand would have done.

⚠ And it resamples, for TerrainHeightmap's reason. A terrain of four 128-sample tiles is 509 samples across and a mask authored in an image editor is 512. The resample is bilinear and edge-to-edge, so the mask's corners land on the terrain's.

Methods (3)

  • public static long ByteCount(in TerrainDescription description)

    How many bytes a weightmap of a terrain is.

  • public static void Import(Terrain terrain, int layer, ReadOnlySpan<byte> bytes, int width, int height)

    Reads a grayscale mask into a paint layer.

  • public static int Export(Terrain terrain, int layer, Span<byte> destination)

    Writes a paint layer's coverage as a grayscale mask.

Used by (1)

  • TerrainWeightmapTestsVixen.Terrain.Tests