void CreateBlankBlendTexture()
 {
     LogFile.WriteLine("CreateBlankBlendTexture()");
     blendtexture = new ImageWrapper(256, 256);
     //blendtexture.Save( "blankblend.jpg" );
     LogFile.WriteLine("...done");
 }
 public void LoadSplatTextureFromFile(string filepath)
 {
     splattexturefilename = filepath;
     splattexture         = new ImageWrapper(filepath);
     //splattexture.Save( "newsplat.jpg" );
     onChanged();
 }
        //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");
        }
 //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");
 }
        List <MapTextureStageModel> LoadTextureStages(string sm3directory, TdfParser.Section terrainsection)
        {
            int numstages = terrainsection.GetIntValue("numtexturestages");
            List <MapTextureStageModel> stages = new List <MapTextureStageModel>();
            TerrainModel terrainmodel          = MetaverseClient.GetInstance().worldstorage.terrainmodel;

            for (int i = 0; i < numstages; i++)
            {
                TdfParser.Section texstagesection    = terrainsection.SubSection("texstage" + i);
                string            texturename        = texstagesection.GetStringValue("source");
                string            blendertexturename = texstagesection.GetStringValue("blender");
                string            operation          = texstagesection.GetStringValue("operation").ToLower();

                int          tilesize;
                ImageWrapper splattexture = LoadSplatTexture(sm3directory, terrainsection, texturename, out tilesize);
                if (operation == "blend")
                {
                    ImageWrapper blendtexture = LoadBlendTexture(sm3directory, terrainsection, blendertexturename);
                    stages.Add(new MapTextureStageModel(MapTextureStageModel.OperationType.Blend, tilesize, splattexture, blendtexture));
                }
                else // todo: add other operations
                {
                    stages.Add(new MapTextureStageModel(MapTextureStageModel.OperationType.Replace, tilesize, splattexture));
                }
            }
            terrainmodel.texturestages = stages;
            return(stages);
        }
 // blend needs two textures
 public MapTextureStageModel(OperationType operation, int Tilesize, ImageWrapper splattexture, ImageWrapper blendtexture)
 {
     LogFile.WriteLine("MapTextureStage(), two stages");
     this.Operation    = operation;
     this.splattexture = splattexture;
     this.blendtexture = blendtexture;
     this.Tilesize     = Tilesize;
 }
 public MapTextureStageModel(OperationType operation, int Tilesize, ImageWrapper splattexture)
 {
     LogFile.WriteLine("MapTextureStage(), single stages");
     this.Operation    = operation;
     this.splattexture = splattexture;
     this.Tilesize     = Tilesize;
     CreateBlankBlendTexture();
 }
 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");
 }
 public MapTextureStageModel(OperationType operation, int Tilesize, ImageWrapper splattexture )
 {
     LogFile.WriteLine("MapTextureStage(), single stages");
     this.Operation = operation;
     this.splattexture = splattexture;
     this.Tilesize = Tilesize;
     CreateBlankBlendTexture();
 }
 // blend needs two textures
 public MapTextureStageModel( OperationType operation, int Tilesize, ImageWrapper splattexture, ImageWrapper blendtexture )
 {
     LogFile.WriteLine("MapTextureStage(), two stages");
     this.Operation = operation;
     this.splattexture = splattexture;
     this.blendtexture = blendtexture;
     this.Tilesize = Tilesize;
 }
Exemple #11
0
        public void LoadFromFile(string filename)
        {
            Gl.glDeleteTextures(1, new int[] { GlReference });
            GlReference = 0;
            ImageWrapper image = new ImageWrapper(filename);

            Init(image, IsAlpha);
            this.filename = filename;
        }
Exemple #12
0
        ImageWrapper LoadSplatTexture(string sm3directory, TdfParser.Section terrainsection, string texturesectionname, out int tilesize)
        {
            TdfParser.Section texturesection = terrainsection.SubSection(texturesectionname);
            string            texturename    = Path.Combine(sm3directory, texturesection.GetStringValue("file"));

            LogFile.WriteLine(texturename);
            tilesize = texturesection.GetIntValue("tilesize");
            ImageWrapper splattexture = new ImageWrapper(texturename);

            return(splattexture);
            //return GlTexture.FromFile(texturename);
        }
Exemple #13
0
        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;
        }
Exemple #14
0
 public void LoadNewImage(ImageWrapper image, bool isalpha)
 {
     g.CheckError();
     this.isalpha = isalpha;
     this.width   = image.Width;
     this.height  = image.Height;
     if (isalpha)
     {
         LoadImageToOpenGlAsAlpha(image);
     }
     else
     {
         LoadImageToOpenGl(image);
     }
     g.CheckError();
 }
