Exemplo n.º 1
0
 public CompleteEvent(vector3 inv, string inrgb, string insimple, string intext)
 {
     pos    = inv;
     rgb    = inrgb;
     simple = insimple;
     text   = intext;
 }
Exemplo n.º 2
0
        private void Bw_DoWorkCont(object sender, DoWorkEventArgs e)
        {
            WorkerInfo wi   = (WorkerInfo)e.Argument;
            vector3    v    = wi.centertile;
            int        xp   = (int)v.x;
            int        yp   = (int)v.y;
            int        zoom = (int)v.z;

            int NumSquare = wi.NumberOfTiles;

            int progress = 0;

            for (int x = -NumSquare; x < NumSquare + 1; x++)
            {
                for (int y = -NumSquare; y < NumSquare + 1; y++)
                {
                    progress++;
                    _contworker.ReportProgress(progress);
                    ContinuityMap c = new ContinuityMap("rgb", 512);
                    c.Combine(x + xp, y + yp, zoom, ".jpg");
                    c = new ContinuityMap("height", 256);
                    c.Combine(x + xp, y + yp, zoom, ".png");
                }
            }
        }
Exemplo n.º 3
0
        public void Download(int z, int x, int y)
        {
            Directory.CreateDirectory("data\\" + z.ToString());
            Directory.CreateDirectory("data\\" + z.ToString() + "\\height");
            Directory.CreateDirectory("data\\" + z.ToString() + "\\rgb");
            Directory.CreateDirectory("data\\" + z.ToString() + "\\mesh");
            Directory.CreateDirectory("data\\" + z.ToString() + "\\data");
            Directory.CreateDirectory("data\\" + z.ToString() + "\\biome");

            string url = "https://api.mapbox.com/v4/mapbox.terrain-rgb/{z}/{x}/{y}.pngraw?access_token={key}";

            url = url.Replace("{z}", z.ToString());
            url = url.Replace("{x}", x.ToString());
            url = url.Replace("{y}", y.ToString());
            url = url.Replace("{key}", MapBoxKey);
            string url2 = "https://api.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}@2x.jpg?access_token={key}";

            url2 = url2.Replace("{z}", z.ToString());
            url2 = url2.Replace("{x}", x.ToString());
            url2 = url2.Replace("{y}", y.ToString());
            url2 = url2.Replace("{key}", MapBoxKey);

            WebClient c = new WebClient();

            Clients.Add(c);
            vector3 v = new vector3(x, y, z);

            c.DownloadFileCompleted += C_DownloadFileCompleted;

            string sPath = GetPath(v, "height") + ".png";

            if (!File.Exists(sPath))
            {
                c.DownloadFile(url, sPath);
            }

            sPath = GetPath(v, "rgb") + ".jpg";
            if (!File.Exists(sPath))
            {
                c.DownloadFile(url2, sPath);
            }

            Process(v);
        }
Exemplo n.º 4
0
        void Process(vector3 v)
        {
            string height   = GetPath(v, "height") + ".png";
            string rgb      = GetPath(v, "rgb") + ".jpg";
            string textname = GetPath(v, "heighttxt") + ".txt";

            // ExtractHeights(v);

            if (CreateMeshes == true)
            {
                CreateMesh(v);
            }

            if (Complete != null)
            {
                Complete(this, new CompleteEvent(v, height, rgb, textname));
            }

            Thread.Sleep(110);
        }
Exemplo n.º 5
0
        public void ExtractHeights(vector3 v)
        {
            string heightname = GetPath(v, "height") + ".png";
            string textname   = GetPath(v, "heighttxt") + ".txt";
            Bitmap b          = (Bitmap)Image.FromFile(heightname);

            Bitmap dest = new Bitmap(b);
            Color  c;
            double height = 0;

            double[,] n = new double[b.Width, b.Height];
            StringBuilder sb = new StringBuilder();

            for (int y = 0; y < b.Height; y++)
            {
                for (int x = 0; x < b.Width; x++)
                {
                    c      = b.GetPixel(x, y);
                    height = -10000 + ((c.R * 256 * 256 + c.G * 256 + c.B) * 0.1);
                    int nh = (int)((height / 8000.0) * 255);
                    if (nh > 255)
                    {
                        nh = 255;
                    }
                    dest.SetPixel(x, y, Color.FromArgb(nh, 0, 0));
                    n[x, y] = height;
                    sb.Append(height);
                    if (x < b.Width - 1)
                    {
                        sb.Append(",");
                    }
                    else
                    {
                        sb.Append("\n");
                    }
                }
            }
            File.WriteAllText(textname, sb.ToString());
        }
