/* private Vector3[] GetVertives() * { * int sum = Mathf.FloorToInt((segment.x + 1) * (segment.y + 1)); * float w = size.x / segment.x; * float h = size.y / segment.y; * * int index = 0; * GetUV(); * GetTriangles(); * vertives = new Vector3[sum]; * for (int i = 0; i < segment.y + 1; i++) * { * for (int j = 0; j < segment.x + 1; j++) * { * float tempHeight = 0; * if (heightMap != null) * { * tempHeight = GetHeight(heightMap, uvs[index]); * } * vertives[index] = new Vector3(j * w, tempHeight, i * h); * index++; * } * } * return vertives; * } */ /* private Vector3[] GetVertives()//texture * { * int sum = Mathf.FloorToInt((segment.x + 1) * (segment.y + 1)); * float w = size.x / segment.x; * float h = size.y / segment.y; * * int index = 0; * GetUV(); * GetTriangles(); * vertives = new Vector3[sum]; * Vector3 point00 = new Vector3(-0.5f, -0.5f); * Vector3 point10 = new Vector3(0.5f, -0.5f); * Vector3 point01 = new Vector3(-0.5f, 0.5f); * Vector3 point11 = new Vector3(0.5f, 0.5f); * * * * Random.seed = 42; * * * for (int i = 0; i < segment.y + 1; i++) * { * for (int j = 0; j < segment.x + 1; j++) * { * float tempHeight = 0; * // if ((i+j)%5 == 0) * { * * tempHeight =Mathf.Abs (heightMap.GetPixel(i , j ).r -0.5f)*2* 10;// * * } * vertives[index] = new Vector3(j * w, tempHeight, i * h); * index++; * } * } * return vertives; * } */ /* private Vector3[] GetVertives()//perlin * { * * * * int sum = Mathf.FloorToInt((segment.x + 1) * (segment.y + 1)); * float w = size.x / segment.x; * float h = size.y / segment.y; * * int index = 0; * GetUV(); * GetTriangles(); * vertives = new Vector3[sum]; * * * int resolution = 256; * Vector3 point00 = new Vector3(-0.5f, -0.5f); * Vector3 point10 = new Vector3(0.5f, -0.5f); * Vector3 point01 = new Vector3(-0.5f, 0.5f); * Vector3 point11 = new Vector3(0.5f, 0.5f); * * * float stepSize = 1f / resolution; * * * * Random.seed = 42; * * * for (int i = 0; i < segment.y + 1; i++) * { * Vector3 point0 = Vector3.Lerp(point00, point01, (i + 0.5f) * stepSize); * Vector3 point1 = Vector3.Lerp(point10, point11, (i + 0.5f) * stepSize); * for (int j = 0; j < segment.x + 1; j++) * { * float tempHeight = 0; * // if ((i+j)%5 == 0) * { * Vector3 point = Vector3.Lerp(point0, point1, (j + 0.5f) * stepSize); * * tempHeight = NoiseMethod.Perlin2D(point, 22) * 10;// * * } * vertives[index] = new Vector3(j * w, tempHeight, i * h); * index++; * } * } * return vertives; * }*/ private Vector3[] GetVertives()//Fractal Noise { float frequency = 5; //[Range(1, 8)] int octaves = 6;//1普通,8烟雾状 // [Range(1f, 4f)] float lacunarity = 2f; // [Range(0f, 1f)] float persistence = 0.5f; int sum = Mathf.FloorToInt((segment.x + 1) * (segment.y + 1)); float w = size.x / segment.x; float h = size.y / segment.y; int index = 0; GetUV(); GetTriangles(); vertives = new Vector3[sum]; int resolution = 256; Vector3 point00 = new Vector3(-0.5f, -0.5f); Vector3 point10 = new Vector3(0.5f, -0.5f); Vector3 point01 = new Vector3(-0.5f, 0.5f); Vector3 point11 = new Vector3(0.5f, 0.5f); float stepSize = 1f / resolution; Random.seed = 42; for (int i = 0; i < segment.y + 1; i++) { Vector3 point0 = Vector3.Lerp(point00, point01, (i + 0.5f) * stepSize); Vector3 point1 = Vector3.Lerp(point10, point11, (i + 0.5f) * stepSize); for (int j = 0; j < segment.x + 1; j++) { float tempHeight = 0; // if ((i+j)%5 == 0) { Vector3 point = Vector3.Lerp(point0, point1, (j + 0.5f) * stepSize); float sample = NoiseMethod.Sum(1, point, frequency, octaves, lacunarity, persistence); tempHeight = sample * 20;// } vertives[index] = new Vector3(j * w, tempHeight, i * h); index++; } } return(vertives); }