| | 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 | |
|
| 816 | 14 | | public ObjFileReaderContext(ObjFile obj) |
| | 15 | | { |
| 816 | 16 | | this.obj = obj; |
| | 17 | |
|
| 816 | 18 | | this.GroupNames = new List<string>(); |
| 816 | 19 | | } |
| | 20 | |
|
| 453 | 21 | | public string? ObjectName { get; set; } |
| | 22 | |
|
| 450 | 23 | | public int LevelOfDetail { get; set; } |
| | 24 | |
|
| 453 | 25 | | public string? MapName { get; set; } |
| | 26 | |
|
| 453 | 27 | | public string? MaterialName { get; set; } |
| | 28 | |
|
| 111 | 29 | | public long SmoothingGroupNumber { get; set; } |
| | 30 | |
|
| 108 | 31 | | public bool IsBevelInterpolationEnabled { get; set; } |
| | 32 | |
|
| 108 | 33 | | public bool IsColorInterpolationEnabled { get; set; } |
| | 34 | |
|
| 108 | 35 | | public bool IsDissolveInterpolationEnabled { get; set; } |
| | 36 | |
|
| 402 | 37 | | public int MergingGroupNumber { get; set; } |
| | 38 | |
|
| 366 | 39 | | public ObjFreeFormType FreeFormType { get; set; } |
| | 40 | |
|
| 372 | 41 | | public bool IsRationalForm { get; set; } |
| | 42 | |
|
| 360 | 43 | | public int DegreeU { get; set; } |
| | 44 | |
|
| 360 | 45 | | public int DegreeV { get; set; } |
| | 46 | |
|
| 339 | 47 | | public float[]? BasicMatrixU { get; set; } |
| | 48 | |
|
| 339 | 49 | | public float[]? BasicMatrixV { get; set; } |
| | 50 | |
|
| 342 | 51 | | public float StepU { get; set; } |
| | 52 | |
|
| 342 | 53 | | public float StepV { get; set; } |
| | 54 | |
|
| 363 | 55 | | public ObjApproximationTechnique? CurveApproximationTechnique { get; set; } |
| | 56 | |
|
| 366 | 57 | | public ObjApproximationTechnique? SurfaceApproximationTechnique { get; set; } |
| | 58 | |
|
| 576 | 59 | | public ObjFreeFormElement? CurrentFreeFormElement { get; set; } |
| | 60 | |
|
| 1425 | 61 | | public List<string> GroupNames { get; private set; } |
| | 62 | |
|
| | 63 | | public List<ObjGroup> GetCurrentGroups() |
| | 64 | | { |
| 492 | 65 | | var groups = new List<ObjGroup>(); |
| | 66 | |
|
| 1128 | 67 | | foreach (var name in this.GroupNames) |
| | 68 | | { |
| 108 | 69 | | var group = obj.Groups.FirstOrDefault(t => string.Equals(t.Name, name, StringComparison.Ordinal)); |
| | 70 | |
|
| 72 | 71 | | if (group == null) |
| | 72 | | { |
| 51 | 73 | | group = new ObjGroup(name); |
| 51 | 74 | | obj.Groups.Add(group); |
| | 75 | | } |
| | 76 | |
|
| 72 | 77 | | groups.Add(group); |
| | 78 | | } |
| | 79 | |
|
| 492 | 80 | | if (groups.Count == 0) |
| | 81 | | { |
| 432 | 82 | | groups.Add(obj.DefaultGroup); |
| | 83 | | } |
| | 84 | |
|
| 492 | 85 | | return groups; |
| | 86 | | } |
| | 87 | |
|
| | 88 | | public void ApplyAttributesToElement(ObjElement element) |
| | 89 | | { |
| 426 | 90 | | element.ObjectName = this.ObjectName; |
| 426 | 91 | | element.LevelOfDetail = this.LevelOfDetail; |
| 426 | 92 | | element.MapName = this.MapName; |
| 426 | 93 | | element.MaterialName = this.MaterialName; |
| 426 | 94 | | } |
| | 95 | |
|
| | 96 | | public void ApplyAttributesToPolygonalElement(ObjPolygonalElement element) |
| | 97 | | { |
| 90 | 98 | | element.SmoothingGroupNumber = this.SmoothingGroupNumber; |
| 90 | 99 | | element.IsBevelInterpolationEnabled = this.IsBevelInterpolationEnabled; |
| 90 | 100 | | element.IsColorInterpolationEnabled = this.IsColorInterpolationEnabled; |
| 90 | 101 | | element.IsDissolveInterpolationEnabled = this.IsDissolveInterpolationEnabled; |
| 90 | 102 | | } |
| | 103 | |
|
| | 104 | | public void ApplyAttributesToFreeFormElement(ObjFreeFormElement element) |
| | 105 | | { |
| 336 | 106 | | element.MergingGroupNumber = this.MergingGroupNumber; |
| 336 | 107 | | element.FreeFormType = this.FreeFormType; |
| 336 | 108 | | element.IsRationalForm = this.IsRationalForm; |
| 336 | 109 | | element.DegreeU = this.DegreeU; |
| 336 | 110 | | element.DegreeV = this.DegreeV; |
| 336 | 111 | | element.BasicMatrixU = this.BasicMatrixU; |
| 336 | 112 | | element.BasicMatrixV = this.BasicMatrixV; |
| 336 | 113 | | element.StepU = this.StepU; |
| 336 | 114 | | element.StepV = this.StepV; |
| 336 | 115 | | element.CurveApproximationTechnique = this.CurveApproximationTechnique; |
| 336 | 116 | | element.SurfaceApproximationTechnique = this.SurfaceApproximationTechnique; |
| 336 | 117 | | } |
| | 118 | | } |
| | 119 | | } |
| | 120 | |
|