private static MeshModel DeserializeComposite(ZipArchive zipFile) { var metadata = MeshModelMetadata.ExtractFrom(zipFile); var partCount = metadata.PartCount; // Vorschaubild lesen byte[] thumbnail = null; if (partCount != 1) { var entry = zipFile.GetEntry("PreviewImage.png"); if (entry != null) { using (var entryStream = entry.Open()) { thumbnail = MeshModelHelper.StreamToArray(entryStream); } } } // Parts lesen var parts = new List <MeshModelPart>(partCount); for (var i = 0; i < partCount; i += 1) { parts.Add(MeshModelPart.Deserialize(zipFile, i.ToString())); } return(new MeshModel(metadata, thumbnail, parts.ToArray())); }
/// <summary> /// Reads the data from the specified <paramref name="subFolder"/> in the specified <paramref name="zipFile"/> and deserializes the data found in it. /// If no <paramref name="subFolder"/> is specified, the method deserializes the data in the <paramref name="zipFile"/>s root directory. /// </summary> public static MeshModelPart Deserialize(ZipArchive zipFile, string subFolder = "") { var fileVersion10 = new Version(1, 0, 0, 0); var result = new MeshModelPart(new MeshModelMetadata()); result.Metadata = MeshModelMetadata.ExtractFrom(zipFile, subFolder); // Versionschecks var fileVersion = result.Metadata.FileVersion; if (fileVersion < fileVersion10) { throw new InvalidOperationException(MeshModelHelper.GetResource <MeshModel>("OldFileVersionError_Text")); } if (fileVersion.Major > MeshModel.MeshModelFileVersion.Major) { throw new InvalidOperationException(MeshModelHelper.FormatResource <MeshModel>("FileVersionError_Text", fileVersion, MeshModel.MeshModelFileVersion)); } // Vorschaubild lesen var thumbnailEntry = zipFile.GetEntry(Path.Combine(subFolder, "PreviewImage.png")); if (thumbnailEntry != null) { using (var entryStream = thumbnailEntry.Open()) { result._Thumbnail = MeshModelHelper.StreamToArray(entryStream); } } // Triangulierungsdaten lesen using (var binaryReader = new BinaryReader(zipFile.GetEntry(Path.Combine(subFolder, "Meshes.dat")).Open())) { var meshCount = binaryReader.ReadInt32(); var meshes = new List <Mesh>(meshCount); for (var i = 0; i < meshCount; i++) { meshes.Add(Mesh.Read(binaryReader, i, fileVersion)); } result.Meshes = meshes.ToArray(); } // Edgedaten lesen using (var binaryReader = new BinaryReader(zipFile.GetEntry(Path.Combine(subFolder, "Edges.dat")).Open())) { var edgeCount = binaryReader.ReadInt32(); var edges = new List <Edge>(edgeCount); for (var i = 0; i < edgeCount; i++) { edges.Add(Edge.Read(binaryReader, fileVersion)); } // we don't try to create a single-point edge result.Edges = edges.Where(e => e.Points?.Length > 3).ToArray(); } // Datenwerte lesen var meshValueList = new List <MeshValueList>(result.Metadata.MeshValueEntries?.Length ?? 0); foreach (var entry in result.Metadata.MeshValueEntries ?? new MeshValueEntry[0]) { using (var binaryReader = new BinaryReader(zipFile.GetEntry(Path.Combine(subFolder, entry.Filename)).Open())) { meshValueList.Add(MeshValueList.Read(binaryReader, entry, fileVersion)); } } result.MeshValues = meshValueList.ToArray(); return(result); }