public MeshFile Read(Stream s)
        {
            var file = new MeshFile();

            file.Header = ReadHeader(s);
            file.SubHeader = ReadSubHeader(s);

            file.MultiMaterialMeshFiles = ReadMeshDictionary(s, file);

            file.TextureBindings = ReadTextureBindings(s, file);

            return file;
        }
        protected ObservableCollection<MeshContentFile> ReadMeshDictionary(Stream s, MeshFile f)
        {
            var files = new ObservableCollection<MeshContentFile>();
            var dirs = new List<EdataDir>();
            var endings = new List<long>();

            s.Seek(f.SubHeader.Dictionary.Offset, SeekOrigin.Begin);

            long dirEnd = f.SubHeader.Dictionary.Offset + f.SubHeader.Dictionary.Size;

            while (s.Position < dirEnd)
            {
                var buffer = new byte[4];
                s.Read(buffer, 0, 4);
                int fileGroupId = BitConverter.ToInt32(buffer, 0);

                if (fileGroupId == 0)
                {
                    var file = new MeshContentFile();
                    s.Read(buffer, 0, 4);
                    file.FileEntrySize = BitConverter.ToUInt32(buffer, 0);

                    var minp = new Point3D();
                    s.Read(buffer, 0, buffer.Length);
                    minp.X = BitConverter.ToSingle(buffer, 0);
                    s.Read(buffer, 0, buffer.Length);
                    minp.Y = BitConverter.ToSingle(buffer, 0);
                    s.Read(buffer, 0, buffer.Length);
                    minp.Z = BitConverter.ToSingle(buffer, 0);
                    file.MinBoundingBox = minp;

                    var maxp = new Point3D();
                    s.Read(buffer, 0, buffer.Length);
                    maxp.X = BitConverter.ToSingle(buffer, 0);
                    s.Read(buffer, 0, buffer.Length);
                    maxp.Y = BitConverter.ToSingle(buffer, 0);
                    s.Read(buffer, 0, buffer.Length);
                    maxp.Z = BitConverter.ToSingle(buffer, 0);
                    file.MaxBoundingBox = maxp;

                    s.Read(buffer, 0, buffer.Length);
                    file.Flags = BitConverter.ToUInt32(buffer, 0);

                    buffer = new byte[2];

                    s.Read(buffer, 0, buffer.Length);
                    file.MultiMaterialMeshIndex = BitConverter.ToUInt16(buffer, 0);

                    s.Read(buffer, 0, buffer.Length);
                    file.HierarchicalAseModelSkeletonIndex = BitConverter.ToUInt16(buffer, 0);

                    file.Name = Utils.ReadString(s);
                    file.Path = MergePath(dirs, file.Name);

                    if (file.Name.Length % 2 == 0)
                        s.Seek(1, SeekOrigin.Current);

                    files.Add(file);

                    while (endings.Count > 0 && s.Position == endings.Last())
                    {
                        dirs.Remove(dirs.Last());
                        endings.Remove(endings.Last());
                    }
                }
                else if (fileGroupId > 0)
                {
                    var dir = new EdataDir();

                    s.Read(buffer, 0, 4);
                    dir.FileEntrySize = BitConverter.ToInt32(buffer, 0);

                    if (dir.FileEntrySize != 0)
                        endings.Add(dir.FileEntrySize + s.Position - 8);
                    else if (endings.Count > 0)
                        endings.Add(endings.Last());

                    dir.Name = Utils.ReadString(s);

                    if (dir.Name.Length % 2 == 0)
                        s.Seek(1, SeekOrigin.Current);

                    dirs.Add(dir);
                }
            }

            return files;
        }
        private Model.Ndfbin.NdfBinary ReadTextureBindings(Stream s, MeshFile file)
        {
            var buffer = new byte[file.SubHeader.MeshMaterial.Size];

            s.Seek(file.SubHeader.MeshMaterial.Offset, SeekOrigin.Begin);
            s.Read(buffer, 0, buffer.Length);

            var ndfReader = new NdfbinReader();

            return ndfReader.Read(buffer);
        }
        public MeshEditorViewModel(MeshFile file)
        {
            MeshFile = file;

            EditTextureBindingsCommand = new ActionCommand(EditTextureBindingsExecute);
        }