public override void Process(uint seed) { List <PathList> pathListList = new List <PathList>(); TerrainHeightMap heightMap = TerrainMeta.HeightMap; TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap; List <Vector3> vector3List = new List <Vector3>(); for (float z = (float)TerrainMeta.Position.z; (double)z < TerrainMeta.Position.z + TerrainMeta.Size.z; z += 50f) { for (float x = (float)TerrainMeta.Position.x; (double)x < TerrainMeta.Position.x + TerrainMeta.Size.x; x += 50f) { Vector3 worldPos; ((Vector3) ref worldPos).\u002Ector(x, 0.0f, z); float num1 = (float)(double)(worldPos.y = (__Null)heightMap.GetHeight(worldPos)); if (worldPos.y > 5.0) { Vector3 normal1 = heightMap.GetNormal(worldPos); if (normal1.y > 0.00999999977648258) { Vector2 vector2 = new Vector2((float)normal1.x, (float)normal1.z); Vector2 normalized = ((Vector2) ref vector2).get_normalized(); vector3List.Add(worldPos); float radius = 12f; int num2 = 12; for (int index = 0; index < 10000; ++index) { ref __Null local1 = ref worldPos.x;
private void DoWork() { Vector3 vector3 = new Vector3((float)(this.width / 2), 0f, (float)(this.height / 2)); Vector3 vector31 = new Vector3(this.pivot.x - vector3.x, 0f, this.pivot.z - vector3.z); TerrainHeightMap heightMap = TerrainMeta.HeightMap; TerrainAlphaMap alphaMap = TerrainMeta.AlphaMap; int num = 0; for (int i = 0; i <= this.height; i++) { int num1 = 0; while (num1 <= this.width) { Vector3 vector32 = new Vector3((float)num1, 0f, (float)i) + vector31; Vector3 vector33 = new Vector3((float)num1, 0f, (float)i) - vector3; float height = heightMap.GetHeight(vector32); if (height < -1f) { this.indices.Add(-1); } else if (!this.alpha || alphaMap.GetAlpha(vector32) >= 0.1f) { if (this.normal) { Vector3 normal = heightMap.GetNormal(vector32); this.normals.Add(normal); } float single = height - this.pivot.y; float single1 = single; vector33.y = single; vector32.y = single1; this.indices.Add(this.vertices.Count); this.vertices.Add(vector33); } else { this.indices.Add(-1); } num1++; num++; } } int num2 = 0; int num3 = 0; while (num3 < this.height) { int num4 = 0; while (num4 < this.width) { int item = this.indices[num2]; int item1 = this.indices[num2 + this.width + 1]; int item2 = this.indices[num2 + 1]; int item3 = this.indices[num2 + 1]; int item4 = this.indices[num2 + this.width + 1]; int item5 = this.indices[num2 + this.width + 2]; if (item != -1 && item1 != -1 && item2 != -1) { this.triangles.Add(item); this.triangles.Add(item1); this.triangles.Add(item2); } if (item3 != -1 && item4 != -1 && item5 != -1) { this.triangles.Add(item3); this.triangles.Add(item4); this.triangles.Add(item5); } num4++; num2++; } num3++; num2++; } }
public override void Process(uint seed) { if (World.Networked) { TerrainMeta.Path.Rivers.Clear(); TerrainMeta.Path.Rivers.AddRange(World.GetPaths("River")); return; } List <PathList> list = new List <PathList>(); TerrainHeightMap heightMap = TerrainMeta.HeightMap; TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap; List <Vector3> list2 = new List <Vector3>(); for (float num = TerrainMeta.Position.z; num < TerrainMeta.Position.z + TerrainMeta.Size.z; num += 50f) { for (float num2 = TerrainMeta.Position.x; num2 < TerrainMeta.Position.x + TerrainMeta.Size.x; num2 += 50f) { Vector3 vector = new Vector3(num2, 0f, num); float num3 = (vector.y = heightMap.GetHeight(vector)); if (vector.y <= 5f) { continue; } Vector3 normal = heightMap.GetNormal(vector); if (normal.y <= 0.01f) { continue; } Vector2 normalized = new Vector2(normal.x, normal.z).normalized; list2.Add(vector); float radius = 18f; int num4 = 18; for (int i = 0; i < 10000; i++) { vector.x += normalized.x; vector.z += normalized.y; if (heightMap.GetSlope(vector) > 30f) { break; } float height = heightMap.GetHeight(vector); if (height > num3 + 10f) { break; } float num5 = Mathf.Min(height, num3); vector.y = Mathf.Lerp(vector.y, num5, 0.15f); int topology = topologyMap.GetTopology(vector, radius); int topology2 = topologyMap.GetTopology(vector); int num6 = 2694148; int num7 = 128; if ((topology & num6) != 0) { list2.Add(vector); break; } if ((topology2 & num7) != 0 && --num4 <= 0) { list2.Add(vector); if (list2.Count >= 25) { int num8 = TerrainMeta.Path.Rivers.Count + list.Count; PathList pathList = new PathList("River " + num8, list2.ToArray()); pathList.Width = 36f; pathList.InnerPadding = 1f; pathList.OuterPadding = 1f; pathList.InnerFade = 10f; pathList.OuterFade = 20f; pathList.RandomScale = 0.75f; pathList.MeshOffset = -0.5f; pathList.TerrainOffset = -1.5f; pathList.Topology = 16384; pathList.Splat = 64; pathList.Start = true; pathList.End = true; list.Add(pathList); } break; } if (i % 12 == 0) { list2.Add(vector); } normal = heightMap.GetNormal(vector); normalized = new Vector2(normalized.x + 0.15f * normal.x, normalized.y + 0.15f * normal.z).normalized; num3 = num5; } list2.Clear(); } } list.Sort((PathList a, PathList b) => b.Path.Points.Length.CompareTo(a.Path.Points.Length)); int num9 = Mathf.RoundToInt(10f * TerrainMeta.Size.x * TerrainMeta.Size.z * 1E-06f); int num10 = Mathf.NextPowerOfTwo((int)((float)World.Size / 36f)); bool[,] array = new bool[num10, num10]; for (int j = 0; j < list.Count; j++) { if (j >= num9) { list.RemoveUnordered(j--); continue; } PathList pathList2 = list[j]; bool flag = false; for (int k = 0; k < j; k++) { if (Vector3.Distance(list[k].Path.GetStartPoint(), pathList2.Path.GetStartPoint()) < 100f) { list.RemoveUnordered(j--); flag = true; break; } } if (flag) { continue; } int num11 = -1; int num12 = -1; for (int l = 0; l < pathList2.Path.Points.Length; l++) { Vector3 vector2 = pathList2.Path.Points[l]; int num13 = Mathf.Clamp((int)(TerrainMeta.NormalizeX(vector2.x) * (float)num10), 0, num10 - 1); int num14 = Mathf.Clamp((int)(TerrainMeta.NormalizeZ(vector2.z) * (float)num10), 0, num10 - 1); if (num11 == num13 && num12 == num14) { continue; } if (array[num14, num13]) { list.RemoveUnordered(j--); flag = true; break; } if (num11 != num13 && num12 != num14) { if (num11 != -1) { array[num14, num11] = true; } if (num12 != -1) { array[num12, num13] = true; } num11 = num13; num12 = num14; array[num14, num13] = true; } else { num11 = num13; num12 = num14; array[num14, num13] = true; } } } for (int m = 0; m < list.Count; m++) { list[m].Name = "River " + (TerrainMeta.Path.Rivers.Count + m); } foreach (PathList item in list) { item.Path.Smoothen(4); item.Path.RecalculateTangents(); } TerrainMeta.Path.Rivers.AddRange(list); }
public override void Process(uint seed) { List <PathList> pathLists = new List <PathList>(); TerrainHeightMap heightMap = TerrainMeta.HeightMap; TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap; List <Vector3> vector3s = new List <Vector3>(); for (float i = TerrainMeta.Position.z; i < TerrainMeta.Position.z + TerrainMeta.Size.z; i += 50f) { for (float j = TerrainMeta.Position.x; j < TerrainMeta.Position.x + TerrainMeta.Size.x; j += 50f) { Vector3 vector3 = new Vector3(j, 0f, i); float height = heightMap.GetHeight(vector3); float single = height; vector3.y = height; float single1 = single; if (vector3.y > 5f) { Vector3 normal = heightMap.GetNormal(vector3); if (normal.y > 0.01f) { Vector2 vector2 = new Vector2(normal.x, normal.z); Vector2 vector21 = vector2.normalized; vector3s.Add(vector3); float single2 = 12f; int num = 12; for (int k = 0; k < 10000; k++) { vector3.x += vector21.x; vector3.z += vector21.y; if (heightMap.GetSlope(vector3) > 30f) { break; } float height1 = heightMap.GetHeight(vector3); if (height1 > single1 + 10f) { break; } vector3.y = Mathf.Min(height1, single1); vector3s.Add(vector3); int topology = topologyMap.GetTopology(vector3, single2); int topology1 = topologyMap.GetTopology(vector3); int num1 = 2694148; int num2 = 128; if ((topology & num1) != 0) { break; } if ((topology1 & num2) != 0) { int num3 = num - 1; num = num3; if (num3 <= 0) { if (vector3s.Count < 300) { break; } PathList pathList = new PathList(string.Concat("River ", pathLists.Count), vector3s.ToArray()) { Width = 24f, InnerPadding = 0.5f, OuterPadding = 0.5f, InnerFade = 8f, OuterFade = 16f, RandomScale = 0.75f, MeshOffset = -0.4f, TerrainOffset = -2f, Topology = 16384, Splat = 64, Start = true, End = true }; pathLists.Add(pathList); break; } } normal = heightMap.GetNormal(vector3); vector2 = new Vector2(vector21.x + 0.15f * normal.x, vector21.y + 0.15f * normal.z); vector21 = vector2.normalized; single1 = vector3.y; } vector3s.Clear(); } } } } pathLists.Sort((PathList a, PathList b) => ((int)b.Path.Points.Length).CompareTo((int)a.Path.Points.Length)); int num4 = Mathf.RoundToInt(10f * TerrainMeta.Size.x * TerrainMeta.Size.z * 1E-06f); int num5 = Mathf.NextPowerOfTwo((int)((float)((float)World.Size) / 24f)); bool[,] flagArray = new bool[num5, num5]; for (int l = 0; l < pathLists.Count; l++) { if (l < num4) { PathList item = pathLists[l]; for (int m = 0; m < l; m++) { if (Vector3.Distance(pathLists[m].Path.GetStartPoint(), item.Path.GetStartPoint()) < 100f) { int num6 = l; l = num6 - 1; pathLists.RemoveUnordered <PathList>(num6); } } int num7 = -1; int num8 = -1; for (int n = 0; n < (int)item.Path.Points.Length; n++) { Vector3 points = item.Path.Points[n]; int num9 = Mathf.Clamp((int)(TerrainMeta.NormalizeX(points.x) * (float)num5), 0, num5 - 1); int num10 = Mathf.Clamp((int)(TerrainMeta.NormalizeZ(points.z) * (float)num5), 0, num5 - 1); if (num7 != num9 || num8 != num10) { if (!flagArray[num10, num9]) { num7 = num9; num8 = num10; flagArray[num10, num9] = true; } else { int num11 = l; l = num11 - 1; pathLists.RemoveUnordered <PathList>(num11); break; } } } } else { int num12 = l; l = num12 - 1; pathLists.RemoveUnordered <PathList>(num12); } } TerrainMeta.Path.Rivers.AddRange(pathLists); }
private void DoWork() { Vector3 vector3_1; ((Vector3) ref vector3_1).\u002Ector((float)(this.width / 2), 0.0f, (float)(this.height / 2)); Vector3 vector3_2; ((Vector3) ref vector3_2).\u002Ector((float)(this.pivot.x - vector3_1.x), 0.0f, (float)(this.pivot.z - vector3_1.z)); TerrainHeightMap heightMap = TerrainMeta.HeightMap; TerrainAlphaMap alphaMap = TerrainMeta.AlphaMap; int num1 = 0; for (int index = 0; index <= this.height; ++index) { int num2 = 0; while (num2 <= this.width) { Vector3 worldPos = Vector3.op_Addition(new Vector3((float)num2, 0.0f, (float)index), vector3_2); Vector3 vector3_3 = Vector3.op_Subtraction(new Vector3((float)num2, 0.0f, (float)index), vector3_1); float height = heightMap.GetHeight(worldPos); if ((double)height < -1.0) { this.indices.Add(-1); } else if (this.alpha && (double)alphaMap.GetAlpha(worldPos) < 0.100000001490116) { this.indices.Add(-1); } else { if (this.normal) { this.normals.Add(heightMap.GetNormal(worldPos)); } worldPos.y = (__Null)(double)(vector3_3.y = (__Null)(height - (float)this.pivot.y)); this.indices.Add(this.vertices.Count); this.vertices.Add(vector3_3); } ++num2; ++num1; } } int index1 = 0; int num3 = 0; while (num3 < this.height) { int num2 = 0; while (num2 < this.width) { int index2 = this.indices[index1]; int index3 = this.indices[index1 + this.width + 1]; int index4 = this.indices[index1 + 1]; int index5 = this.indices[index1 + 1]; int index6 = this.indices[index1 + this.width + 1]; int index7 = this.indices[index1 + this.width + 2]; if (index2 != -1 && index3 != -1 && index4 != -1) { this.triangles.Add(index2); this.triangles.Add(index3); this.triangles.Add(index4); } if (index5 != -1 && index6 != -1 && index7 != -1) { this.triangles.Add(index5); this.triangles.Add(index6); this.triangles.Add(index7); } ++num2; ++index1; } ++num3; ++index1; } }
private void DoWork() { Vector3 vector = new Vector3(width / 2, 0f, height / 2); Vector3 vector2 = new Vector3(pivot.x - vector.x, 0f, pivot.z - vector.z); TerrainHeightMap heightMap = TerrainMeta.HeightMap; TerrainAlphaMap alphaMap = TerrainMeta.AlphaMap; int num = 0; for (int i = 0; i <= height; i++) { int num2 = 0; while (num2 <= width) { Vector3 worldPos = new Vector3(num2, 0f, i) + vector2; Vector3 item = new Vector3(num2, 0f, i) - vector; float num3 = heightMap.GetHeight(worldPos); if (num3 < -1f) { indices.Add(-1); } else if (alpha && alphaMap.GetAlpha(worldPos) < 0.1f) { indices.Add(-1); } else { if (normal) { Vector3 item2 = heightMap.GetNormal(worldPos); normals.Add(item2); } worldPos.y = (item.y = num3 - pivot.y); indices.Add(vertices.Count); vertices.Add(item); } num2++; num++; } } int num4 = 0; int num5 = 0; while (num5 < height) { int num6 = 0; while (num6 < width) { int num7 = indices[num4]; int num8 = indices[num4 + width + 1]; int num9 = indices[num4 + 1]; int num10 = indices[num4 + 1]; int num11 = indices[num4 + width + 1]; int num12 = indices[num4 + width + 2]; if (num7 != -1 && num8 != -1 && num9 != -1) { triangles.Add(num7); triangles.Add(num8); triangles.Add(num9); } if (num10 != -1 && num11 != -1 && num12 != -1) { triangles.Add(num10); triangles.Add(num11); triangles.Add(num12); } num6++; num4++; } num5++; num4++; } }