ITexture LoadTexture(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.GetInstance().WriteLine(texturename); tilesize = texturesection.GetIntValue("tilesize"); return(GlTexture.FromFile(texturename)); }
public RenderableS3o(string s3opath) { g = new GraphicsHelperGl(); unit = new S3oLoader().LoadS3o(s3opath); if (unit.texturename1 == "Spring unit") { unit.texturename1 = "Default.tga"; unit.texturename2 = "Default.tga"; } string texturedirectory = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(s3opath)), "unittextures"); LogFile.GetInstance().WriteLine(texturedirectory + "\\" + unit.texturename1 + "]"); texture1 = GlTexture.FromFile(texturedirectory + "/" + unit.texturename1); }
// static int count = 0; public Unit LoadS3o(string filename) { // if (count > 10) // { // throw new Exception(""); //} // count++; FileStream inStream = new FileStream(filename, FileMode.Open, FileAccess.Read); byte[] sdobytes = new byte[inStream.Length]; inStream.Read(sdobytes, 0, (int)inStream.Length); inStream.Seek(0, SeekOrigin.Begin); int offset = 0; _S3OHeader s3oheader = new _S3OHeader(); s3oheader = (_S3OHeader)ReadBinary(s3oheader, sdobytes, offset); DumpBytes(sdobytes, 0, 30); LogFile.GetInstance().WriteLine("[" + s3oheader.magic + "] [" + magiccode + "]"); if (s3oheader.magic.Trim() != magiccode.Trim()) { throw new Exception("Not an s3o file"); } LogFile.GetInstance().WriteLine("Version: " + s3oheader.version); Unit unit = new Unit(); unit.Height = s3oheader.height; unit.Mid = new Vector3(s3oheader.midx, s3oheader.midy, s3oheader.midz); unit.Radius = s3oheader.radius; LogFile.GetInstance().WriteLine(ReadString(sdobytes, (int)s3oheader.texture1)); LogFile.GetInstance().WriteLine(ReadString(sdobytes, (int)s3oheader.texture2)); unit.texturename1 = ReadString(sdobytes, (int)s3oheader.texture1); unit.texturename2 = ReadString(sdobytes, (int)s3oheader.texture2); if (unit.texturename1 == "Spring unit") { unit.texturename1 = "Default.JPG"; unit.texturename2 = "Default.JPG"; } string texturedirectory = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(filename)), "unittextures"); string texture1filepath = texturedirectory + "\\" + unit.texturename1; string texture2filepath = texturedirectory + "\\" + unit.texturename2; LogFile.GetInstance().WriteLine(texturedirectory + "\\" + unit.texturename1 + "]"); //System.Drawing.Bitmap blankbitmap = new System.Drawing.Bitmap(1, 1); //blankbitmap.SetPixel(0, 0, System.Drawing.Color.FromArgb(255, 255, 255)); if (File.Exists(texture1filepath)) { unit.texture1 = GlTexture.FromFile(texturedirectory + "/" + unit.texturename1); } else { MapDesigner.MainUI.GetInstance().uiwindow.WarningMessage("Couldnt find texture " + texture1filepath + " , whilst loading " + filename + " . The object may not appear correctly"); unit.texture1 = new GlTexture(false); } if (File.Exists(texture2filepath)) { unit.texture2 = GlTexture.FromFile(texturedirectory + "/" + unit.texturename2); } else { MapDesigner.MainUI.GetInstance().uiwindow.WarningMessage("Couldnt find texture " + texture2filepath + " , whilst loading " + filename + " . The object may not appear correctly"); unit.texture2 = new GlTexture(false); } unit.unitpart = LoadUnitPart(sdobytes, Convert.ToInt32(s3oheader.rootPiece)); unit.Name = Path.GetFileNameWithoutExtension(filename).ToLower(); return(unit); }