Beispiel #1
0
        public static bool AddHeight(Terrain t, TerrainHeightSettings settings)
        {
            int heightMapWidth = t.terrainData.heightmapWidth;

            float[,] masterData = t.terrainData.GetHeights(0, 0, heightMapWidth, heightMapWidth);
            int asize = t.terrainData.alphamapWidth;

            float[,,] alphaData = t.terrainData.GetAlphamaps(0, 0, asize, asize);

            float tx = 0;
            float tz = 0;

            Vector3 pos = Vector3.zero;

            for (int x = 0; x < heightMapWidth; x++)
            {
                tx = (float)x / (float)(heightMapWidth - 1);
                for (int y = 0; y < heightMapWidth; y++)
                {
                    tz = 1 - (float)y / (float)(heightMapWidth - 1);
                }
            }

            t.terrainData.SetHeights(0, 0, masterData);
            return(true);
        }
Beispiel #2
0
        public static bool Setup(Terrain t, TerrainHeightSettings settings)
        {
            var t1 = settings.diffSettings.From;
            var t2 = settings.diffSettings.To;

            int heightMapWidth = t.terrainData.heightmapWidth;

            float[,] masterData = t.terrainData.GetHeights(0, 0, heightMapWidth, heightMapWidth);
            int asize = t.terrainData.alphamapWidth;

            float[,,] alphaData = t.terrainData.GetAlphamaps(0, 0, asize, asize);

            float tx = 0;
            float tz = 0;

            Vector3 pos = Vector3.zero;

            for (int x = 0; x < heightMapWidth; x++)
            {
                tx = (float)x / (float)(heightMapWidth - 1);
                for (int y = 0; y < heightMapWidth; y++)
                {
                    tz = 1 - (float)y / (float)(heightMapWidth - 1);

                    float diff = t2.GetPixelBilinear(tx, tz).r - t1.GetPixelBilinear(tx, tz).r;
                    if (settings.diffSettings.Additive)
                    {
                        masterData[x, y] = masterData[x, y] + diff;
                    }
                    else
                    {
                        masterData[x, y] = masterData[x, y];
                    }
                }
            }

            t.terrainData.SetHeights(0, 0, masterData);
            return(true);
        }