public WorldLOD(byte[] inData) { using (MemoryStream ms = new MemoryStream(inData)) { using (BinaryReader br = new BinaryReader(ms)) { // Set up the two area lists with default values for (int i = 0; i < 4096; ++i) { this.MapAreas.Add(null); this.MapAreaHoles.Add(null); } this.Version = br.ReadIFFChunk<TerrainVersion>(); if (br.PeekChunkSignature() == TerrainWorldModelObjects.Signature) { this.WorldModelObjects = br.ReadIFFChunk<TerrainWorldModelObjects>(); } if (br.PeekChunkSignature() == TerrainWorldObjectModelIndices.Signature) { this.WorldModelObjectIndices = br.ReadIFFChunk<TerrainWorldObjectModelIndices>(); } if (br.PeekChunkSignature() == TerrainWorldModelObjectPlacementInfo.Signature) { this.WorldModelObjectPlacementInfo = br.ReadIFFChunk<TerrainWorldModelObjectPlacementInfo>(); } this.MapAreaOffsets = br.ReadIFFChunk<WorldLODMapAreaOffsets>(); // Read the map areas and their holes for (int y = 0; y < 64; ++y) { for (int x = 0; x < 64; ++x) { int mapAreaOffsetIndex = (y * 64) + x; uint mapAreaOffset = this.MapAreaOffsets.MapAreaOffsets[mapAreaOffsetIndex]; if (mapAreaOffset > 0) { br.BaseStream.Position = mapAreaOffset; this.MapAreas[mapAreaOffsetIndex] = br.ReadIFFChunk<WorldLODMapArea>(); if (br.PeekChunkSignature() == WorldLODMapAreaHoles.Signature) { this.MapAreaHoles[mapAreaOffsetIndex] = br.ReadIFFChunk<WorldLODMapAreaHoles>(); } else { this.MapAreaHoles[mapAreaOffsetIndex] = WorldLODMapAreaHoles.CreateEmpty(); } } else { this.MapAreas[mapAreaOffsetIndex] = null; this.MapAreaHoles[mapAreaOffsetIndex] = null; } } } } } }
public void LoadBinaryData(byte[] inData) { using (MemoryStream ms = new MemoryStream(inData)) { using (BinaryReader br = new BinaryReader(ms)) { this.GroupNameOffset = br.ReadUInt32(); this.DescriptiveGroupNameOffset = br.ReadUInt32(); this.Flags = (GroupFlags) br.ReadUInt32(); this.BoundingBox = br.ReadBox(); this.PortalReferenceStartingIndex = br.ReadUInt16(); this.PortalReferenceCount = br.ReadUInt16(); this.RenderBatchCountA = br.ReadUInt16(); this.RenderBatchCountInterior = br.ReadUInt16(); this.RenderBatchCountExterior = br.ReadUInt16(); this.Unknown = br.ReadUInt16(); for (int i = 0; i < 4; ++i) { this.FogIndices.Add(br.ReadByte()); } this.LiquidType = br.ReadUInt32(); this.GroupID = new UInt32ForeignKey("WMOAreaTable", "WMOGroupID", br.ReadUInt32()); this.UnknownFlags = br.ReadUInt32(); this.Unused = br.ReadUInt32(); // Required subchunks this.PolygonMaterials = br.ReadIFFChunk<ModelPolygonMaterials>(); this.VertexIndices = br.ReadIFFChunk<ModelVertexIndices>(); this.Vertices = br.ReadIFFChunk<ModelVertices>(); this.Normals = br.ReadIFFChunk<ModelNormals>(); this.TextureCoordinates = br.ReadIFFChunk<ModelTextureCoordinates>(); this.RenderBatches = br.ReadIFFChunk<ModelRenderBatches>(); // Optional chunks if (br.PeekChunkSignature() == MOBS.Signature) { this.mobs = br.ReadIFFChunk<MOBS>(); } if (this.Flags.HasFlag(GroupFlags.HasLights)) { this.LightReferences = br.ReadIFFChunk<ModelLightReferences>(); } if (this.Flags.HasFlag(GroupFlags.HasDoodads)) { this.DoodadReferences = br.ReadIFFChunk<ModelDoodadReferences>(); } if (this.Flags.HasFlag(GroupFlags.HasBSP)) { this.BSPNodes = br.ReadIFFChunk<ModelBSPNodes>(); this.BSPFaceIndices = br.ReadIFFChunk<ModelBSPFaceIndices>(); } if (this.Flags.HasFlag(GroupFlags.UnknownLODRelated)) { this.mpbv = br.ReadIFFChunk<MPBV>(); this.mpbp = br.ReadIFFChunk<MPBP>(); this.mpbi = br.ReadIFFChunk<MPBI>(); this.mpbg = br.ReadIFFChunk<MPBG>(); } if (this.Flags.HasFlag(GroupFlags.HasVertexColours)) { this.VertexColours = br.ReadIFFChunk<ModelVertexColours>(); } if (this.Flags.HasFlag(GroupFlags.HasLiquids)) { this.Liquids = br.ReadIFFChunk<ModelLiquids>(); } if (this.Flags.HasFlag(GroupFlags.HasTriangleStrips)) { this.TriangleStripIndices = br.ReadIFFChunk<ModelTriangleStripIndices>(); this.TriangleStrips = br.ReadIFFChunk<ModelTriangleStrips>(); } if (this.Flags.HasFlag(GroupFlags.HasTwoTextureCoordinateSets)) { this.AdditionalTextureCoordinates = br.ReadIFFChunk<ModelTextureCoordinates>(); } if (this.Flags.HasFlag(GroupFlags.HasTwoVertexShadingSets)) { this.AdditionalVertexColours = br.ReadIFFChunk<ModelVertexColours>(); } if (this.Flags.HasFlag(GroupFlags.HasThreeTextureCoordinateSets)) { this.SecondAddtionalTextureCoordinates = br.ReadIFFChunk<ModelTextureCoordinates>(); } } } }
public ModelRoot(byte[] inData) { using (MemoryStream ms = new MemoryStream(inData)) { using (BinaryReader br = new BinaryReader(ms)) { this.Version = br.ReadIFFChunk<TerrainVersion>(); this.Header = br.ReadIFFChunk<ModelRootHeader>(); this.Textures = br.ReadIFFChunk<ModelTextures>(); this.Materials = br.ReadIFFChunk<ModelMaterials>(); this.GroupNames = br.ReadIFFChunk<ModelGroupNames>(); this.GroupInformation = br.ReadIFFChunk<ModelGroupInformation>(); this.Skybox = br.ReadIFFChunk<ModelSkybox>(); this.PortalVertices = br.ReadIFFChunk<ModelPortalVertices>(); this.Portals = br.ReadIFFChunk<ModelPortals>(); this.PortalReferences = br.ReadIFFChunk<ModelPortalReferences>(); this.VisibleVertices = br.ReadIFFChunk<ModelVisibleVertices>(); this.VisibleBlocks = br.ReadIFFChunk<ModelVisibleBlocks>(); this.StaticLighting = br.ReadIFFChunk<ModelStaticLighting>(); this.DoodadSets = br.ReadIFFChunk<ModelDoodadSets>(); this.DoodadPaths = br.ReadIFFChunk<ModelDoodadPaths>(); this.DoodadInstances = br.ReadIFFChunk<ModelDoodadInstances>(); this.Fog = br.ReadIFFChunk<ModelFog>(); // Optional chunk if ((br.BaseStream.Position != br.BaseStream.Length) && br.PeekChunkSignature() == ModelConvexPlanes.Signature) { this.ConvexPlanes = br.ReadIFFChunk<ModelConvexPlanes>(); } // Version-dependent chunk if ((br.BaseStream.Position != br.BaseStream.Length) && br.PeekChunkSignature() == ModelGameObjectFileID.Signature) { this.GameObjectFileID = br.ReadIFFChunk<ModelGameObjectFileID>(); } } } }