Version: 2022.3

PaintContext

class in UnityEngine.TerrainTools

切换到手册

描述

可能跨多个相连地形瓦片的绘制操作的上下文。

This class is used to apply an edit operation to an area of Terrain that may span multiple Terrain tiles. A PaintContext may be used to edit heightmap or splatmap data, and may also be used to gather normal data in read-only mode (you cannot write to normals, because they are derived from the heightmap).

A PaintContext will calculate the relevant regions on each Terrain, and collect the original data into a single sourceRenderTarget. Your edit operation can then read from sourcerenderTarget, and write the modified data to destinationRenderTarget. Once you have applied your edit operation, the PaintContext can also write the modified data in destinationRenderTarget back to each Terrain, ensuring no seams between them.

The simplest way to use a PaintContext is through the helper functions in TerrainPaintUtility:
TerrainPaintUtility.BeginPaintHeightmap, TerrainPaintUtility.EndPaintHeightmap, TerrainPaintUtility.BeginPaintTexture, TerrainPaintUtility.EndPaintTexture, TerrainPaintUtility.CollectNormals and TerrainPaintUtility.ReleaseContextResources.

You can also use PaintContext more directly through its member functions. In general, they are used in the following order:
1) Constructor, PaintContext.CreateFromBounds - Construct a PaintContext with a target Terrain and a region to edit
2) PaintContext.CreateRenderTargets - Create the source and destination RenderTargets
3) PaintContext.GatherHeightmap, PaintContext.GatherAlphamap, PaintContext.GatherNormals - Read from Terrain tiles into sourceRenderTarget
4) Apply editing operations, reading from sourceRenderTarget, and writing to destinationRenderTarget
5) PaintContext.ScatterHeightmap, PaintContext.ScatterAlphamap - Write from destinationRenderTarget into Terrain tiles (optional)
6) PaintContext.Cleanup - Destroy RenderTarget resources (required if you call CreateRenderTargets)
7) PaintContext.ApplyDelayedActions - Apply any delayed actions that perform expensive updates


See Also: TerrainPaintTool<T0>

静态变量

kNormalizedHeightScaleUnity 在内部使用此值将 [0, 1] 高度值变换为纹素值(存储在 TerrainData.heightmapTexture 中)。

变量

destinationRenderTexture(只读)写入编辑操作以修改数据的 RenderTexture。
heightWorldSpaceMin此 PaintContext 在世界空间中接触的所有地形瓦片的最小高度。
heightWorldSpaceSize此 PaintContext 在世界空间中接触的所有地形瓦片的高度范围(从最小值到最大值)。
oldRenderTexture(只读)调用 CreateRenderTargets 时的 RenderTexture.active 值。
originTerrain(只读)用于构建 PaintContext 的地形。
pixelRect(只读)此 PaintContext 代表的像素矩形。
pixelSize(只读)PaintContext 像素的大小(采用地形单位,正如 originTerrain 所定义。)
sourceRenderTexture(只读)用于存储地形瓦片原始数据的渲染目标。
targetTextureHeight(只读)目标地形纹理的高度。这是单个地形的分辨率。
targetTextureWidth(只读)目标地形纹理的宽度。这是单个地形的分辨率。
terrainCount(只读)此 PaintContext 中的地形瓦片数量。

构造函数

PaintContext创建新的 PaintContext,从而编辑 pixelRect 所定义区域中的地形上的目标纹理。

公共函数

Cleanup释放此 PaintContext 的已分配资源。
CreateRenderTargets创建 sourceRenderTexture 和 /destinationRenderTexture/。
Gather将用户指定的纹理数据收集到 sourceRenderTexture 中。
GatherAlphamap将 Alpha 贴图信息收集到 sourceRenderTexture 中。
GatherHeightmap将高度贴图信息收集到 sourceRenderTexture 中。
GatherHoles将地形孔洞信息收集到 sourceRenderTexture 中。
GatherNormals将法线信息收集到 sourceRenderTexture 中。
GetClippedPixelRectInRenderTexturePixels相对于 PaintContext 渲染纹理,检索地形的已裁剪像素矩形。
GetClippedPixelRectInTerrainPixels检索地形的已裁剪像素矩形。
GetTerrain从 PaintContext 检索地形。
Scatter通过将修改复制回用户为源地形瓦片指定的 RenderTextures,应用已编辑的 PaintContext。
ScatterAlphamap通过将修改复制回源地形瓦片,应用已编辑的 Alpha 贴图 PaintContext。
ScatterHeightmap通过将修改复制回源地形瓦片,应用已编辑的高度贴图 PaintContext。
ScatterHoles通过将修改复制回源地形瓦片,应用已编辑的地形孔洞 PaintContext。

静态函数

ApplyDelayedActions刷新由 PaintContext 高度贴图和 Alpha 贴图修改项创建的延迟操作。
CreateFromBounds构造一个 PaintContext 以用于编辑 boundsInTerrainSpace 和 extraBorderPixels 所定义区域中的地形上的纹理。