| | | 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 | | |
| | 1140 | 14 | | public ObjFileReaderContext(ObjFile obj, ObjFileReaderSettings settings) |
| | | 15 | | { |
| | 1140 | 16 | | this.obj = obj; |
| | 1140 | 17 | | this.Settings = settings; |
| | | 18 | | |
| | 1140 | 19 | | this.GroupNames = new List<string>(); |
| | 1140 | 20 | | } |
| | | 21 | | |
| | 116 | 22 | | public ObjFileReaderSettings Settings { get; } |
| | | 23 | | |
| | 608 | 24 | | public string? ObjectName { get; set; } |
| | | 25 | | |
| | 604 | 26 | | public int LevelOfDetail { get; set; } |
| | | 27 | | |
| | 608 | 28 | | public string? MapName { get; set; } |
| | | 29 | | |
| | 612 | 30 | | public string? MaterialName { get; set; } |
| | | 31 | | |
| | 152 | 32 | | public long SmoothingGroupNumber { get; set; } |
| | | 33 | | |
| | 148 | 34 | | public bool IsBevelInterpolationEnabled { get; set; } |
| | | 35 | | |
| | 148 | 36 | | public bool IsColorInterpolationEnabled { get; set; } |
| | | 37 | | |
| | 148 | 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 | | |
| | 2048 | 64 | | public List<string> GroupNames { get; private set; } |
| | | 65 | | |
| | | 66 | | public List<ObjGroup> GetCurrentGroups() |
| | | 67 | | { |
| | 688 | 68 | | var groups = new List<ObjGroup>(); |
| | | 69 | | |
| | 1640 | 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 | | |
| | 688 | 83 | | if (groups.Count == 0) |
| | | 84 | | { |
| | 580 | 85 | | groups.Add(obj.DefaultGroup); |
| | | 86 | | } |
| | | 87 | | |
| | 688 | 88 | | return groups; |
| | | 89 | | } |
| | | 90 | | |
| | | 91 | | public void ApplyAttributesToElement(ObjElement element) |
| | | 92 | | { |
| | 572 | 93 | | element.ObjectName = this.ObjectName; |
| | 572 | 94 | | element.LevelOfDetail = this.LevelOfDetail; |
| | 572 | 95 | | element.MapName = this.MapName; |
| | 572 | 96 | | element.MaterialName = this.MaterialName; |
| | 572 | 97 | | } |
| | | 98 | | |
| | | 99 | | public void ApplyAttributesToPolygonalElement(ObjPolygonalElement element) |
| | | 100 | | { |
| | 124 | 101 | | element.SmoothingGroupNumber = this.SmoothingGroupNumber; |
| | 124 | 102 | | element.IsBevelInterpolationEnabled = this.IsBevelInterpolationEnabled; |
| | 124 | 103 | | element.IsColorInterpolationEnabled = this.IsColorInterpolationEnabled; |
| | 124 | 104 | | element.IsDissolveInterpolationEnabled = this.IsDissolveInterpolationEnabled; |
| | 124 | 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 | | |