コード例 #1
0
        public void GeneratePlaneMesh(Map map)
        {
            foreach (var c in map.Graph.centers)
            {
                if (c.water)
                    continue;
                var corner = new Vector2[c.corners.Count];
                HashSet<Vector2> uv      = new HashSet<Vector2>();
                HashSet<Vector2> uv2     = new HashSet<Vector2>();

                for (int i = 0; i < corner.Length; i++)
                {
                    var point = c.corners[i].point;
                    var _X = (point.x - (Map.Width / 2f)) * 32f;
                    var _Y = (point.y - (Map.Height / 2f)) * 32f;
                    corner[i] = new Vector2(_X, _Y);
                }

                for (int i = 0; i < c.corners.Count; i++)
                {
                    var p = c.corners[i];
                    uv2.Add(new Vector2(p.moisture, UnityEngine.Random.value));
                    uv.Add(p.point);
                }

                GenerateMesh(corner, uv.ToArray(), uv2.ToArray(), m_Plane);
            }
        }
コード例 #2
0
        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;
        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: MapTexture.cs プロジェクト: woniupapa/nmap
        public void AttachTexture(GameObject plane, Map map, NoisyEdges noisyEdge)
        {
            int textureWidth = (int) Map.Width*_textureScale;
            int textureHeight = (int) Map.Height*_textureScale;

            Texture2D texture = new Texture2D(textureWidth, textureHeight,TextureFormat.RGB565, true);
            texture.SetPixels(Enumerable.Repeat(BiomeProperties.Colors[Biome.Ocean], textureWidth * textureHeight).ToArray());

            //绘制扰乱的边缘
            foreach (Center p in map.Graph.centers)
            {
                foreach (var r in p.neighbors)
                {
                    Edge edge = map.Graph.lookupEdgeFromCenter(p, r);
                    if (!noisyEdge.path0.ContainsKey(edge.index) || !noisyEdge.path1.ContainsKey(edge.index))
                    {
                        // It's at the edge of the map, where we don't have
                        // the noisy edges computed. TODO: figure out how to
                        // fill in these edges from the voronoi library.
                        continue;
                    }
                    //绘制扰乱后的形状
                    DrawNoisyPolygon(texture, p, noisyEdge.path0[edge.index]);
                    DrawNoisyPolygon(texture, p, noisyEdge.path1[edge.index]);
                }
            }
            //绘制扰乱后的河流
            foreach (var line in map.Graph.edges.Where(p => p.river > 0 && !p.d0.water && !p.d1.water))
            {
                //绘制扰乱后的边缘
                List<Vector2> edge0 = noisyEdge.path0[line.index];
                for (int i = 0; i < edge0.Count - 1; i++)
                    DrawLine(texture, edge0[i].x, edge0[i].y, edge0[i + 1].x, edge0[i + 1].y, Color.blue);

                List<Vector2> edge1 = noisyEdge.path1[line.index];
                for (int i = 0; i < edge1.Count - 1; i++)
                    DrawLine(texture, edge1[i].x, edge1[i].y, edge1[i + 1].x, edge1[i + 1].y, Color.blue);
            }

            texture.Apply();

            plane.GetComponent<Renderer>().material.mainTexture = texture;
        }
コード例 #5
0
ファイル: MapTexture.cs プロジェクト: WilliamChao/nmap
 public void AttachTexture(GameObject plane, Map map, NoisyEdges noisyEdge)
 {
     Texture2D texture = GetTexture(map, noisyEdge);
     plane.GetComponent<Renderer>().material.mainTexture = texture;
 }