Exemple #1
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>();
                    }
                }
            }
        }
Exemple #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>
        /// <inheritdoc/>
        public void LoadBinaryData(byte[] inData)
        {
            using (var ms = new MemoryStream(inData))
            {
                using (var br = new BinaryReader(ms))
                {
                    GroupNameOffset            = br.ReadUInt32();
                    DescriptiveGroupNameOffset = br.ReadUInt32();

                    Flags = (GroupFlags)br.ReadUInt32();

                    BoundingBox = br.ReadBox();

                    FirstPortalReferenceIndex = br.ReadUInt16();
                    PortalReferenceCount      = br.ReadUInt16();

                    RenderBatchCountA        = br.ReadUInt16();
                    RenderBatchCountInterior = br.ReadUInt16();
                    RenderBatchCountExterior = br.ReadUInt16();
                    Unknown = br.ReadUInt16();

                    for (var i = 0; i < 4; ++i)
                    {
                        FogIndices.Add(br.ReadByte());
                    }

                    LiquidType = br.ReadUInt32();
                    GroupID    = new ForeignKey <uint>(DatabaseName.WMOAreaTable, nameof(WMOAreaTableRecord.WMOGroupID), br.ReadUInt32());

                    UnknownFlags = br.ReadUInt32();
                    Unused       = br.ReadUInt32();

                    // Required subchunks
                    PolygonMaterials   = br.ReadIFFChunk <ModelPolygonMaterials>();
                    VertexIndices      = br.ReadIFFChunk <ModelVertexIndices>();
                    Vertices           = br.ReadIFFChunk <ModelVertices>();
                    Normals            = br.ReadIFFChunk <ModelNormals>();
                    TextureCoordinates = br.ReadIFFChunk <ModelTextureCoordinates>();
                    RenderBatches      = br.ReadIFFChunk <ModelRenderBatches>();

                    // Optional chunks
                    if (Flags.HasFlag(GroupFlags.HasLights))
                    {
                        LightReferences = br.ReadIFFChunk <ModelLightReferences>();
                    }

                    if (Flags.HasFlag(GroupFlags.HasDoodads))
                    {
                        DoodadReferences = br.ReadIFFChunk <ModelDoodadReferences>();
                    }

                    if (Flags.HasFlag(GroupFlags.HasBSP))
                    {
                        BSPNodes       = br.ReadIFFChunk <ModelBSPNodes>();
                        BSPFaceIndices = br.ReadIFFChunk <ModelBSPFaceIndices>();
                    }

                    if (Flags.HasFlag(GroupFlags.HasVertexColours))
                    {
                        VertexColours = br.ReadIFFChunk <ModelVertexColours>();
                    }

                    if (Flags.HasFlag(GroupFlags.HasLiquids))
                    {
                        Liquids = br.ReadIFFChunk <ModelLiquids>();
                    }

                    if (Flags.HasFlag(GroupFlags.HasTwoTextureCoordinateSets))
                    {
                        AdditionalTextureCoordinates = br.ReadIFFChunk <ModelTextureCoordinates>();
                    }

                    if (Flags.HasFlag(GroupFlags.HasTwoVertexShadingSets))
                    {
                        AdditionalVertexColours = br.ReadIFFChunk <ModelVertexColours>();
                    }

                    if (Flags.HasFlag(GroupFlags.HasThreeTextureCoordinateSets))
                    {
                        SecondAddtionalTextureCoordinates = br.ReadIFFChunk <ModelTextureCoordinates>();
                    }
                }
            }
        }