using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; namespace OpenVIII.Battle.Dat { /// /// Section 2: Model geometry /// /// [StructLayout(LayoutKind.Sequential, Pack = 1)] public class Geometry { #region Fields /// /// Number of objects /// public readonly int CObjects; /// /// Object Data (see below) /// public readonly IReadOnlyList Objects; /// /// Object Positions /// public readonly IReadOnlyList PObjects; /// /// Total count of vertices /// public readonly uint CTotalVertices; #endregion Fields #region Constructors private Geometry(BinaryReader br, long byteOffset) { CObjects = br.ReadInt32(); PObjects = Enumerable.Range(0, CObjects).Select(_ => br.ReadUInt32()).ToList().AsReadOnly(); Objects = PObjects.Select(pOffset => Object.CreateInstance(br, pOffset + byteOffset)).ToList().AsReadOnly(); CTotalVertices = br.ReadUInt32(); } #endregion Constructors #region Methods public static Geometry CreateInstance(BinaryReader br, long byteOffset) { br.BaseStream.Seek(byteOffset, SeekOrigin.Begin); return new Geometry(br, byteOffset); } #endregion Methods } }