コード例 #1
0
 void CreateBlankBlendTexture()
 {
     LogFile.WriteLine("CreateBlankBlendTexture()");
     blendtexture = new ImageWrapper(256, 256);
     //blendtexture.Save( "blankblend.jpg" );
     LogFile.WriteLine("...done");
 }
コード例 #2
0
 public void LoadSplatTextureFromFile(string filepath)
 {
     splattexturefilename = filepath;
     splattexture         = new ImageWrapper(filepath);
     //splattexture.Save( "newsplat.jpg" );
     onChanged();
 }
コード例 #3
0
        //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");
        }
コード例 #4
0
 //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");
 }
コード例 #5
0
ファイル: Sm3Persistence.cs プロジェクト: beyonddiana/osmp-cs
        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);
        }
コード例 #6
0
 // 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;
 }
コード例 #7
0
 public MapTextureStageModel(OperationType operation, int Tilesize, ImageWrapper splattexture)
 {
     LogFile.WriteLine("MapTextureStage(), single stages");
     this.Operation    = operation;
     this.splattexture = splattexture;
     this.Tilesize     = Tilesize;
     CreateBlankBlendTexture();
 }
コード例 #8
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");
 }
コード例 #9
0
 public MapTextureStageModel(OperationType operation, int Tilesize, ImageWrapper splattexture )
 {
     LogFile.WriteLine("MapTextureStage(), single stages");
     this.Operation = operation;
     this.splattexture = splattexture;
     this.Tilesize = Tilesize;
     CreateBlankBlendTexture();
 }
コード例 #10
0
 // 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;
 }
コード例 #11
0
ファイル: GlTexture.cs プロジェクト: beyonddiana/osmp-cs
        public void LoadFromFile(string filename)
        {
            Gl.glDeleteTextures(1, new int[] { GlReference });
            GlReference = 0;
            ImageWrapper image = new ImageWrapper(filename);

            Init(image, IsAlpha);
            this.filename = filename;
        }
コード例 #12
0
ファイル: Sm3Persistence.cs プロジェクト: beyonddiana/osmp-cs
        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);
        }
コード例 #13
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;
        }
コード例 #14
0
ファイル: GlTexture.cs プロジェクト: beyonddiana/osmp-cs
 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();
 }
コード例 #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);
             }
         }
     }
 }
コード例 #16
0
ファイル: GlTexture.cs プロジェクト: beyonddiana/osmp-cs
 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);
 }
コード例 #17
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");
        }
コード例 #18
0
ファイル: GlTexture.cs プロジェクト: beyonddiana/osmp-cs
        // 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);
        }
コード例 #19
0
ファイル: GlTexture.cs プロジェクト: beyonddiana/osmp-cs
        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");
        }
コード例 #20
0
ファイル: Sm3Persistence.cs プロジェクト: beyonddiana/osmp-cs
        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;
        }
コード例 #21
0
 public void LoadSplatTextureFromFile( string filepath )
 {
     splattexturefilename = filepath;
     splattexture = new ImageWrapper( filepath );
     //splattexture.Save( "newsplat.jpg" );
     onChanged();
 }
コード例 #22
0
 public void LoadBlendTextureFromFile( string filepath )
 {
     blendtexturefilename = filepath;
     blendtexture = new ImageWrapper( filepath ); // note to self: Is this right???
     onChanged();
 }
コード例 #23
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");
 }
コード例 #24
0
ファイル: PaintTexture.cs プロジェクト: hughperkins/osmp-cs
 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 );
             }
         }
     }
 }
コード例 #25
0
ファイル: GlTexture.cs プロジェクト: beyonddiana/osmp-cs
 public GlTexture(ImageWrapper image, string filename, bool isalpha)
 {
     this.filename = filename;
     Init(image, isalpha);
 }
コード例 #26
0
ファイル: GlTexture.cs プロジェクト: beyonddiana/osmp-cs
 public GlTexture(ImageWrapper image, bool isalpha)
 {
     this.filename = "";
     Init(image, isalpha);
 }
コード例 #27
0
ファイル: GlTexture.cs プロジェクト: beyonddiana/osmp-cs
        // 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);
        }
コード例 #28
0
 public void LoadBlendTextureFromFile(string filepath)
 {
     blendtexturefilename = filepath;
     blendtexture         = new ImageWrapper(filepath); // note to self: Is this right???
     onChanged();
 }
コード例 #29
0
ファイル: GlTexture.cs プロジェクト: beyonddiana/osmp-cs
        // create blank texture
        public GlTexture(int width, int height, bool isalpha)
        {
            ImageWrapper image = new ImageWrapper(width, height);

            Init(image, isalpha);
        }
コード例 #30
0
ファイル: Sm3Persistence.cs プロジェクト: hughperkins/osmp-cs
        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;
        }
コード例 #31
0
 void CreateBlankBlendTexture()
 {
     LogFile.WriteLine( "CreateBlankBlendTexture()" );
     blendtexture = new ImageWrapper( 256, 256 );
     //blendtexture.Save( "blankblend.jpg" );
     LogFile.WriteLine( "...done" );
 }
コード例 #32
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" );
 }
コード例 #33
0
ファイル: GlTexture.cs プロジェクト: beyonddiana/osmp-cs
        public static GlTexture FromFile(string filename)
        {
            ImageWrapper image = new ImageWrapper(filename);

            return(new GlTexture(image, filename, false));
        }
コード例 #34
0
ファイル: GlTexture.cs プロジェクト: beyonddiana/osmp-cs
        public static GlTexture FromAlphamapFile(string filename)
        {
            ImageWrapper image = new ImageWrapper(filename);

            return(new GlTexture(image, filename, true));
        }
コード例 #35
0
ファイル: Sm3Persistence.cs プロジェクト: hughperkins/osmp-cs
 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);
 }