x


How can I automatically place grass and other details on my terrain to correspond with the splatmap?

I have a grass texture on certain parts of my terrain, and I want to have a grass detail everywhere that texture is. Is there a quick way to do this?

more ▼

asked Mar 03 '10 at 10:24 PM

John 2 gravatar image

John 2
11 1 1 2

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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.

more ▼

answered Mar 04 '10 at 11:43 AM

duck gravatar image

duck ♦♦
41k 92 148 415

how exactly would these commands be implemented?

Feb 21 '11 at 03:55 AM Bad Commander Filename
(comments are locked)
10|3000 characters needed characters left

You can do this with these scripts: http://lemuria.org/projects/wiki/TerrainTools

more ▼

answered Mar 19 '10 at 04:04 PM

chad gravatar image

chad
72 2 2 4

(comments are locked)
10|3000 characters needed characters left

where are these x,y coming from?

more ▼

answered Oct 30 '11 at 04:34 PM

bingomanatee gravatar image

bingomanatee
16 1 4 5

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5083
x2203
x1477
x109
x57

asked: Mar 03 '10 at 10:24 PM

Seen: 3818 times

Last Updated: Oct 30 '11 at 04:34 PM