Esempio n. 1
0
        public void RebuildTerrain(string path_override)
        {
            Config config = this.GetConfig();

            HeightData data;

            this.currentMap = this.outputs3d.SelectedIndex;

            if (this.currentMap == -1) return;

            if (path_override == null)
            {
                data = (HeightData)this.maps[this.outputs3d.SelectedItem];
            }
            else
            {
                data = Main.LoadHeightmapFromImageFile(path_override);

                /* The map was not loaded */
                if (data == null)
                {
                    System.Windows.Forms.MessageBox.Show("Could not load the image!");
                    this.OutputButtonsOff();
                    return;
                }
            }

            

            this.ShowBuildingModel();

            System.Threading.ThreadStart starter = delegate { this.SetTerrain(data); };
            this.modelThread = new System.Threading.Thread(starter);
            this.modelThread.Start();
        }
Esempio n. 2
0
        public void ShowImage()
        {
            Config config = this.GetConfig();

            try
            {
                this.AddStatus("Loading");

                int oldImageWidth  = 0;
                int oldImageHeight = 0;

                // save original output image dimensions, so we can deetect their change
                if (this.output.Image != null)
                {
                    oldImageWidth  = this.output.Image.Width;
                    oldImageHeight = this.output.Image.Height;
                }

                // if the image being loaded doesn't exist, cancel
                try
                {
                    // load imported or internal
                    if (this.currentImportedFile != null)
                    {
                        this.data = Main.LoadHeightmapFromImageFile(this.currentImportedFile);

                        if (this.data == null)
                        {
                            throw new Exception();
                        }
                    }
                    else
                    {
                        this.data = (HeightData)this.maps[this.outputs.SelectedItem];
                    }
                    currentImage = HeightDataToBitmap(this.data);
                }
                catch (Exception e)
                {
                    this.RemoveStatus("Loading");

                    return;
                }


                // apply overlay pattern?
                if (this.overlays.SelectedIndex > 0)
                {
                    string overlayPath = config.OverlayDirectory + "/" + (string)this.overlays.Items[this.overlays.SelectedIndex];

                    System.Drawing.Bitmap overlay = new System.Drawing.Bitmap(overlayPath);
                    this.currentImageWithOverlay = this.ApplyOverlay(this.data, overlay);

                    overlay.Dispose();
                }

                // decide which image (gray or overlay) to display
                if (this.overlays.SelectedIndex > 0 && this.toggleOverlay.Checked)
                {
                    this.output.Image = this.currentImageWithOverlay;
                }
                else
                {
                    this.output.Image = this.currentImage;
                }

                // detect size change (reset the view if size changed to prevent the image shrinking avay from the screen)
                if (oldImageWidth > this.output.Image.Width || oldImageHeight > this.output.Image.Width || oldImageHeight == 0)
                {
                    this.output.Width  = this.output.Image.Width;
                    this.output.Height = this.output.Image.Height;
                }
            }
            catch (OutOfMemoryException)
            {
                this.OutOfMemory();
            }

            this.RemoveStatus("Loading");
        }