Class DetailUtility
Functions for manipulating terrain details
Inherited Members
Namespace: UnityEditor .TerrainTools
Assembly: Unity.TerrainTools.Editor.dll
Syntax
public static class DetailUtility
Methods
GetDensityMapTexture(TerrainData, int)
Gets a TerrainData's detailLayer as a Texture2D
Declaration
public static Texture2D GetDensityMapTexture(TerrainData tData, int detailLayer = 0)
Parameters
Type | Name | Description |
---|---|---|
Terrain |
tData | a TerrainData object |
int | detailLayer | the detail layer to use |
Returns
Type | Description |
---|---|
Texture2D | Texture2D representing the grayscale values of the detail masks |
LoadDensityMap(Terrain, string, int)
Loads a saved density map for terrain
from folder
into detail layer detailLayer
Declaration
public static bool LoadDensityMap(Terrain terrain, string folderName, int detailLayer)
Parameters
Type | Name | Description |
---|---|---|
Terrain | terrain | Terrain object |
string | folderName | string folder path |
int | detailLayer | integer detail layer |
Returns
Type | Description |
---|---|
bool | True if the expected texture asset exists and can be applied, or false otherwise. |
LoadDensityMap(Terrain, DefaultAsset, int)
Loads a saved density map for terrain
from folder
into detail layer detailLayer
Declaration
public static bool LoadDensityMap(Terrain terrain, DefaultAsset folder, int detailLayer)
Parameters
Type | Name | Description |
---|---|---|
Terrain | terrain | Terrain object |
Default |
folder | DefaultAsset or string folder path |
int | detailLayer | integer detail layer |
Returns
Type | Description |
---|---|
bool | True if the expected texture asset exists and can be applied, or false otherwise. |
LoadDensityMaps(Terrain, string)
Given a the text path of an asset folder to seach, finds the detail maps corresponding
to terrain
and loads them into the corresponding detail channels of terrain
.
Declaration
public static void LoadDensityMaps(Terrain terrain, string folderName)
Parameters
Type | Name | Description |
---|---|---|
Terrain | terrain | a Terrain object |
string | folderName | an Asset folder containing textures |
LoadDensityMaps(Terrain, DefaultAsset)
Given a DefaultAsset folder
to seach, finds the density maps corresponding to
terrain
and loads them into the corresponding detail channels of terrain
.
Declaration
public static void LoadDensityMaps(Terrain terrain, DefaultAsset folder)
Parameters
Type | Name | Description |
---|---|---|
Terrain | terrain | a Terrain object |
Default |
folder | a DefaultAsset corresponding to Asset folder containing textures |
SaveAllDensityMaps(Terrain, string)
Save a detail density map for every prototype in the supplied terrain to folder
Declaration
public static void SaveAllDensityMaps(Terrain terrain, string folderName)
Parameters
SaveAllDensityMaps(Terrain, DefaultAsset)
Save a detail density map for every prototype in the supplied terrain to folder
Declaration
public static void SaveAllDensityMaps(Terrain terrain, DefaultAsset folder)
Parameters
Type | Name | Description |
---|---|---|
Terrain | terrain | |
Default |
folder |
SaveDensityMap(Terrain, DefaultAsset, int)
Saves a Texture2D representing the detail density in terrain
to the asset folder folder
Declaration
public static void SaveDensityMap(Terrain terrain, DefaultAsset folder, int detailLayer)
Parameters
Type | Name | Description |
---|---|---|
Terrain | terrain | A terrain object to save |
Default |
folder | An asset folder to receive saved assets |
int | detailLayer | The detail layer to save |
SetDensityMap(TerrainData, Material, int)
Use the supplied material to generate a detail layer map for the supplied TerrainData The material will be blitted to an 8-bit R8 RenderTarget of the same resolution as the TerrainData's detail layers. The material will be given references to the TerrainData's splatmap textures (referenced as "_Control0" and "_Control1" if present), and the heightmap (referenced as "_Height"). If instanced rendering is enabled, the material will also be given a reference to the TerrainData's normal map ("_Normal"). Existing detail arrays will be passed to the material as RenderTextures (referenced as "_Density#" where # is the detail layer number. The material can use or ignore these inputs as desired.
Declaration
public static void SetDensityMap(TerrainData tData, Material densityMaterial, int detailLayer = 0)
Parameters
Type | Name | Description |
---|---|---|
Terrain |
tData | (this) target TerrainData |
Material | densityMaterial | a material to blit |
int | detailLayer | the detail index of the details to scatter |
SetDensityMap(TerrainData, RenderTexture, int)
Sets a TerrainData's detail layer using the supplied RenderTextures This executes synchronously
Declaration
public static void SetDensityMap(TerrainData tData, RenderTexture rTexture, int detailLayer = 0)
Parameters
Type | Name | Description |
---|---|---|
Terrain |
tData | |
Render |
rTexture | |
int | detailLayer |
SetDensityMap(TerrainData, in Texture2D, int, bool)
Populates a TerrainData's detail layer using the red channel of the supplied texture as a density map. Bright texels translate to more detail instances, dark texels translate to fewer or none. By default, the texture will be resampled to the correct size for the TerrainData's detail array. If the optional allowResample parameter is passed as false, the method will throw an ArgumentException if the texture and detail resolutions don't match. This method will accept any Texture2D as an input, but for best results use a texture which is not saved with gamma or color correction.
Declaration
public static void SetDensityMap(TerrainData tData, in Texture2D texture, int detailLayer = 0, bool allowResample = true)
Parameters
Type | Name | Description |
---|---|---|
Terrain |
tData | the TerrainData to populate |
Texture2D | texture | a Texture2D. |
int | detailLayer | the detail layer to populate |
bool | allowResample | if true, resample the texture to fit the detail array. If false, accept only textures of the same dimensions as the detail array |
Exceptions
Type | Condition |
---|---|
Argument |
thrown if allowResample is false and the texture resolution does not match the detail array resolution |