class in UnityEngine.Experimental.TerrainAPI
可能跨多个相连地形瓦片的绘制操作的上下文。
此类用于对可能跨多个地形瓦片的地形区域应用编辑操作。
PaintContext 可用于编辑高度贴图或泼溅贴图数据,也可用于以只读模式收集正常数据(不能写入法线,因为它们来自高度贴图)。
PaintContext 将计算每个地形上的相关区域,并将原始数据采集到单个 sourceRenderTarget 中。
随后编辑操作可以从 sourcerenderTarget 读取并将修改的数据写入 destinationRenderTarget 中。
应用编辑操作后,PaintContext 还可以将 destinationRenderTarget 中的已修改数据写回到每个地形,确保其间无缝接合。
使用 PaintContext 的最简单方法是通过 TerrainPaintUtility 中的 helper 函数:
TerrainPaintUtility.BeginPaintHeightmap、TerrainPaintUtility.EndPaintHeightmap、TerrainPaintUtility.BeginPaintTexture、TerrainPaintUtility.EndPaintTexture、TerrainPaintUtility.CollectNormals 和 TerrainPaintUtility.ReleaseContextResources。
还可以通过成员函数更直接地使用 PaintContext。一般情况下,按以下顺序使用这些函数
1) 构造函数,PaintContext.CreateFromBounds - 构造一个 PaintContext 以及要编辑的目标地形和区域
2) PaintContext.CreateRenderTargets - 创建源和目标 RenderTargets
3) PaintContext.GatherHeightmap、PaintContext.GatherAlphamap、PaintContext.GatherNormals - 从地形瓦片读取到sourceRenderTarget
4) 应用编辑操作,从 sourceRenderTarget 读取,并写入 destinationRenderTarget
5) PaintContext.ScatterHeightmap、PaintContext.ScatterAlphamap - 从 destinationRenderTarget 写入到地形瓦片中(可选)
6) PaintContext.Cleanup - 销毁 RenderTarget 资源(如果调用了 CreateRenderTargets 则需要)
7) PaintContext.ApplyDelayedActions - 应用任何执行成本高昂的更新的延迟操作
另请参阅:TerrainPaintTool<T0>
| kNormalizedHeightScale | Unity 在内部使用此值将 [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 所定义区域中的地形上的纹理。 |