Terrain To Mesh
  • Terrain To Mesh
  • Quick Start
  • Editor Window Settings
    • Mesh
    • Material
    • Objects
    • Save
  • Update Splatmap Shader
  • Run-time API
    • TerrainToMesh
      • ExportMesh
      • ExportTerrainLayers
      • ExportSplatmapMaterial
      • ExportSplatmapTextures
      • HasHoles
      • ExportHolesmapTexture
      • ExportBasemapDiffuseTexture
      • ExportBasemapNormalTexture
      • ExportBasemapMaskTexture
      • ExportBasemapOcclusionTexture
      • ExportGrassTextures
      • ExportGrassAtlasTexture
      • HasPrototypes
      • CountPrototypes
      • ExportPrototypes
    • TerrainToMeshUtilities
      • GenerateGrassMesh
      • GenerateEdgeFallTexture
      • ConvertMeshToOBJ
      • ConvertMeshToOBJAndSaveToFile
      • ConvertMeshToOBJAndAppendToFile
      • GetDefaultMaterial
      • GetDefaultShader
      • GetDefaultShaderProperty
      • SetupDefaultMaterial
      • SetupAlphaCutoutForDefaultMaterial
      • ConvertPrototypesToTreeGameObjects
      • ConvertPrototypesToGrassGameObjects
      • ConvertPrototypesToGrassMeshes
      • ConvertPrototypesToDetailMeshGameObjects
      • ConvertPrototypesToDetailMeshes
      • CalculateExportedMeshVertexCount
      • SetMeshPivotPoint
    • TerrainToMeshEdgeFall
    • TerrainToMeshPrototype
    • TerrainToMeshConversionDetails
  • Help & Contact
Powered by GitBook
On this page
PreviousExportHolesmapTextureNextExportBasemapNormalTexture

Last updated 1 month ago

Export Basemap Diffuse Texture

Texture2D ExportBasemapDiffuseTexture(int resolution, bool saveHolesmapInAlphaChannel, bool enableHeightBasedBlend = false, float heightTransition = 0)

Bakes all terrain paint textures Diffuse maps into one Basemap texture.

saveHolesmapInAlphaChannel - If set to true, texture's alpha channel will contain holesmap's cutout values.

By default object doesn't use Height Based Blend feature. This is optional feature for the terrain material and if converted terrain uses it, it needs to be manually set inside ExportBasemapDiffuseTexture method:

Material's height based blend values can be read using Terrain.GetMaterialHeightBasedBlendValues method.


Texture2D[] ExportBasemapDiffuseTexture(int resolution, bool saveHolesmapInAlphaChannel, int splitCountHorizontal, int splitCountVertical, bool enableHeightBasedBlend = false, float heightTransition = 0)

Splits terrain into 2D grid by splitCountHorizontal and splitCountVertical amount and for each chunk calculates BasemapDiffuse texture.

This method can be used in combination with multi-chunk mesh exporter, in this case index of a mesh in 2D grid array and Basemap texture's, are the same.

//Example of generating multi-chunk meshes (8x8 grid) with UVs per chunk and
//exporting Basemap Diffuse textures for each one. 

bool calculateUVsPerChunck = true;
int vertexCount = 100;
int textureResolution = 2048;
int splitCountHorizontal = 8;
int splitCountVertical = 8;

Mesh[] meshes = terrainData.TerrainToMesh().ExportMesh(vertexCount, vertexCount, splitCountHorizontal, splitCountVertical, calculateUVsPerChunck);
Texture2D[] diffuseMaps = terrainData.TerrainToMesh().ExportBasemapDiffuseTexture(textureResolution, false, splitCountHorizontal, splitCountVertical);

for(int i = 0; i < meshes.Length; i++)
{
    GameObject go = new GameObject();

    //Assign generated terrain mesh
    go.AddComponent<MeshFilter>().sharedMesh = meshes[i];


    //Creating material using default shader
    Material material = new Material(TerrainToMeshUtilities.GetDefaultShader());

    //Setting up material to use diffuse texture
    TerrainToMeshUtilities.SetupDefaultMaterial(material, diffuseMaps[i], false, null, null, null);


    //Assign material
    go.AddComponent<MeshRenderer>().sharedMaterial = material;
}

Texture2D ExportBasemapDiffuseTexture(int resolution, bool saveHolesmapInAlphaChannel, int splitCountHorizontal, int splitCountVertical, int splitColumnIndex, int splitRowIndex, bool enableHeightBasedBlend = false, float heightTransition = 0)

Splits terrain into 2D grid by splitCountHorizontal and splitCountVertical amount and calculates BasemapDiffuse texture for chunk with index splitColumnIndex and splitRowIndex.

If texture exporter methods are used in the run-time builds, make sure Terrain Textures Exporter shader is inside Always Included Shaders array of the

Graphics Settings
TerrainData