ImageWrapper LoadBlendTexture( string sm3directory, TdfParser.Section terrainsection, string texturesectionname ) { TdfParser.Section texturesection = terrainsection.SubSection(texturesectionname); string texturename = Path.Combine( sm3directory, texturesection.GetStringValue("file") ); LogFile.WriteLine(texturename); return new ImageWrapper( texturename ); //return GlTexture.FromAlphamapFile(texturename); }
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; }
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; }
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); }