Quantcast
Channel: Answers for "How can I automatically place grass and other details on my terrain to correspond with the splatmap?"
Viewing full articles (15 articles)
Browse article index
↧

Answer by duck

$
0
0

There isn't a quick way, but it is possible, however you'd have to use some of the undocumented terrain commands to read the Alphamap (splat map) data, and then construct a corresponding detail layers to match it.

The commands you'll need to use are:

// read all layers of the alphamap (the splatmap) into a 3D float array:
float[,,] alphaMapData = terrainData.GetAlphamaps(x, y, width, height);


// read all detail layers into a 3D int array:
int numDetails = terrainData.detailPrototypes.Length;
int [,,] detailMapData = new int[terrainData.detailWidth, terrainData.detailHeight, numDetails];
for (int layerNum=0; layerNum < numDetails; layerNum++) {
    int[,] detailLayer = terrainData.GetDetailLayer(x, y, width, height, layerNum);
}


// write all detail data to terrain data:
for (int n = 0; n < detailMapData.Length; n++)
{
    terrainData.SetDetailLayer(0, 0, n, detailMapData[n]);
}

// write alpha map data to terrain data:
terrainData.SetAlphamaps(x, y, alphaMapData);

In your case, you might not want to read the detail layers, you might just want to start with the new int[,,] detailMapData and populate it yourself based on whatever's in the alpha map. You'd then might want to wrap all this up in an editor script, so that you can call it from a menu or something.

Important things to note:

  • The detail map width and height might be different to the alpha map width and heigth (depending on your terrain settings).

  • These functions are undocumented. Any future updates of the unity engine might change or remove these functions from the API. This means your project may not work in future versions of the Unity editor, and webplayer builds may not work with future versions of the plugin.

↧

Viewing full articles (15 articles)
Browse article index

Latest Images

Trending Articles



Latest Images