| | 1 | | // <copyright file="ObjFileReaderContext.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 | | namespace JeremyAnsel.Media.WavefrontObj |
| | 9 | | { |
| | 10 | | internal class ObjFileReaderContext |
| | 11 | | { |
| | 12 | | private ObjFile obj; |
| | 13 | |
|
| 1124 | 14 | | public ObjFileReaderContext(ObjFile obj, ObjFileReaderSettings settings) |
| | 15 | | { |
| 1124 | 16 | | this.obj = obj; |
| 1124 | 17 | | this.Settings = settings; |
| | 18 | |
|
| 1124 | 19 | | this.GroupNames = new List<string>(); |
| 1124 | 20 | | } |
| | 21 | |
|
| 116 | 22 | | public ObjFileReaderSettings Settings { get; } |
| | 23 | |
|
| 604 | 24 | | public string? ObjectName { get; set; } |
| | 25 | |
|
| 600 | 26 | | public int LevelOfDetail { get; set; } |
| | 27 | |
|
| 604 | 28 | | public string? MapName { get; set; } |
| | 29 | |
|
| 604 | 30 | | public string? MaterialName { get; set; } |
| | 31 | |
|
| 148 | 32 | | public long SmoothingGroupNumber { get; set; } |
| | 33 | |
|
| 144 | 34 | | public bool IsBevelInterpolationEnabled { get; set; } |
| | 35 | |
|
| 144 | 36 | | public bool IsColorInterpolationEnabled { get; set; } |
| | 37 | |
|
| 144 | 38 | | public bool IsDissolveInterpolationEnabled { get; set; } |
| | 39 | |
|
| 536 | 40 | | public int MergingGroupNumber { get; set; } |
| | 41 | |
|
| 488 | 42 | | public ObjFreeFormType FreeFormType { get; set; } |
| | 43 | |
|
| 496 | 44 | | public bool IsRationalForm { get; set; } |
| | 45 | |
|
| 480 | 46 | | public int DegreeU { get; set; } |
| | 47 | |
|
| 480 | 48 | | public int DegreeV { get; set; } |
| | 49 | |
|
| 452 | 50 | | public float[]? BasicMatrixU { get; set; } |
| | 51 | |
|
| 452 | 52 | | public float[]? BasicMatrixV { get; set; } |
| | 53 | |
|
| 456 | 54 | | public float StepU { get; set; } |
| | 55 | |
|
| 456 | 56 | | public float StepV { get; set; } |
| | 57 | |
|
| 484 | 58 | | public ObjApproximationTechnique? CurveApproximationTechnique { get; set; } |
| | 59 | |
|
| 488 | 60 | | public ObjApproximationTechnique? SurfaceApproximationTechnique { get; set; } |
| | 61 | |
|
| 768 | 62 | | public ObjFreeFormElement? CurrentFreeFormElement { get; set; } |
| | 63 | |
|
| 2028 | 64 | | public List<string> GroupNames { get; private set; } |
| | 65 | |
|
| | 66 | | public List<ObjGroup> GetCurrentGroups() |
| | 67 | | { |
| 684 | 68 | | var groups = new List<ObjGroup>(); |
| | 69 | |
|
| 1632 | 70 | | foreach (var name in this.GroupNames) |
| | 71 | | { |
| 188 | 72 | | var group = obj.Groups.FirstOrDefault(t => string.Equals(t.Name, name, StringComparison.Ordinal)); |
| | 73 | |
|
| 132 | 74 | | if (group == null) |
| | 75 | | { |
| 104 | 76 | | group = new ObjGroup(name); |
| 104 | 77 | | obj.Groups.Add(group); |
| | 78 | | } |
| | 79 | |
|
| 132 | 80 | | groups.Add(group); |
| | 81 | | } |
| | 82 | |
|
| 684 | 83 | | if (groups.Count == 0) |
| | 84 | | { |
| 576 | 85 | | groups.Add(obj.DefaultGroup); |
| | 86 | | } |
| | 87 | |
|
| 684 | 88 | | return groups; |
| | 89 | | } |
| | 90 | |
|
| | 91 | | public void ApplyAttributesToElement(ObjElement element) |
| | 92 | | { |
| 568 | 93 | | element.ObjectName = this.ObjectName; |
| 568 | 94 | | element.LevelOfDetail = this.LevelOfDetail; |
| 568 | 95 | | element.MapName = this.MapName; |
| 568 | 96 | | element.MaterialName = this.MaterialName; |
| 568 | 97 | | } |
| | 98 | |
|
| | 99 | | public void ApplyAttributesToPolygonalElement(ObjPolygonalElement element) |
| | 100 | | { |
| 120 | 101 | | element.SmoothingGroupNumber = this.SmoothingGroupNumber; |
| 120 | 102 | | element.IsBevelInterpolationEnabled = this.IsBevelInterpolationEnabled; |
| 120 | 103 | | element.IsColorInterpolationEnabled = this.IsColorInterpolationEnabled; |
| 120 | 104 | | element.IsDissolveInterpolationEnabled = this.IsDissolveInterpolationEnabled; |
| 120 | 105 | | } |
| | 106 | |
|
| | 107 | | public void ApplyAttributesToFreeFormElement(ObjFreeFormElement element) |
| | 108 | | { |
| 448 | 109 | | element.MergingGroupNumber = this.MergingGroupNumber; |
| 448 | 110 | | element.FreeFormType = this.FreeFormType; |
| 448 | 111 | | element.IsRationalForm = this.IsRationalForm; |
| 448 | 112 | | element.DegreeU = this.DegreeU; |
| 448 | 113 | | element.DegreeV = this.DegreeV; |
| 448 | 114 | | element.BasicMatrixU = this.BasicMatrixU; |
| 448 | 115 | | element.BasicMatrixV = this.BasicMatrixV; |
| 448 | 116 | | element.StepU = this.StepU; |
| 448 | 117 | | element.StepV = this.StepV; |
| 448 | 118 | | element.CurveApproximationTechnique = this.CurveApproximationTechnique; |
| 448 | 119 | | element.SurfaceApproximationTechnique = this.SurfaceApproximationTechnique; |
| 448 | 120 | | } |
| | 121 | | } |
| | 122 | | } |
| | 123 | |
|