static void LoadTextures(BinaryReader br, Header header) { // Read texdataStringTable br.BaseStream.Seek(header.lumps[44].fileofs, SeekOrigin.Begin); int nStringTable = header.lumps[44].filelen / sizeof(int); int[] StringTable = new int[nStringTable]; for (int i = 0; i < nStringTable; i++) { StringTable[i] = br.ReadInt32(); } // Read texture names StringBuilder strBuilder; string[] TextureNames = new string[nStringTable]; char singleChar; for (int i = 0; i < nStringTable; i++) { strBuilder = new StringBuilder(64, 128); // Seek to string br.BaseStream.Seek(header.lumps[43].fileofs + StringTable[i], SeekOrigin.Begin); // Read until max lenght or \0 byte while ((singleChar = br.ReadChar()) != '\0' && strBuilder.Length < 128) { strBuilder.Append(singleChar); } TextureNames[i] = strBuilder.ToString(); } // Read texdata br.BaseStream.Seek(header.lumps[2].fileofs, SeekOrigin.Begin); int nTextdata = header.lumps[2].filelen / 32; texdata_t[] texdatas = new texdata_t[nTextdata]; long materialTime = 0; for (int i = 0; i < nTextdata; i++) { texdata_t texdata; texdata.reflectivity = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); texdata.nameStringTableID = br.ReadInt32(); texdata.name = TextureNames[texdata.nameStringTableID]; texdata.width = br.ReadInt32(); texdata.height = br.ReadInt32(); texdata.view_width = br.ReadInt32(); texdata.view_height = br.ReadInt32(); long materialStart = HighResolutionTimer.Ticks; texdata.mat = TextureManager.Instance.LoadMaterial(texdata.name); materialTime += HighResolutionTimer.Ticks - materialStart; texdatas[i] = texdata; } // Read texinfo br.BaseStream.Seek(header.lumps[6].fileofs, SeekOrigin.Begin); int nTexinfo = header.lumps[6].filelen / 72; world.texinfos = new texinfo_t[nTexinfo]; for (int i = 0; i < nTexinfo; i++) { // Init structure texinfo_t texinfo; texinfo.textureVecs = new Vector4[2]; texinfo.lightmapVecs = new Vector3[2]; texinfo.lightmapVecs2 = new float[2]; // Read structure texinfo.textureVecs[0] = new Vector4(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); texinfo.textureVecs[1] = new Vector4(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); texinfo.lightmapVecs[0] = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); texinfo.lightmapVecs2[0] = br.ReadSingle(); texinfo.lightmapVecs[1] = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); texinfo.lightmapVecs2[1] = br.ReadSingle(); texinfo.flags = (SurfFlags)br.ReadInt32(); texinfo.texdata = br.ReadInt32(); texinfo.texdata_t = texdatas[texinfo.texdata]; world.texinfos[i] = texinfo; } }
void ReadTexInfos(Header header, BinaryReader br) { // Read texdata br.BaseStream.Seek(header.lumps[2].fileofs, SeekOrigin.Begin); int nTextdata = header.lumps[2].filelen / 32; texdata_t[] texdatas = new texdata_t[nTextdata]; for (int i = 0; i < nTextdata; i++) { texdata_t texdata = new texdata_t(); texdata.reflectivity = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); texdata.nameStringTableID = br.ReadInt32(); //texdata.name = TextureNames[texdata.nameStringTableID]; texdata.width = br.ReadInt32(); texdata.height = br.ReadInt32(); texdata.view_width = br.ReadInt32(); texdata.view_height = br.ReadInt32(); texdata.mat = null; texdatas[i] = texdata; } // Read texinfo br.BaseStream.Seek(header.lumps[6].fileofs, SeekOrigin.Begin); int nTexinfo = header.lumps[6].filelen / 72; texinfos = new texinfo_t[nTexinfo]; for (int i = 0; i < nTexinfo; i++) { // Init structure texinfo_t texinfo; texinfo.textureVecs = new Vector4[2]; texinfo.lightmapVecs = new Vector3[2]; texinfo.lightmapVecs2 = new float[2]; // Read structure texinfo.textureVecs[0] = new Vector4(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); texinfo.textureVecs[1] = new Vector4(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); texinfo.lightmapVecs[0] = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); texinfo.lightmapVecs2[0] = br.ReadSingle(); texinfo.lightmapVecs[1] = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); texinfo.lightmapVecs2[1] = br.ReadSingle(); texinfo.flags = (SurfFlags)br.ReadInt32(); texinfo.texdata = br.ReadInt32(); texinfo.texdata_t = texdatas[texinfo.texdata]; texinfos[i] = texinfo; } }