| | 1 | | // <copyright file="ObjMaterialFile.cs" company="Jérémy Ansel"> |
| | 2 | | // Copyright (c) 2017, 2019 Jérémy Ansel |
| | 3 | | // </copyright> |
| | 4 | | // <license> |
| | 5 | | // Licensed under the MIT license. See LICENSE.txt |
| | 6 | | // </license> |
| | 7 | |
|
| | 8 | | using System.Text; |
| | 9 | |
|
| | 10 | | namespace JeremyAnsel.Media.WavefrontObj |
| | 11 | | { |
| | 12 | | public class ObjMaterialFile |
| | 13 | | { |
| 876 | 14 | | public ObjMaterialFile() |
| | 15 | | { |
| 876 | 16 | | this.Materials = new List<ObjMaterial>(); |
| 876 | 17 | | } |
| | 18 | |
|
| 468 | 19 | | public string? HeaderText { get; set; } |
| | 20 | |
|
| | 21 | | [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.RootHidden)] |
| 3018 | 22 | | public List<ObjMaterial> Materials { get; private set; } |
| | 23 | |
|
| | 24 | | public static ObjMaterialFile FromFile(string? path) |
| | 25 | | { |
| 6 | 26 | | if (path == null) |
| | 27 | | { |
| 3 | 28 | | throw new ArgumentNullException(nameof(path)); |
| | 29 | | } |
| | 30 | |
|
| 3 | 31 | | using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) |
| | 32 | | { |
| 3 | 33 | | return ObjMaterialFileReader.FromStream(stream); |
| | 34 | | } |
| 3 | 35 | | } |
| | 36 | |
|
| | 37 | | public static ObjMaterialFile FromStream(Stream? stream) |
| | 38 | | { |
| 675 | 39 | | return ObjMaterialFileReader.FromStream(stream); |
| | 40 | | } |
| | 41 | |
|
| | 42 | | public void WriteTo(string? path) |
| | 43 | | { |
| 3 | 44 | | if (path == null) |
| | 45 | | { |
| 0 | 46 | | throw new ArgumentNullException(nameof(path)); |
| | 47 | | } |
| | 48 | |
|
| 3 | 49 | | using (var writer = new StreamWriter(path)) |
| | 50 | | { |
| 3 | 51 | | ObjMaterialFileWriter.Write(this, writer); |
| 3 | 52 | | } |
| 3 | 53 | | } |
| | 54 | |
|
| | 55 | | public void WriteTo(Stream? stream) |
| | 56 | | { |
| 198 | 57 | | if (stream == null) |
| | 58 | | { |
| 3 | 59 | | throw new ArgumentNullException(nameof(stream)); |
| | 60 | | } |
| | 61 | |
|
| 195 | 62 | | using (var writer = new StreamWriter(stream, new UTF8Encoding(false, true), 1024, true)) |
| | 63 | | { |
| 195 | 64 | | ObjMaterialFileWriter.Write(this, writer); |
| 195 | 65 | | } |
| 195 | 66 | | } |
| | 67 | | } |
| | 68 | | } |
| | 69 | |
|