public void Read(BinaryReader reader)
 {
     SectionType = (SectionType)reader.ReadInt32();
     SectionSize = reader.ReadInt32();
     reader.BaseStream.Seek(sizeof(short), SeekOrigin.Current); // пропускаем "unknown"
     Version = (DffVersion)reader.ReadInt16();
 }
        private void ParseDataSection(int sectionSize, SectionType parent, DffVersion version)
        {
            switch (parent)
            {
            case SectionType.Geometry:
                ParseGeometry(version);
                break;

            case SectionType.Material:
                ParseMaterial(sectionSize);
                break;

            case SectionType.FrameList:
                ParseFramesList();
                break;

            case SectionType.Atomic:
                ParseAtomic();
                break;

            default:
                input.BaseStream.Seek(sectionSize, SeekOrigin.Current);
                break;
            }
        }
        /// <summary>
        /// Обрабатывает секцию Geometry
        /// Считывает вершины, треугольники (индексы вершин), нормали, текстурные координаты.
        /// </summary>
        private void ParseGeometry(DffVersion version)
        {
            ModelMeshData mesh = new ModelMeshData();

            GeometrySectionFlags flags = (GeometrySectionFlags)input.ReadInt16();

            input.BaseStream.Seek(sizeof(short), SeekOrigin.Current); // unknown

            int trianglesCount = input.ReadInt32();
            int verticesCount  = input.ReadInt32();

            input.BaseStream.Seek(sizeof(int), SeekOrigin.Current); // morphTargetCount aka frameCount

            if (version < DffVersion.GTA_VC_2)
            {
                // geometry has lighting data. Ignoring it.
                // TODO :: we can use it for rendering!!!
                input.BaseStream.Seek(12, SeekOrigin.Current);
            }

            if ((flags & GeometrySectionFlags.MultipleTextureCoords) != GeometrySectionFlags.None)
            {
                Log.Instance.Print("Multiple TexCoords sets are provided but used only the first of it!", MessageType.Warning);
            }

            if ((flags & GeometrySectionFlags.HasColorInfo) != GeometrySectionFlags.None)
            {
                ReadColors(mesh, verticesCount);
            }
            else
            {
                FillColors(mesh, verticesCount);
            }

            if ((flags & GeometrySectionFlags.HasTextureCoords) != GeometrySectionFlags.None)
            {
                ReadTextureCoords(mesh, verticesCount);
            }

            ReadTriangles(mesh, trianglesCount);

            input.BaseStream.Seek(4 * sizeof(float), SeekOrigin.Current); // ignoring bounding sphere (x, y, z, radius)
            input.BaseStream.Seek(2 * sizeof(int), SeekOrigin.Current);   // hasPosition, hasNormal (not used)

            ReadVertices(mesh, verticesCount);

            if ((flags & GeometrySectionFlags.HasNormalsInfo) != GeometrySectionFlags.None)
            {
                ReadNormals(mesh, verticesCount);
            }

            modelData.Meshes.Add(mesh);
        }
 public void Read(BinaryReader reader)
 {
     SectionType = (SectionType)reader.ReadInt32();
     SectionSize = reader.ReadInt32();
     reader.BaseStream.Seek(sizeof(short), SeekOrigin.Current); // пропускаем "unknown"
     Version = (DffVersion)reader.ReadInt16();
 }
        /// <summary>
        /// Обрабатывает секцию Geometry
        /// Считывает вершины, треугольники (индексы вершин), нормали, текстурные координаты.
        /// </summary>
        private void ParseGeometry(DffVersion version)
        {
            ModelMeshData mesh = new ModelMeshData();

             GeometrySectionFlags flags = (GeometrySectionFlags)input.ReadInt16();

             input.BaseStream.Seek(sizeof(short), SeekOrigin.Current); // unknown

             int trianglesCount = input.ReadInt32();
             int verticesCount = input.ReadInt32();
             input.BaseStream.Seek(sizeof(int), SeekOrigin.Current); // morphTargetCount aka frameCount

             if (version < DffVersion.GTA_VC_2)
             {
            // geometry has lighting data. Ignoring it.
            // TODO :: we can use it for rendering!!!
            input.BaseStream.Seek(12, SeekOrigin.Current);
             }

             if ((flags & GeometrySectionFlags.MultipleTextureCoords) != GeometrySectionFlags.None)
            Log.Instance.Print("Multiple TexCoords sets are provided but used only the first of it!", MessageType.Warning);

             if ((flags & GeometrySectionFlags.HasColorInfo) != GeometrySectionFlags.None)
            ReadColors(mesh, verticesCount);
             else
            FillColors(mesh, verticesCount);

             if ((flags & GeometrySectionFlags.HasTextureCoords) != GeometrySectionFlags.None)
            ReadTextureCoords(mesh, verticesCount);

             ReadTriangles(mesh, trianglesCount);

             input.BaseStream.Seek(4 * sizeof(float), SeekOrigin.Current); // ignoring bounding sphere (x, y, z, radius)
             input.BaseStream.Seek(2 * sizeof(int), SeekOrigin.Current); // hasPosition, hasNormal (not used)

             ReadVertices(mesh, verticesCount);

             if ((flags & GeometrySectionFlags.HasNormalsInfo) != GeometrySectionFlags.None)
            ReadNormals(mesh, verticesCount);

             modelData.Meshes.Add(mesh);
        }
        private void ParseDataSection(int sectionSize, SectionType parent, DffVersion version)
        {
            switch(parent)
             {
            case SectionType.Geometry:
               ParseGeometry(version);
               break;

            case SectionType.Material:
               ParseMaterial(sectionSize);
               break;

            case SectionType.FrameList:
               ParseFramesList();
               break;

            case SectionType.Atomic:
               ParseAtomic();
               break;

            default:
               input.BaseStream.Seek(sectionSize, SeekOrigin.Current);
               break;
             }
        }