| | 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 | | { |
| 1564 | 14 | | public ObjMaterialFile() |
| | 15 | | { |
| 1564 | 16 | | this.Materials = new List<ObjMaterial>(); |
| 1564 | 17 | | } |
| | 18 | |
|
| 996 | 19 | | public string? HeaderText { get; set; } |
| | 20 | |
|
| | 21 | | [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.RootHidden)] |
| 5828 | 22 | | public List<ObjMaterial> Materials { get; private set; } |
| | 23 | |
|
| | 24 | | public static ObjMaterialFile FromFile(string? path) |
| | 25 | | { |
| 8 | 26 | | if (path == null) |
| | 27 | | { |
| 4 | 28 | | throw new ArgumentNullException(nameof(path)); |
| | 29 | | } |
| | 30 | |
|
| 4 | 31 | | using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) |
| | 32 | | { |
| | 33 | | #if NET6_0_OR_GREATER |
| 3 | 34 | | return ObjMaterialFileReader9.FromStream(stream); |
| | 35 | | #else |
| 1 | 36 | | return ObjMaterialFileReader.FromStream(stream); |
| | 37 | | #endif |
| | 38 | | } |
| 4 | 39 | | } |
| | 40 | |
|
| | 41 | | public static ObjMaterialFile FromStream(Stream? stream) |
| | 42 | | { |
| | 43 | | #if NET6_0_OR_GREATER |
| 936 | 44 | | return ObjMaterialFileReader9.FromStream(stream); |
| | 45 | | #else |
| 312 | 46 | | return ObjMaterialFileReader.FromStream(stream); |
| | 47 | | #endif |
| | 48 | | } |
| | 49 | |
|
| | 50 | | public void WriteTo(string? path) |
| | 51 | | { |
| 8 | 52 | | if (path == null) |
| | 53 | | { |
| 4 | 54 | | throw new ArgumentNullException(nameof(path)); |
| | 55 | | } |
| | 56 | |
|
| 4 | 57 | | using (var writer = new StreamWriter(path)) |
| | 58 | | { |
| 4 | 59 | | ObjMaterialFileWriter.Write(this, writer); |
| 4 | 60 | | } |
| 4 | 61 | | } |
| | 62 | |
|
| | 63 | | public void WriteTo(Stream? stream) |
| | 64 | | { |
| 308 | 65 | | if (stream == null) |
| | 66 | | { |
| 4 | 67 | | throw new ArgumentNullException(nameof(stream)); |
| | 68 | | } |
| | 69 | |
|
| 304 | 70 | | using (var writer = new StreamWriter(stream, new UTF8Encoding(false, true), 1024, true)) |
| | 71 | | { |
| 304 | 72 | | ObjMaterialFileWriter.Write(this, writer); |
| 304 | 73 | | } |
| 304 | 74 | | } |
| | 75 | | } |
| | 76 | | } |
| | 77 | |
|