IEnumerator GeneratingSlopeTask() { Color[] Pixels = new Color[ScmapEditor.Current.map.Width * ScmapEditor.Current.map.Height]; int x = 0; int y = 0; int i = 0; Vector3 Vert0 = Vector3.zero; Vector3 Vert1 = Vector3.zero; Vector3 Vert2 = Vector3.zero; Vector3 Vert3 = Vector3.zero; for (x = 0; x < ScmapEditor.Current.map.Width; x++) { for (y = 0; y < ScmapEditor.Current.map.Height; y++) { i = y + x * ScmapEditor.Current.map.Height; Vert0.x = x; Vert1.x = x + 1; Vert2.x = x; Vert3.x = x + 1; Vert0.z = y; Vert1.z = y; Vert2.z = y + 1; Vert3.z = y + 1; /* Old FAF way * Vert0.y = SlopeHeightmapPixels[x, y] * 512f; * Vert1.y = SlopeHeightmapPixels[x + 1, y] * 512f; * Vert2.y = SlopeHeightmapPixels[x, y + 1] * 512f; * Vert3.y = SlopeHeightmapPixels[x + 1, y + 1] * 512f; * * // Triangle 1: 0, 2, 1 * // 0, 3, 1 * float Dot = Vector3.Dot(GetTriangleVector(Vert0, Vert2, Vert1), Vector3.up); * * // Triangle 2: 3, 1, 2 * // 3, 0, 2 * //if (Dot > 0.5f) * Dot = Mathf.Min(Dot, Vector3.Dot(GetTriangleVector(Vert3, Vert1, Vert2), Vector3.up)); * * if (Dot > FlatHeight) * Pixels[i] = Flat; * else if (Dot > NonFlatHeight) * Pixels[i] = LowAngle; * else if (Dot > AlmostUnpassableHeight) * Pixels[i] = HighAngle; * else if (Dot > UnpassableHeight) * Pixels[i] = AlmostUnpassable; * else * Pixels[i] = Unpassable; */ Vert0.y = ScmapEditor.GetHeight(x, y) * ScaleHeight; Vert1.y = ScmapEditor.GetHeight(x + 1, y) * ScaleHeight; Vert2.y = ScmapEditor.GetHeight(x + 1, y + 1) * ScaleHeight; Vert3.y = ScmapEditor.GetHeight(x, y + 1) * ScaleHeight; float Dot = getSupComSlope(Vert0.y, Vert1.y, Vert2.y, Vert3.y); if (Dot <= FlatHeight) { Pixels[i] = Flat; } else if (Dot <= NonFlatHeight) { Pixels[i] = LowAngle; } else if (Dot <= AlmostUnpassableHeight) { Pixels[i] = HighAngle; } else if (Dot <= UnpassableHeight) { Pixels[i] = AlmostUnpassable; } else { Pixels[i] = Unpassable; } /* * float Min = Mathf.Min(Slope0, Slope1, Slope2, Slope3); * float Max = Mathf.Max(Slope0, Slope1, Slope2, Slope3); * * float Slope = Mathf.Abs(Max - Min) * 2; * * if (Slope < FlatHeight) * Pixels[i] = Flat; * else if (Slope < NonFlatHeight) * Pixels[i] = LowAngle; * else if (Slope < AlmostUnpassableHeight) * Pixels[i] = HighAngle; * else if (Slope < UnpassableHeight) * Pixels[i] = AlmostUnpassable; * else * Pixels[i] = Unpassable; */ } } yield return(Ninja.JumpToUnity); SlopeData.SetPixels(Pixels); SlopeData.Apply(false); ScmapEditor.Current.TerrainMaterial.SetTexture("_SlopeTex", SlopeData); ScmapEditor.Current.TerrainMaterial.SetFloat("_UseSlopeTex", 1); //yield return null; }