public static BSPNode ReadNode(BinaryReader reader, BSPType treeType) { // We peek forward to get the type, then revert our position. var type = Encoding.ASCII.GetString(reader.ReadBytes(4)).Reverse(); reader.BaseStream.Position -= 4; BSPNode node; switch (type) { case "PORT": node = new BSPPortal(); break; case "LEAF": node = new BSPLeaf(); break; case "BPnn": case "BPIn": case "BpIN": case "BpnN": case "BPIN": case "BPnN": default: node = new BSPNode(); break; } node.Unpack(reader, treeType); return(node); }
public static BSPNode ReadNode(BinaryReader reader, BSPType treeType) { // We peek forward to get the type, then revert our position. var type = reader.ReadUInt32(); reader.BaseStream.Position -= 4; BSPNode node; switch (type) { case PORT: node = new BSPPortal(); break; case LEAF: node = new BSPLeaf(); break; case BPnn: case BPIn: case BpIN: case BpnN: case BPIN: case BPnN: default: node = new BSPNode(); break; } node.Unpack(reader, treeType); return(node); }
} = new List <ushort>(); // List of PolygonIds public static BSPNode Read(DatReader datReader, BSPType treeType) { BSPNode obj = new BSPNode(); obj.Type = datReader.ReadUInt32(); switch (obj.Type) { case PORT: return(BSPPortal.ReadPortal(datReader, treeType)); case LEAF: return(BSPLeaf.ReadLeaf(datReader, treeType)); } obj.SplittingPlane = Plane.Read(datReader); switch (obj.Type) { case BPnn: case BPIn: obj.PosNode = BSPNode.Read(datReader, treeType); break; case BpIN: case BpnN: obj.NegNode = BSPNode.Read(datReader, treeType); break; case BPIN: case BPnN: obj.PosNode = BSPNode.Read(datReader, treeType); obj.NegNode = BSPNode.Read(datReader, treeType); break; } if (treeType == BSPType.Cell) { return(obj); } obj.Sphere = CSphere.Read(datReader); if (treeType == BSPType.Physics) { return(obj); } uint numPolys = datReader.ReadUInt32(); for (uint i = 0; i < numPolys; i++) { obj.InPolys.Add(datReader.ReadUInt16()); } return(obj); }
public static BSPLeaf ReadLeaf(DatReader datReader, BSPType treeType) { BSPLeaf obj = new BSPLeaf(); obj.Type = 0x4C454146; // LEAF obj.LeafIndex = datReader.ReadInt32(); if (treeType == BSPType.Physics) { obj.Solid = datReader.ReadInt32(); // Note that if Solid is equal to 0, these values will basically be null. Still read them, but they don't mean anything. obj.Sphere = CSphere.Read(datReader); uint numPolys = datReader.ReadUInt32(); for (uint i = 0; i < numPolys; i++) { obj.InPolys.Add(datReader.ReadUInt16()); } } return(obj); }