public static void Main(string[] args) { if (args.Length < 1) { Usage(); Console.WriteLine("ERROR: No arguments were given."); return; } var map1 = new BspFile(); map1.Load(args[0]); //LoadMap(args[0]); foreach (var texture in map1.GetLump <TexDataLump>().Data) { texture.TexName = "R997/Mc/Mc-Jackolantern"; } map1.Save("test.bsp"); var map2 = new BspFile(); map2.Load("test.bsp"); // // foreach (var ent in map.GetLump<EntityLump>().Data.Where(ent => ent.Properties.ContainsKey("skyname"))) // { // ent.Properties["skyname"] = "sky_day01_09"; // Console.WriteLine("hi"); // } // var lastoffset = 0; // foreach (var lump in map.Lumps.OrderBy(lump => lump.Offset)) // { // Console.WriteLine("Lump {0}, offset {1}, length {2}, last offset {3}, diff {4}", lump.Type, lump.Offset, lump.Length, lastoffset, lump.Offset - lastoffset); // lastoffset = lump.Offset; // } // var pakfile = new Pakfile(map); // ZipArchive archive = pakfile.GetZipArchive(); // foreach (var entry in archive.Entries) // { // Console.WriteLine(entry.Name); // } }
public void PostReadProcess(BspFile bsp) { Texinfo textureInfos = bsp.GetLump <Texinfo>(); Planes planes = bsp.GetLump <Planes>(); Surfedges surfEdges = bsp.GetLump <Surfedges>(); Edges edges = bsp.GetLump <Edges>(); Vertices vertices = bsp.GetLump <Vertices>(); List <Face> faces = bsp.GetLump <Faces>() .Where(x => x.Styles.Length > 0 && x.Styles[0] != byte.MaxValue) // Indicates a fullbright face, no offset .Where(x => x.LightmapOffset >= 0 && x.LightmapOffset < _lightmapData.Length) // Invalid offset .ToList(); Dictionary <int, Lightmap> offsetDict = new Dictionary <int, Lightmap>(); foreach (Face face in faces) { if (offsetDict.ContainsKey(face.LightmapOffset)) { continue; } TextureInfo ti = textureInfos[face.TextureInfo]; Plane pl = planes[face.Plane]; List <Vector2> uvs = new List <Vector2>(); for (int i = 0; i < face.NumEdges; i++) { int ei = surfEdges[face.FirstEdge + i]; Edge edge = edges[Math.Abs(ei)]; Vector3 point = vertices[ei > 0 ? edge.Start : edge.End]; Vector3 sn = new Vector3(ti.S.X, ti.S.Y, ti.S.Z); float u = Vector3.Dot(point, sn) + ti.S.W; Vector3 tn = new Vector3(ti.T.X, ti.T.Y, ti.T.Z); float v = Vector3.Dot(point, tn) + ti.T.W; uvs.Add(new Vector2(u, v)); } float minu = uvs.Min(x => x.X); float maxu = uvs.Max(x => x.X); float minv = uvs.Min(x => x.Y); float maxv = uvs.Max(x => x.Y); int width = (int)Math.Ceiling(maxu / 16) - (int)Math.Floor(minu / 16) + 1; int height = (int)Math.Ceiling(maxv / 16) - (int)Math.Floor(minv / 16) + 1; int bpp = bsp.Version == Version.Quake1 ? 1 : 3; byte[] data = new byte[bpp * width * height]; Array.Copy(_lightmapData, face.LightmapOffset, data, 0, data.Length); Lightmap map = new Lightmap { Offset = face.LightmapOffset, Width = width, Height = height, BitsPerPixel = bpp, Data = data }; _lightmaps.Add(map); offsetDict.Add(map.Offset, map); } }
public Pakfile(BspFile bspFile) { ParentFile = bspFile; Paklump = (UnmanagedLump)bspFile.GetLump(LumpType.LUMP_PAKFILE); }