public void ShowElevation(GameObject plane, Map2 map) { var textureWidth = (int)Map1.Width * _textureScale; var textureHeight = (int)Map1.Height * _textureScale; var texture = new Texture2D(textureWidth, textureHeight, TextureFormat.RGB565, true); texture.SetPixels(Enumerable.Repeat(BiomeProperties.Colors[Biome.Ocean], textureWidth * textureHeight).ToArray()); //绘制陆地 var lands = map.Graph.centers.Where(p => !p.ocean); foreach (var land in lands) texture.FillPolygon( land.corners.Select(p => p.point * _textureScale).ToArray(), BiomeProperties.Colors[Biome.Beach] * land.elevation); //绘制边缘 var lines = map.Graph.edges.Where(p => p.v0 != null).Select(p => new[] { p.v0.point.x, p.v0.point.y, p.v1.point.x, p.v1.point.y }).ToArray(); foreach (var line in lines) DrawLine(texture, line[0], line[1], line[2], line[3], Color.black); //绘制中心点 var points = map.Graph.centers.Select(p => p.point).ToList(); foreach (var p in points) texture.SetPixel((int)(p.x * _textureScale), (int)(p.y * _textureScale), Color.red); texture.Apply(); plane.GetComponent<Renderer>().material.mainTexture = texture; }
public void AttachTexture(GameObject plane, Map map) { int _textureWidth = (int)Map.Width * _textureScale; int _textureHeight = (int)Map.Height * _textureScale; Texture2D texture = new Texture2D(_textureWidth, _textureHeight, TextureFormat.RGBA32, false); texture.wrapMode = TextureWrapMode.Clamp; foreach (var c in map.Graph.centers) { var corner = new Vector2[c.corners.Count]; for (int i = 0; i < corner.Length; i++) { var p = c.corners[i]; corner[i] = new Vector2(p.point.x * _textureScale, p.point.y * _textureScale); } texture.FillPolygon(corner, BiomeProperties.Colors[c.biome]); } texture.Apply(); var render = plane.GetComponent<Renderer>(); render.material.mainTexture = texture; mapScale = render.bounds.size.x; }
public void AttachTexture(GameObject plane, Map map) { int _textureWidth = (int)Map.Width * _textureScale; int _textureHeight = (int)Map.Height * _textureScale; Texture2D texture = new Texture2D(_textureWidth, _textureHeight); texture.SetPixels(Enumerable.Repeat(Color.magenta, _textureWidth * _textureHeight).ToArray()); var lines = map.Graph.edges.Where(p => p.v0 != null).Select(p => new[] { p.v0.point.x, p.v0.point.y, p.v1.point.x, p.v1.point.y }).ToArray(); foreach (var c in map.Graph.centers) texture.FillPolygon(c.corners.Select(p => new Vector2(p.point.x * _textureScale, p.point.y * _textureScale)).ToArray(), BiomeProperties.Colors[c.biome]); foreach (var line in lines) DrawLine(texture, line[0], line[1], line[2], line[3], Color.black); foreach (var line in map.Graph.edges.Where(p => p.river > 0 && !p.d0.water && !p.d1.water)) DrawLine(texture, line.v0.point.x, line.v0.point.y, line.v1.point.x, line.v1.point.y, Color.blue); texture.Apply(); plane.renderer.material.mainTexture = texture; plane.transform.localPosition = new Vector3(Map.Width / 2, Map.Height / 2, 1); }
private void DrawNoisyPolygon(Texture2D texture, Center p, List<Vector2> orgEdges) { _edgePoints.Clear(); _edgePoints.AddRange(orgEdges); _edgePoints.Add(p.point); texture.FillPolygon( _edgePoints.Select(x => new Vector2(x.x * _textureScale, x.y * _textureScale)).ToArray(), BiomeProperties.Colors[p.biome]); }