Exemple #15
0
 void LoadTextureData(MapTextureStageModel maptexturestage)
 {
     LogFile.WriteLine("PaintTexture.LoadTextureData( " + maptexturestage);
     thistexture = maptexturestage.blendtexture;
     if (thistexture != null)
     {
         texturewidth  = thistexture.Width;
         textureheight = thistexture.Height;
         LogFile.WriteLine("edittexture width " + texturewidth + " height " + textureheight);
         alphadata = new double[texturewidth, textureheight];
         for (int x = 0; x < texturewidth; x++)
         {
             for (int y = 0; y < textureheight; y++)
             {
                 alphadata[x, y] = thistexture.GetRed(x, y);
             }
         }
     }
 }
Exemple #16
0
 void Init(ImageWrapper image, bool isalpha)
 {
     this.isalpha = isalpha;
     g            = GraphicsHelperFactory.GetInstance();
     g.CheckError();
     CreateGlId();
     this.width  = image.Width;
     this.height = image.Height;
     if (isalpha)
     {
         LoadImageToOpenGlAsAlpha(image);
     }
     else
     {
         LoadImageToOpenGl(image);
     }
     g.CheckError();
     LogFile.WriteLine("GlTexture.Init id = " + GlReference);
 }
        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");
        }
Exemple #18
0
        // reads R channel as alpha channel
        void LoadImageToOpenGlAsAlpha(ImageWrapper image)
        {
            width  = image.Width;
            height = image.Height;
            LogFile.WriteLine("loading texture " + filename + " width: " + width + " height: " + height);

            alphadata = new byte[width, height];
            byte[] dataforgl = new byte[width * height];
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    int gloffset = y * width + x;
                    alphadata[x, y]     = image.GetRed(x, y);
                    dataforgl[gloffset] = image.GetRed(x, y);
                }
            }

            Gl.glBindTexture(Gl.GL_TEXTURE_2D, GlReference);
            Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_ALPHA8, width, height, 0, Gl.GL_ALPHA, Gl.GL_UNSIGNED_BYTE, dataforgl);
            Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_NEAREST);
        }
Exemple #19
0
        void LoadImageToOpenGl(ImageWrapper image)
        {
            width  = image.Width;
            height = image.Height;
            LogFile.WriteLine("loading texture " + filename + " width: " + width + " height: " + height);

            alphadata = new byte[width, height];

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    alphadata[x, y] = image.GetAlpha(x, y);
                }
            }

            LogFile.WriteLine("glreference: " + GlReference);
            Gl.glBindTexture(Gl.GL_TEXTURE_2D, GlReference);
            Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, Gl.GL_RGBA8, width, height,
                                  Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, image.data);
            Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
            image.Save("out2.jpg");
        }
Exemple #20
0
        void LoadHeightMap(string sm3directory, TdfParser.Section terrainsection)
        {
            TerrainModel terrainmodel = MetaverseClient.GetInstance().worldstorage.terrainmodel;

            string filename     = Path.Combine(sm3directory, terrainsection.GetStringValue("heightmap"));
            double heightoffset = terrainsection.GetDoubleValue("heightoffset");
            double heightscale  = terrainsection.GetDoubleValue("heightscale");

            LogFile.WriteLine("heightoffset: " + heightoffset + " heightscale " + heightscale);
            terrainmodel.MinHeight = heightoffset;
            terrainmodel.MaxHeight = heightoffset + heightscale; // I guess???

            ImageWrapper image = new ImageWrapper(filename);
            //Bitmap bitmap = DevIL.DevIL.LoadBitmap(filename);
            int width  = image.Width;
            int height = image.Height;

            terrainmodel.HeightMapWidth  = width;
            terrainmodel.HeightMapHeight = height;
            terrainmodel.Map             = new double[width, height];
            LogFile.WriteLine("loaded bitmap " + width + " x " + height);
            double minheight        = terrainmodel.MinHeight;
            double maxheight        = terrainmodel.MaxHeight;
            double heightmultiplier = (maxheight - minheight) / 255;

            LogFile.WriteLine("heightmultiplier: " + heightmultiplier + " minheight: " + minheight);
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    terrainmodel.Map[i, j] =
                        (float)(minheight + heightmultiplier *
                                image.GetBlue(i, j));
                }
            }
            terrain.HeightmapFilename = filename;
        }
 public void LoadSplatTextureFromFile( string filepath )
 {
     splattexturefilename = filepath;
     splattexture = new ImageWrapper( filepath );
     //splattexture.Save( "newsplat.jpg" );
     onChanged();
 }
 public void LoadBlendTextureFromFile( string filepath )
 {
     blendtexturefilename = filepath;
     blendtexture = new ImageWrapper( filepath ); // note to self: Is this right???
     onChanged();
 }
 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");
 }
