Version: 2020.2
Experimental: this API is experimental and might be changed or removed in the future.

PaintContext

class in UnityEngine.Experimental.TerrainAPI

切换到手册

描述

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

此类用于对可能跨多个地形瓦片的地形区域应用编辑操作。 PaintContext 可用于编辑高度贴图或泼溅贴图数据,也可用于以只读模式收集正常数据(不能写入法线,因为它们来自高度贴图)。

PaintContext 将计算每个地形上的相关区域,并将原始数据采集到单个 sourceRenderTarget 中。 随后编辑操作可以从 sourcerenderTarget 读取并将修改的数据写入 destinationRenderTarget 中。 应用编辑操作后,PaintContext 还可以将 destinationRenderTarget 中的已修改数据写回到每个地形,确保其间无缝接合。

使用 PaintContext 的最简单方法是通过 TerrainPaintUtility 中的 helper 函数:
TerrainPaintUtility.BeginPaintHeightmapTerrainPaintUtility.EndPaintHeightmapTerrainPaintUtility.BeginPaintTextureTerrainPaintUtility.EndPaintTextureTerrainPaintUtility.CollectNormalsTerrainPaintUtility.ReleaseContextResources

还可以通过成员函数更直接地使用 PaintContext。一般情况下,按以下顺序使用这些函数
1) 构造函数,PaintContext.CreateFromBounds - 构造一个 PaintContext 以及要编辑的目标地形和区域
2) PaintContext.CreateRenderTargets - 创建源和目标 RenderTargets
3) PaintContext.GatherHeightmapPaintContext.GatherAlphamapPaintContext.GatherNormals - 从地形瓦片读取到sourceRenderTarget
4) 应用编辑操作,从 sourceRenderTarget 读取,并写入 destinationRenderTarget
5) PaintContext.ScatterHeightmapPaintContext.ScatterAlphamap - 从 destinationRenderTarget 写入到地形瓦片中(可选)
6) PaintContext.Cleanup - 销毁 RenderTarget 资源(如果调用了 CreateRenderTargets 则需要)
7) PaintContext.ApplyDelayedActions - 应用任何执行成本高昂的更新的延迟操作


另请参阅: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 所定义区域中的地形上的纹理。
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961