Beispiel #1
0
        public DatFile(string filename, bool deformMainModel)
        {
            if (filename.EndsWith(".ACT", StringComparison.InvariantCultureIgnoreCase))
            {
                filename = filename.ToUpper().Replace(".ACT", ".DAT");                 //fix up some 3rd party vehicle weirdness
            }
            CModel currentModel = null;

            Stream file = OpenDataFile(filename);

            if (!Exists)
            {
                return;
            }

            EndianBinaryReader reader = new EndianBinaryReader(EndianBitConverter.Big, file);

            while (true)
            {
                int type = reader.ReadInt32();
                int size = 0;
                if (type != (int)BlockType.Null)
                {
                    size = reader.ReadInt32();
                }

                switch (type)
                {
                case (int)BlockType.Null:
                    break;

                case (int)BlockType.ModelName:
                    reader.Seek(2, SeekOrigin.Current);
                    string name = ReadNullTerminatedString(reader);

                    if (deformMainModel && Path.GetFileNameWithoutExtension(name).Equals(Path.GetFileNameWithoutExtension(filename), StringComparison.InvariantCultureIgnoreCase))
                    {
                        currentModel = new CDeformableModel();
                    }
                    else
                    {
                        currentModel = new CModel();
                    }

                    currentModel.Name = name;
                    _models.Add(currentModel);

                    break;

                case (int)BlockType.Vertices:
                    ReadVertexBlock(reader, currentModel);
                    break;

                case (int)BlockType.Faces:
                    ReadPolygonBlock(reader, currentModel);
                    break;

                case (int)BlockType.TextureCoords:
                    ReadTextureMapBlock(reader, currentModel);
                    break;

                case (int)BlockType.Materials:
                    ReadMaterialsBlock(reader, currentModel);
                    break;

                case (int)BlockType.FaceMaterials:
                    ReadFaceMaterialsBlock(reader, currentModel);
                    break;

                default:
                    Debug.WriteLine("Unknown section: " + type);
                    reader.Seek(size, SeekOrigin.Current);
                    break;
                }

                if (reader.BaseStream.Position == reader.BaseStream.Length)
                {
                    break;
                }
            }

            reader.Close();
            if (filename == "FAUST.DAT")
            {
            }
            _models.Resolve(true);
        }
Beispiel #2
0
        public DatFile(string filename, bool deformMainModel)
        {
            if (filename.EndsWith(".ACT", StringComparison.InvariantCultureIgnoreCase))
                filename = filename.ToUpper().Replace(".ACT", ".DAT"); //fix up some 3rd party vehicle weirdness

            CModel currentModel = null;

            Stream file = OpenDataFile(filename);
            if (!Exists)
                return;

            EndianBinaryReader reader = new EndianBinaryReader(EndianBitConverter.Big, file);

            while (true)
            {
                int type = reader.ReadInt32();
                int size = 0;
                if (type != (int)BlockType.Null)
                    size = reader.ReadInt32();

                switch (type)
                {
                    case (int)BlockType.Null:
                        break;

                    case (int)BlockType.ModelName:
                        reader.Seek(2, SeekOrigin.Current);
                        string name = ReadNullTerminatedString(reader);

                        if (deformMainModel && Path.GetFileNameWithoutExtension(name).Equals(Path.GetFileNameWithoutExtension(filename), StringComparison.InvariantCultureIgnoreCase))
                            currentModel = new CDeformableModel();
                        else
                            currentModel = new CModel();

                        currentModel.Name = name;
                        _models.Add(currentModel);

                        break;

                    case (int)BlockType.Vertices:
                        ReadVertexBlock(reader, currentModel);
                        break;

                    case (int)BlockType.Faces:
                        ReadPolygonBlock(reader, currentModel);
                        break;

                    case (int)BlockType.TextureCoords:
                        ReadTextureMapBlock(reader, currentModel);
                        break;

                    case (int)BlockType.Materials:
                        ReadMaterialsBlock(reader, currentModel);
                        break;

                    case (int)BlockType.FaceMaterials:
                        ReadFaceMaterialsBlock(reader, currentModel);
                        break;

                    default:
                        Debug.WriteLine("Unknown section: " + type);
                        reader.Seek(size, SeekOrigin.Current);
                        break;
                }

                if (reader.BaseStream.Position == reader.BaseStream.Length)
                    break;
            }

            reader.Close();
            if (filename == "FAUST.DAT")
            {
            }
            _models.Resolve(true);
        }