Exemple #24
0
 void LoadTextureData( MapTextureStageModel maptexturestage )
 {
     LogFile.WriteLine( "PaintTexture.LoadTextureData( " + maptexturestage );
     thistexture = maptexturestage.blendtexture;
     if (thistexture != null)
     {
         texturewidth = thistexture.Width;
         textureheight = thistexture.Height;
         LogFile.WriteLine( "edittexture width " + texturewidth + " height " + textureheight );
         alphadata = new double[texturewidth, textureheight];
         for (int x = 0; x < texturewidth; x++)
         {
             for (int y = 0; y < textureheight; y++)
             {
                 alphadata[x, y] = thistexture.GetRed( x, y );
             }
         }
     }
 }
Exemple #25
0
 public GlTexture(ImageWrapper image, string filename, bool isalpha)
 {
     this.filename = filename;
     Init(image, isalpha);
 }
Exemple #26
0
 public GlTexture(ImageWrapper image, bool isalpha)
 {
     this.filename = "";
     Init(image, isalpha);
 }
Exemple #27
0
        // note to self: do something with this
        //~GlTexture()
        //{
        //  Console.WriteLine("deleting texture ref " + GlReference + " " + filename);
        //            Gl.glDeleteTextures(1, new int[] { GlReference });
        //      }

        // create blank texture
        public GlTexture(bool isalpha)
        {
            ImageWrapper image = new ImageWrapper(2, 2);

            Init(image, isalpha);
        }
 public void LoadBlendTextureFromFile(string filepath)
 {
     blendtexturefilename = filepath;
     blendtexture         = new ImageWrapper(filepath); // note to self: Is this right???
     onChanged();
 }
Exemple #29
0
        // create blank texture
        public GlTexture(int width, int height, bool isalpha)
        {
            ImageWrapper image = new ImageWrapper(width, height);

            Init(image, isalpha);
        }
Exemple #30
0
        void LoadHeightMap( string sm3directory, TdfParser.Section terrainsection)
        {
            TerrainModel terrainmodel = MetaverseClient.GetInstance().worldstorage.terrainmodel;

            string filename = Path.Combine( sm3directory, terrainsection.GetStringValue("heightmap") );
            double heightoffset = terrainsection.GetDoubleValue("heightoffset");
            double heightscale = terrainsection.GetDoubleValue("heightscale");
            LogFile.WriteLine("heightoffset: " + heightoffset + " heightscale " + heightscale);
            terrainmodel.MinHeight = heightoffset;
            terrainmodel.MaxHeight = heightoffset + heightscale; // I guess???

            ImageWrapper image = new ImageWrapper( filename );
            //Bitmap bitmap = DevIL.DevIL.LoadBitmap(filename);
            int width = image.Width;
            int height = image.Height;
            terrainmodel.HeightMapWidth = width;
            terrainmodel.HeightMapHeight = height;
            terrainmodel.Map = new double[width, height];
            LogFile.WriteLine("loaded bitmap " + width + " x " + height);
            double minheight = terrainmodel.MinHeight;
            double maxheight = terrainmodel.MaxHeight;
            double heightmultiplier = (maxheight - minheight) / 255;
            LogFile.WriteLine("heightmultiplier: " + heightmultiplier + " minheight: " + minheight);
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    terrainmodel.Map[i, j] =
                        (float)(minheight + heightmultiplier *
                        image.GetBlue(i,j) );
                }
            }
            terrain.HeightmapFilename = filename;
        }
 void CreateBlankBlendTexture()
 {
     LogFile.WriteLine( "CreateBlankBlendTexture()" );
     blendtexture = new ImageWrapper( 256, 256 );
     //blendtexture.Save( "blankblend.jpg" );
     LogFile.WriteLine( "...done" );
 }
 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" );
 }
Exemple #33
0
        public static GlTexture FromFile(string filename)
        {
            ImageWrapper image = new ImageWrapper(filename);

            return(new GlTexture(image, filename, false));
        }
Exemple #34
0
        public static GlTexture FromAlphamapFile(string filename)
        {
            ImageWrapper image = new ImageWrapper(filename);

            return(new GlTexture(image, filename, true));
        }
Exemple #35
0
 ImageWrapper LoadSplatTexture( string sm3directory, TdfParser.Section terrainsection, string texturesectionname, out int tilesize )
 {
     TdfParser.Section texturesection = terrainsection.SubSection(texturesectionname);
     string texturename = Path.Combine( sm3directory, texturesection.GetStringValue("file") );
     LogFile.WriteLine(texturename);
     tilesize = texturesection.GetIntValue("tilesize");
     ImageWrapper splattexture = new ImageWrapper( texturename );
     return splattexture;
     //return GlTexture.FromFile(texturename);
 }