Exemplo n.º 6
0
        private void Bw_DoWork(object sender, DoWorkEventArgs e)
        {
            WorkerInfo wi   = (WorkerInfo)e.Argument;
            vector3    v    = wi.centertile;
            int        xp   = (int)v.x;
            int        yp   = (int)v.y;
            int        zoom = (int)v.z;

            int NumSquare = wi.NumberOfTiles;

            int progress = 0;

            for (int x = -NumSquare; x < NumSquare + 1; x++)
            {
                for (int y = -NumSquare; y < NumSquare + 1; y++)
                {
                    progress++;
                    _worker.ReportProgress(progress);
                    mapgen.Download(zoom, x + xp, y + yp);
                    mapTileInspector1.Process(x + xp, y + yp, zoom);
                    mapTileInspector1.Decode(x + xp, y + yp, zoom);
                }
            }
        }
Exemplo n.º 7
0
        public static string GetPath(vector3 v, string subfolder, string append = "")
        {
            string path = string.Format(@"data\{0}\{3}\{1}_{2}{4}", v.z, v.x, v.y, subfolder, append);

            return(path);
        }
Exemplo n.º 8
0
        string GetPath(vector3 v, string add)
        {
            string path = string.Format(@"data\{0}\{3}\{1}_{2}", v.z, v.x, v.y, add);

            return(path);
        }
Exemplo n.º 9
0
        public void CreateMesh(vector3 v)
        {
            string rgbname = GetPath(v, "height") + ".png";
            Bitmap bmp     = (Bitmap)Image.FromFile(rgbname);

            StringBuilder b = new StringBuilder();

            b.Append("o massive_" + v.x + "_" + v.y + "_" + v.z + "\n");

            RectD bounds = TileBounds(new Vector2d(v.x, v.y), (int)v.z);

            const int w = 256;
            const int h = 256;

            const int NumVertsX = 256;
            const int NumVertsY = 256;

            StringBuilder tex = new StringBuilder();
            StringBuilder f   = new StringBuilder();

            //double xscale = w * bounds.Size.x;
            //double zscale = h * bounds.Size.y;
            double xscale = bounds.Size.x;
            double zscale = bounds.Size.y;

            Color c;

            for (int z = 0; z < NumVertsY; z++)
            {
                for (int x = 0; x < NumVertsX; x++)
                {
                    c = bmp.GetPixel(x, z);
                    double height = -10000 + ((c.R * 256 * 256 + c.G * 256 + c.B) * 0.1);
                    //height = height / 8000.0;
                    b.Append(string.Format("v {0:0.00000000} {1:0.00000000} {2:0.00000000}", (x / (double)NumVertsX) * xscale, height, (z / (double)NumVertsY) * zscale) + "\n");
                    tex.Append("vt " + ((float)x / (float)(NumVertsX - 1)) + " " + (NumVertsY - ((float)z / (float)(NumVertsY - 1))) + "\n");
                }
            }

            b.Append("vn 0 1 0\n");

            const int totalVerts          = w * NumVertsY;
            const int totalTriangles      = 2 * (NumVertsX - 1) * (NumVertsY - 1);
            const int triangleIndexStride = 3 * sizeof(int);

            int counter = 0;

            for (int x = 0; x < (NumVertsX - 1) * (NumVertsY - 1); x++)
            {
                // for (int z = 0; z < NumVertsY ; z++)
                //{
                counter++;
                f.Append("f ");
                f.Append(counter + 1 + "/");
                f.Append(counter + 1 + "/");
                f.Append(1 + " ");

                f.Append(counter + "/");
                f.Append(counter + "/");
                f.Append(1 + " ");

                f.Append((counter + NumVertsX) + "/");
                f.Append(counter + NumVertsX + "/");
                f.Append(1 + " ");

                f.Append((counter + NumVertsX + 1) + "/");
                f.Append((counter + NumVertsX + 1) + "/");
                f.Append(1 + "\n");
                if (counter % NumVertsX == NumVertsX - 1)
                {
                    counter++;
                }

                //b.Append("F ")
                //b.Append(row1Index);
                //b.Append(row2Index + 1);
                //b.Append(row2Index);
                //}
            }

            b.Append(tex.ToString());
            b.Append(f.ToString());

            File.WriteAllText(GetPath(v, "mesh") + ".obj", b.ToString());
        }