Documentation

Unity Engine

Download Unity

Unity Engine

GetHeightmapWeights(TerrainData, TerrainRegion, float, out RectInt)

Gets the weight that an edit of a region applies at each heightmap sample it covers.
Read time 1 minuteLast updated 22 days ago

Definition

GetHeightmapWeights(TerrainData, TerrainRegion, float, RectInt)

public static float[,] GetHeightmapWeights(TerrainData terrainData, TerrainRegion region, float falloff, out RectInt sampleRect)

Parameters

terrainData

The TerrainData whose heightmap grid to use.

The region.

falloff

The fraction of the region, from 0 to 1, over which the weight fades at its edge. See TerrainRegion.GetWeight.

sampleRect

The rectangle of heightmap samples that the weights cover.

Returns

Type

Description

float[,]The weights, from 0 to 1, indexed [z, x] from the corner of
sampleRect
, as TerrainData.GetHeights returns heights.

Remarks

These are the weights that TerrainEditUtility.SculptHeights applies with the same falloff and no blend distance: the region is widened to the heightmap cells it crosses in the same way, and sample (x, z) of the heightmap lies at (x, z) * size / (heightmapResolution - 1). A sample with a weight of 0 lies outside the region. Read the heights of the same rectangle with TerrainData.GetHeights.