コード例 #1
0
 void CreateBlankTexture()
 {
     LogFile.WriteLine("CreateBlankTexture()");
     splattexture = new ImageWrapper(1, 1);
     splattexture.SetPixel(0, 0, 255, 255, 255, 255);
     //splattexture.Save( "blanksplat.jpg" );
     LogFile.WriteLine("...done");
 }
コード例 #2
0
ファイル: GlTexture.cs プロジェクト: beyonddiana/osmp-cs
        public void SaveAlphaToFile(string filename)
        {
            ImageWrapper image = new ImageWrapper(width, height);

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    image.SetPixel(i, j, alphadata[i, j], alphadata[i, j], alphadata[i, j], alphadata[i, j]);
                }
            }
            image.Save(filename);
            this.filename = filename;
            this.modified = false;
        }
コード例 #3
0
        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");
        }
コード例 #4
0
 void CreateBlankTexture()
 {
     LogFile.WriteLine("CreateBlankTexture()");
     splattexture = new ImageWrapper( 1, 1 );
     splattexture.SetPixel( 0, 0, 255, 255, 255, 255 );
     //splattexture.Save( "blanksplat.jpg" );
     LogFile.WriteLine( "...done" );
 }
コード例 #5
0
 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");
 }
コード例 #6
0
        public void ApplyBrush(IBrushShape brushshape, int brushsize, double brushcentrex, double brushcentrey, bool israising, double milliseconds)
        {
            if (thistexture != null && maptexturestage != null)
            {
                double timemultiplier = milliseconds * speed;

                double directionmultiplier = 1.0;
                if (!israising)
                {
                    directionmultiplier = -1.0;
                }

                int mapx               = (int)(brushcentrex);
                int mapy               = (int)(brushcentrey);
                int mapwidth           = MetaverseClient.GetInstance().worldstorage.terrainmodel.HeightMapWidth - 1;
                int mapheight          = MetaverseClient.GetInstance().worldstorage.terrainmodel.HeightMapHeight - 1;
                int texturex           = (int)(texturewidth * mapx / mapwidth);
                int texturey           = (int)(textureheight * mapy / mapheight);
                int texturebrushwidth  = (int)(texturewidth * brushsize / mapwidth);
                int texturebrushheight = (int)(textureheight * brushsize / mapheight);
                for (int i = -texturebrushwidth; i <= texturebrushwidth; i++)
                {
                    for (int j = -texturebrushheight; j <= texturebrushheight; j++)
                    {
                        double brushshapecontribution = brushshape.GetStrength((double)i / texturebrushwidth,
                                                                               (double)j / texturebrushheight);
                        if (brushshapecontribution > 0)
                        {
                            int thisx = texturex + i;
                            int thisy = texturey + j;
                            //      Console.WriteLine(thisx + " " + thisy);
                            if (thisx >= 0 && thisy >= 0 && thisx < texturewidth &&
                                thisy < textureheight)
                            {
                                // we update our double array then set the int array iwthin ITexture itself
                                //LogFile.WriteLine( speed + " " + directionmultiplier + " " + timemultiplier + " " + brushshapecontribution );
                                alphadata[thisx, thisy] += speed * directionmultiplier * timemultiplier * brushshapecontribution;
                                if (alphadata[thisx, thisy] >= 255)
                                {
                                    alphadata[thisx, thisy] = 255;
                                }
                                else if (alphadata[thisx, thisy] < 0)
                                {
                                    alphadata[thisx, thisy] = 0;
                                }
                                thistexture.SetPixel(thisx, thisy, (byte)alphadata[thisx, thisy], (byte)alphadata[thisx, thisy], (byte)alphadata[thisx, thisy], 255);
                                //LogFile.WriteLine( "setting pixel " + thisx + " " + thisy + " to " + (byte)alphadata[thisx, thisy] );
                                //thistexture.AlphaData[thisx, thisy] = (byte)alphadata[thisx, thisy];
                                //  Console.WriteLine(thisx + " " + thisy + " " + (byte)alphadata[thisx, thisy]);
                            }
                        }
                    }
                }

                thistexture.Save("editedblend.jpg");

                //thistexture.ReloadAlpha();
                maptexturestage.onChanged();
                //thistexture.Modified = true;
                MetaverseClient.GetInstance().worldstorage.terrainmodel.OnBlendMapInPlaceEdited(maptexturestage, mapx - brushsize, mapy - brushsize, mapx + brushsize, mapy + brushsize);
            }
        }