/// <summary> /// Writes a geometrymesh to a file, given a streamwriter. /// </summary> /// <param name="type">The geometry mesh.</param> /// <param name="location">The streamwriter.</param> public void WriteFile(GeometryMesh type, StreamWriter writer) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } g3.OFFWriter offWriter = new g3.OFFWriter(); List <WriteMesh> serialisableMeshes = new List <WriteMesh>() { new WriteMesh(type.Base) }; IOWriteResult result = offWriter.Write(writer, serialisableMeshes, Options); if (result.code != IOCode.Ok) { throw new G3WriterException(result); } IOConventions.WriteIfNormalised(type.IsNormalised, writer); }
/// <summary> /// Writes an unstructured mesh to an off file with a given streamwriter. /// </summary> /// <param name="type">The unstructured mesh that needs to be written to an off file.</param> /// <param name="writer">The streamwriter that needs to be used.</param> public void WriteFile(IMesh type, StreamWriter writer) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } Thread.CurrentThread.CurrentCulture = Settings.Culture; writer.WriteLine("OFF"); writer.WriteLine($"{type.VertexCount} {type.FaceCount} 0"); foreach (Vector3 vertice in type.Vertices) { writer.WriteLine($"{vertice.X} {vertice.Y} {vertice.Z}"); } foreach (Vector3 face in type.Faces) { writer.WriteLine($"3 {face.X} {face.Y} {face.Z}"); } IOConventions.WriteIfNormalised(type.IsNormalised, writer); }
/// <summary> /// Writes a geometrymesh to a file, given a location. /// </summary> /// <param name="type">The geometry mesh.</param> /// <param name="location">The location of the file.</param> public void WriteFile(GeometryMesh type, string location) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (string.IsNullOrEmpty(location)) { throw new ArgumentNullException(nameof(location)); } IOWriteResult result = StandardMeshWriter.WriteMesh( location, type.Base, Options); if (result.code != IOCode.Ok) { throw new G3WriterException(result); } using (StreamWriter writer = File.AppendText(location)) { IOConventions.WriteIfNormalised(type.IsNormalised, writer); } }