Added noise testing, created connected tiles

This commit is contained in:
TAASONI3
2023-11-26 00:13:14 +01:00
parent 509c207d32
commit 3640f8a21f
11 changed files with 1228 additions and 387 deletions

View File

@@ -17,7 +17,7 @@ public class NoiseGenerator
else{
applyNormalNoise(tile, map);
}*/
applyNormalNoise(tile, map);
applyNewNoise(tile, map);
}
@@ -46,6 +46,52 @@ public class NoiseGenerator
tile.GetComponent<Tile>().setType(tiletype);
}
private void applyNewNoise(GameObject tile, Dictionary<Vector3, GameObject> map)
{
//resetMesh(tile);
Mesh mesh = tile.GetComponent<MeshFilter>().mesh;
Vector3[] vertices = mesh.vertices;
float[] samples;
Color32[] colors;
Color32 low;
Color32 high;
string tiletype = "";
samples = calculateBasicSamples(tile);
low = new Color32(0, 150, 0, 255);
high = new Color32(0, 110, 20, 255);
float lowestValue = 10;
float highestValue = 0;
for (int i = 0; i < samples.Length; i++)
{
if (lowestValue > samples[i])
{
lowestValue = samples[i];
}
if (highestValue < samples[i])
{
highestValue = samples[i];
}
}
float modifier = highestValue - lowestValue;
colors = new Color32[samples.Length];
for (int i = 0; i < samples.Length; i++)
{
colors[i] = Color32.Lerp(low, high, (1 / modifier) * (samples[i] - lowestValue));
}
for (int i = 0; i < samples.Length; i++)
{
vertices[i].y = samples[i] * 3;
}
applyMesh(tile, vertices, mesh, colors);
tile.GetComponent<Tile>().setType(tiletype);
}
private void applyNormalNoise(GameObject tile, Dictionary<Vector3, GameObject> map)
{
//resetMesh(tile);
@@ -92,7 +138,7 @@ public class NoiseGenerator
high = new Color32(0, 185, 0, 255);
tiletype = "Plane";
}
float lowestValue = 10;
float highestValue = 0;
@@ -146,18 +192,16 @@ public class NoiseGenerator
float[] samples = new float[vertices.Length];
for (int i = 0; i < vertices.Length; i++)
{
if (vertices[i].x != 5 && vertices[i].z != 5 && vertices[i].x != -5 && vertices[i].z != -5)
{
float xCord = tile.GetComponent<Tile>().getPosition().x + vertices[i].x / (vertices.Length - 1) * 10;
float yCord = tile.GetComponent<Tile>().getPosition().z + vertices[i].z / (vertices.Length - 1) * 10;
float sample = Mathf.PerlinNoise(xCord, yCord) - 0.1f * rand.Next(0, 6);
samples[i] = sample;
}
float xCord = tile.GetComponent<Tile>().getPosition().x + vertices[i].x / (vertices.Length - 1) * 10;
float yCord = tile.GetComponent<Tile>().getPosition().z + vertices[i].z / (vertices.Length - 1) * 10;
float sample = Mathf.PerlinNoise(xCord, yCord) - 0.1f * rand.Next(0, 6);
samples[i] = sample;
}
return samples;
}
private float[] calculateSamplesCity(GameObject tile){
private float[] calculateSamplesCity(GameObject tile)
{
Mesh mesh = tile.GetComponent<MeshFilter>().mesh;
Vector3[] vertices = mesh.vertices;
float[] samples = new float[vertices.Length];
@@ -209,7 +253,7 @@ public class NoiseGenerator
Vector3[] vertices = mesh.vertices;
float[] samples = calculateBasicSamples(tile);
bool isVertical = (rand.Next(0,2) == 0 ? true : false);
bool isVertical = (rand.Next(0, 2) == 0 ? true : false);
int startX = 0;
int startZ = 0;
@@ -260,9 +304,9 @@ public class NoiseGenerator
{
for (int k = 0; k < vertices.Length; k++)
{
if (Mathf.Round(vertices[k].x) == randX+i && Mathf.Round(vertices[k].z) == randZ+j)
if (Mathf.Round(vertices[k].x) == randX + i && Mathf.Round(vertices[k].z) == randZ + j)
{
samples[k] = samples[k] - rand.Next(1,3) - 0.25f * rand.Next(0,4);
samples[k] = samples[k] - rand.Next(1, 3) - 0.25f * rand.Next(0, 4);
break;
}
}
@@ -289,7 +333,7 @@ public class NoiseGenerator
result = result + "\"vertices\": {\r\n";
for (int i = 0; i < vertices.Length; i++)
{
result = result + FileHandler.generateJSON("vertice"+i, "\"" + vertices[i].x + "/" + vertices[i].y + "/" + vertices[i].z + "\"");
result = result + FileHandler.generateJSON("vertice" + i, "\"" + vertices[i].x + "/" + vertices[i].y + "/" + vertices[i].z + "\"");
if (i < vertices.Length - 1)
{
result = result + ",\r\n";
@@ -318,7 +362,7 @@ public class NoiseGenerator
Vector3[] vertices = new Vector3[verticeTokens.Count];
JToken current;
string[] parts;
for(int i = 0; i < colorTokens.Count;i++)
for (int i = 0; i < colorTokens.Count; i++)
{
current = colorTokens[i];
parts = current.Value<string>().Split('/');