//public void Load()
        //{
        //  Load(Config.GetInstance().defaultHeightMapFilename);
        //}

        public void Load(string filename)
        {
            //Bitmap bitmap = Bitmap.FromFile(filename) as Bitmap;
            //Bitmap bitmap = DevIL.DevIL.LoadBitmap(filename);
            ImageWrapper image  = new ImageWrapper(filename);
            int          width  = image.Width;
            int          height = image.Height;

            MetaverseClient.GetInstance().worldstorage.terrainmodel.HeightMapWidth = width;
            MetaverseClient.GetInstance().worldstorage.terrainmodel.HeightMapHeight = height;
            MetaverseClient.GetInstance().worldstorage.terrainmodel.Map = new double[width, height];
            LogFile.WriteLine("loaded bitmap " + width + " x " + height);
            double minheight        = Config.GetInstance().mingroundheight;
            double maxheight        = Config.GetInstance().maxgroundheight;
            double heightmultiplier = (maxheight - minheight) / 255;

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    MetaverseClient.GetInstance().worldstorage.terrainmodel.Map[i, j] = (float)(minheight +
                                                                                                heightmultiplier *
                                                                                                image.GetBlue(i, j));
                }
            }
            MetaverseClient.GetInstance().worldstorage.terrainmodel.HeightmapFilename = filename;
            MetaverseClient.GetInstance().worldstorage.terrainmodel.OnTerrainModified();
            MainTerrainWindow.GetInstance().InfoMessage("Heightmap loaded");
        }
Esempio n. 2
0
 public void Register(IBrushEffect brusheffect)
 {
     Console.WriteLine(this.GetType() + " registering " + brusheffect);
     this.brusheffects.Add(brusheffect.GetType(), brusheffect);
     if (CurrentEditBrush.GetInstance().BrushEffect == null)
     {
         CurrentEditBrush.GetInstance().BrushEffect = brusheffect;
     }
     MainTerrainWindow.GetInstance().AddBrushEffect(brusheffect.Name, brusheffect.Description, brusheffect);
 }
Esempio n. 3
0
 public void Register(IBrushShape brushshape)
 {
     Console.WriteLine(this.GetType() + " registering " + brushshape);
     this.brushshapes.Add(brushshape.GetType(), brushshape);
     if (CurrentEditBrush.GetInstance().BrushShape == null)
     {
         CurrentEditBrush.GetInstance().BrushShape = brushshape;
     }
     MainTerrainWindow.GetInstance().AddBrushShape(brushshape.Name, brushshape.Description, brushshape);
 }
Esempio n. 4
0
        public void LoadSm3(string filename)
        {
            terrain.tdfparser = TdfParser.FromFile(filename);
            TdfParser.Section terrainsection = terrain.tdfparser.RootSection.SubSection("map/terrain");
            string            tdfdirectory   = Path.GetDirectoryName(Path.GetDirectoryName(filename));

            LoadTextureStages(tdfdirectory, terrainsection);
            LoadHeightMap(tdfdirectory, terrainsection);
            terrain.OnTerrainModified();
            MainTerrainWindow.GetInstance().InfoMessage("SM3 load completed");
        }
        public void Save(string filename)
        {
            double[,] mesh = MetaverseClient.GetInstance().worldstorage.terrainmodel.Map;
            int          width  = mesh.GetUpperBound(0) + 1;
            int          height = mesh.GetUpperBound(1) + 1;
            ImageWrapper image  = new ImageWrapper(width, height);
            //Bitmap bitmap = new Bitmap( width, height, PixelFormat.Format24bppRgb );
            //Graphics g = Graphics.FromImage(bitmap);
            //Pen[] pens = new Pen[256];
            //for (int i = 0; i < 256; i++)
            //{
            //  pens[i] = new Pen(System.Drawing.Color.FromArgb(i, i, i));
            //}
            double minheight        = Config.GetInstance().mingroundheight;
            double maxheight        = Config.GetInstance().maxgroundheight;
            double heightmultiplier = 255 / (maxheight - minheight);

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    int normalizedmeshvalue = (int)((mesh[i, j] - minheight) * heightmultiplier);
                    normalizedmeshvalue = Math.Max(0, normalizedmeshvalue);
                    normalizedmeshvalue = Math.Min(255, normalizedmeshvalue);
                    byte normalizedmeshvaluebyte = (byte)normalizedmeshvalue;
                    image.SetPixel(i, j, normalizedmeshvaluebyte, normalizedmeshvaluebyte, normalizedmeshvaluebyte, 255);
                    //g.DrawRectangle(pens[ normalizedmeshvalue ], i, j, 1, 1);
                }
            }
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            image.Save(filename);
            //DevIL.DevIL.SaveBitmap(filename, bitmap);
            //bitmap.Save(filename, ImageFormat.Bmp);
            MetaverseClient.GetInstance().worldstorage.terrainmodel.HeightmapFilename = filename;
            MetaverseClient.GetInstance().worldstorage.terrainmodel.OnTerrainModified();
            MainTerrainWindow.GetInstance().InfoMessage("Heightmap saved");
        }