Started to implement road generation.

This commit is contained in:
2015-05-20 11:26:46 +03:00
parent 11ca59d8bb
commit 7bd2b7b255
24 changed files with 616 additions and 119 deletions

View File

@ -26,7 +26,7 @@ public class TerrainGeneratorScript : MonoBehaviour
TerrainGenerator generator = new TerrainGenerator();
map = generator.Generate(TerrainWidth, TerrainHeight);
}
private Mesh GenerateWater()
{
Mesh water = new Mesh();
@ -51,7 +51,7 @@ public class TerrainGeneratorScript : MonoBehaviour
private IEnumerator GenerateMap()
{
// Wait for the map generation thread
// Generate terrain
foreach (var i in Task.RunAsync(GenerateTerrainThread))
yield return i;
@ -60,7 +60,7 @@ public class TerrainGeneratorScript : MonoBehaviour
terrainData.heightmapResolution = Mathf.Max(map.Height, map.Width) + 1;
terrainData.size = new Vector3(map.Width, map.Biome.Height, map.Height);
terrainData.SetDetailResolution(1024, 8);
terrainData.SetHeights(0, 0, map.Heights);
terrainData.SetHeights(0, 0, map.Heightmap);
terrainData.name = "Generated Terrain Data";
yield return null;
@ -120,21 +120,20 @@ public class TerrainGeneratorScript : MonoBehaviour
int iy = Mathf.RoundToInt(y_01 * TerrainHeight);
// Get height
float height = map.Heights[ix, iy] * terrainData.size.y;
float height = map.GetHeight(ix, iy);
// Get steepness
int safex = (ix == 0) ? 1 : ix;
int safey = (iy == 0) ? 1 : iy;
float dx = map.Heights[safex - 1, safey] * map.Biome.Height - height;
float dy = map.Heights[safex, safey - 1] * map.Biome.Height - height;
float dx = map.GetHeight(safex - 1, safey) - height;
float dy = map.GetHeight(safex, safey - 1) - height;
float steepness = dx * dx + dy * dy;
// Go through each texture layer
float[] weights = new float[terrainData.alphamapLayers];
float sum = 0;
// Go through each texture layer
for (int t = 0; t < terrainData.alphamapLayers; t++)
{
// Set up expression