Example #1
0
        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>();
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Deserialzes the provided binary data of the object. This is the full data block which follows the data
        /// signature and data block length.
        /// </summary>
        /// <param name="inData">The binary data containing the object.</param>
        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>();
                    }
                }
            }
        }