From 39f59258af1fc888ac6e2650e349c74c75c8e18b Mon Sep 17 00:00:00 2001 From: DomCR Date: Fri, 14 Mar 2025 09:22:56 +0100 Subject: [PATCH 1/5] case --- src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs b/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs index 6de73cdd9..cd7904ed3 100644 --- a/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs +++ b/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs @@ -1047,6 +1047,8 @@ private CadTemplate readUnlistedType(short classNumber) case "LWPOLYLINE": template = this.readLWPolyline(); break; + case "MATERIAL": + break; case "MESH": template = this.readMesh(); break; From 2dd5efb751ccd557958fa9565e891ee4ee3bfb3a Mon Sep 17 00:00:00 2001 From: DomCR Date: Sun, 16 Mar 2025 21:38:42 +0100 Subject: [PATCH 2/5] ambient and diffuse color --- .../DxfObjectsSectionReader.cs | 13 ++ .../IO/Templates/CadMaterialTemplate.cs | 14 ++ src/ACadSharp/Objects/Material.cs | 149 +++++++++++++----- 3 files changed, 136 insertions(+), 40 deletions(-) create mode 100644 src/ACadSharp/IO/Templates/CadMaterialTemplate.cs diff --git a/src/ACadSharp/IO/DXF/DxfStreamReader/DxfObjectsSectionReader.cs b/src/ACadSharp/IO/DXF/DxfStreamReader/DxfObjectsSectionReader.cs index 735d046e2..6a5cbce57 100644 --- a/src/ACadSharp/IO/DXF/DxfStreamReader/DxfObjectsSectionReader.cs +++ b/src/ACadSharp/IO/DXF/DxfStreamReader/DxfObjectsSectionReader.cs @@ -74,6 +74,8 @@ private CadTemplate readObject() return this.readObjectCodes(new CadGroupTemplate(), this.readGroup); case DxfFileToken.ObjectGeoData: return this.readObjectCodes(new CadGeoDataTemplate(), this.readGeoData); + case DxfFileToken.ObjectMaterial: + return this.readObjectCodes(new CadMaterialTemplate(), this.readMaterial); case DxfFileToken.ObjectScale: return this.readObjectCodes(new CadTemplate(new Scale()), this.readScale); case DxfFileToken.ObjectTableContent: @@ -362,6 +364,17 @@ private bool readGeoData(CadTemplate template, DxfMap map) } } + private bool readMaterial(CadTemplate template, DxfMap map) + { + CadMaterialTemplate tmp = template as CadMaterialTemplate; + + switch (this._reader.Code) + { + default: + return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]); + } + } + private bool readScale(CadTemplate template, DxfMap map) { switch (this._reader.Code) diff --git a/src/ACadSharp/IO/Templates/CadMaterialTemplate.cs b/src/ACadSharp/IO/Templates/CadMaterialTemplate.cs new file mode 100644 index 000000000..222abf0d8 --- /dev/null +++ b/src/ACadSharp/IO/Templates/CadMaterialTemplate.cs @@ -0,0 +1,14 @@ +using ACadSharp.Objects; + +namespace ACadSharp.IO.Templates +{ + internal class CadMaterialTemplate : CadTemplate + { + public CadMaterialTemplate() : base(new Material()) { } + + public override void Build(CadDocumentBuilder builder) + { + base.Build(builder); + } + } +} diff --git a/src/ACadSharp/Objects/Material.cs b/src/ACadSharp/Objects/Material.cs index c993678d7..a9a44e70b 100644 --- a/src/ACadSharp/Objects/Material.cs +++ b/src/ACadSharp/Objects/Material.cs @@ -1,5 +1,24 @@ -namespace ACadSharp.Objects +using ACadSharp.Attributes; +using CSUtilities.Extensions; + +namespace ACadSharp.Objects { + public enum AmbientColorMethod + { + Current = 0, + Override = 1, + + } + + /// + /// Represents a object + /// + /// + /// Object name
+ /// Dxf class name + ///
+ [DxfName(DxfFileToken.ObjectMaterial)] + [DxfSubClass(DxfSubclassMarker.Material)] public class Material : NonGraphicalObject { /// @@ -11,45 +30,95 @@ public class Material : NonGraphicalObject /// public override string SubclassMarker => DxfSubclassMarker.Material; - //1 Material name(string) - - //2 Description(string, default null string) - - //70 - - //Ambient color method(default = 0) : - - //0 = Use current color - - //1 = Override current color - - //40 - - //Ambient color factor(real, default = 1.0; valid range is 0.0 to 1.0) - - //90 - - //Ambient color value(unsigned 32-bit integer representing an AcCmEntityColor) - - //71 - - //Diffuse color method(default = 0) : - - //0 = Use current color - - //1 = Override current color - - //41 - - //Diffuse color factor(real, default = 1.0; valid range is 0.0 to 1.0) - - //91 - - //Diffuse color value(unsigned 32-bit integer representing an AcCmEntityColor) - - //42 - - //Diffuse map blend factor(real, default = 1.0) + /// + /// Material name. + /// + [DxfCodeValue(1)] + public override string Name + { + get + { + return base.Name; + } + set + { + base.Name = value; + } + } + + /// + /// Material description. + /// + [DxfCodeValue(2)] + public string Description { get; set; } + + /// + /// Ambient color method. + /// + [DxfCodeValue(70)] + public AmbientColorMethod AmbientColorMethod { get; set; } = AmbientColorMethod.Current; + + /// + /// Ambient color factor. + /// + /// + /// valid range is 0.0 to 1.0) + /// + [DxfCodeValue(40)] + public double AmbientColorFactor + { + get { return this._ambientColorFactor; } + set + { + ObjectExtensions.InRange(value, 0, 1, $"{nameof(AmbientColorFactor)} valid values are from 0.0 to 1.0"); + this._ambientColorFactor = value; + } + } + + private double _ambientColorFactor = 1.0; + + /// + /// Ambient color value. + /// + [DxfCodeValue(90)] + public Color AmbientColor { get; set; } + + /// + /// Ambient color method. + /// + [DxfCodeValue(71)] + public AmbientColorMethod DiffuseColorMethod { get; set; } = AmbientColorMethod.Current; + + /// + /// Diffuse color factor. + /// + /// + /// valid range is 0.0 to 1.0) + /// + [DxfCodeValue(41)] + public double DiffuseColorFactor + { + get { return this._diffuseColorFactor; } + set + { + ObjectExtensions.InRange(value, 0, 1, $"{nameof(DiffuseColorFactor)} valid values are from 0.0 to 1.0"); + this._diffuseColorFactor = value; + } + } + + private double _diffuseColorFactor = 1.0; + + /// + /// Diffuse color value. + /// + [DxfCodeValue(91)] + public Color DiffuseColor { get; set; } + + /// + /// Diffuse map blend factor. + /// + [DxfCodeValue(42)] + public double DiffuseMapBlendFactor { get; set; } = 1.0; //72 From ea8d614e6ab3a23823f5f97d5214bcf4a740dfef Mon Sep 17 00:00:00 2001 From: DomCR Date: Mon, 17 Mar 2025 08:32:56 +0100 Subject: [PATCH 3/5] mappers --- src/ACadSharp/Objects/Material.cs | 110 +++++++++++++++++++----------- 1 file changed, 71 insertions(+), 39 deletions(-) diff --git a/src/ACadSharp/Objects/Material.cs b/src/ACadSharp/Objects/Material.cs index a9a44e70b..5600cf871 100644 --- a/src/ACadSharp/Objects/Material.cs +++ b/src/ACadSharp/Objects/Material.cs @@ -7,7 +7,50 @@ public enum AmbientColorMethod { Current = 0, Override = 1, + } + + public enum MapSource + { + UseCurrentScene = 0, + UseImageFile = 1, + } + public enum ProjectionMethod + { + None = 0, + Planar = 1, + Box = 2, + Cylinder = 3, + Sphere = 4 + } + + public enum TilingMethod + { + None = 0, + Tile = 1, + Crop = 2, + Clamp = 3 + } + + [System.Flags] + public enum AutoTransformMethodFlags + { + /// + /// None. + /// + None = 0, + /// + /// No auto transform. + /// + NoAutoTransform = 1, + /// + /// Scale mapper to current entity extents; translate mapper to entity origin. + /// + ScaleMapper = 2, + /// + /// Include current block transform in mapper transform. + /// + IncludeCurrentBlock = 4 } /// @@ -120,49 +163,38 @@ public double DiffuseColorFactor [DxfCodeValue(42)] public double DiffuseMapBlendFactor { get; set; } = 1.0; - //72 - - //Diffuse map source(default = 1) : - - //0 = Use current scene - - //1 = Use image file(specified by file name; null file name specifies no map) - - //3 - - //Diffuse map file name(string, default = null string) - - //73 - - //Projection method of diffuse map mapper(default = 1): - - //1 = Planar - - //2 = Box - - //3 = Cylinder - - //4 = Sphere - - //74 - - //Tiling method of diffuse map mapper(default = 1): - - //1 = Tile - - //2 = Crop - - //3 = Clamp - - //75 + /// + /// Diffuse map source. + /// + [DxfCodeValue(72)] + public MapSource DiffuseMapSource { get; set; } = MapSource.UseImageFile; - //Auto transform method of diffuse map mapper(bitset, default = 1) : + /// + /// Diffuse map file name. + /// + /// + /// null file name specifies no map. + /// + [DxfCodeValue(3)] + public string DiffuseMapRileName { get; set; } - //1= No auto transform + /// + /// Projection method of diffuse map mapper. + /// + [DxfCodeValue(73)] + public ProjectionMethod ProjectionMethod { get; set; } = ProjectionMethod.Planar; - //2 = Scale mapper to current entity extents; translate mapper to entity origin + /// + /// Tiling method of diffuse map mapper. + /// + [DxfCodeValue(74)] + public TilingMethod DiffuseMapper { get; set; } = TilingMethod.Tile; - //4 = Include current block transform in mapper transform + /// + /// Auto transform method of diffuse map mapper. + /// + [DxfCodeValue(75)] + public AutoTransformMethodFlags AutoTransformDiffuse { get; set; } = AutoTransformMethodFlags.NoAutoTransform; //43 From 6252e090645ab50895be4e03a48c7667f6369541 Mon Sep 17 00:00:00 2001 From: DomCR Date: Wed, 19 Mar 2025 18:30:19 +0100 Subject: [PATCH 4/5] dxf reader --- .../DxfObjectsSectionReader.cs | 80 +++ src/ACadSharp/Objects/Material.cs | 527 +++++++++--------- src/CSUtilities | 2 +- 3 files changed, 349 insertions(+), 260 deletions(-) diff --git a/src/ACadSharp/IO/DXF/DxfStreamReader/DxfObjectsSectionReader.cs b/src/ACadSharp/IO/DXF/DxfStreamReader/DxfObjectsSectionReader.cs index 6a5cbce57..0441d9de9 100644 --- a/src/ACadSharp/IO/DXF/DxfStreamReader/DxfObjectsSectionReader.cs +++ b/src/ACadSharp/IO/DXF/DxfStreamReader/DxfObjectsSectionReader.cs @@ -2,6 +2,7 @@ using ACadSharp.Objects; using ACadSharp.Objects.Evaluations; using System; +using System.Collections.Generic; using System.Diagnostics; using System.Linq; using static ACadSharp.IO.Templates.CadEvaluationGraphTemplate; @@ -367,9 +368,88 @@ private bool readGeoData(CadTemplate template, DxfMap map) private bool readMaterial(CadTemplate template, DxfMap map) { CadMaterialTemplate tmp = template as CadMaterialTemplate; + List arr = null; switch (this._reader.Code) { + case 43: + arr = new(); + for (int i = 0; i < 16; i++) + { + Debug.Assert(this._reader.Code == 43); + + arr.Add(this._reader.ValueAsDouble); + + this._reader.ReadNext(); + } + + tmp.CadObject.DiffuseMatrix = new CSMath.Matrix4(arr.ToArray()); + return this.checkObjectEnd(template, map, this.readMaterial); + case 47: + arr = new(); + for (int i = 0; i < 16; i++) + { + Debug.Assert(this._reader.Code == 47); + + arr.Add(this._reader.ValueAsDouble); + + this._reader.ReadNext(); + } + + tmp.CadObject.SpecularMatrix = new CSMath.Matrix4(arr.ToArray()); + return this.checkObjectEnd(template, map, this.readMaterial); + case 49: + arr = new(); + for (int i = 0; i < 16; i++) + { + Debug.Assert(this._reader.Code == 49); + + arr.Add(this._reader.ValueAsDouble); + + this._reader.ReadNext(); + } + + tmp.CadObject.ReflectionMatrix = new CSMath.Matrix4(arr.ToArray()); + return this.checkObjectEnd(template, map, this.readMaterial); + case 142: + arr = new(); + for (int i = 0; i < 16; i++) + { + Debug.Assert(this._reader.Code == 142); + + arr.Add(this._reader.ValueAsDouble); + + this._reader.ReadNext(); + } + + tmp.CadObject.OpacityMatrix = new CSMath.Matrix4(arr.ToArray()); + return this.checkObjectEnd(template, map, this.readMaterial); + case 144: + arr = new(); + for (int i = 0; i < 16; i++) + { + Debug.Assert(this._reader.Code == 144); + + arr.Add(this._reader.ValueAsDouble); + + this._reader.ReadNext(); + } + + tmp.CadObject.BumpMatrix = new CSMath.Matrix4(arr.ToArray()); + return this.checkObjectEnd(template, map, this.readMaterial); + case 147: + arr = new(); + for (int i = 0; i < 16; i++) + { + Debug.Assert(this._reader.Code == 147); + + arr.Add(this._reader.ValueAsDouble); + + this._reader.ReadNext(); + } + + tmp.CadObject.RefractionMatrix = new CSMath.Matrix4(arr.ToArray()); + return this.checkObjectEnd(template, map, this.readMaterial); default: return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]); } diff --git a/src/ACadSharp/Objects/Material.cs b/src/ACadSharp/Objects/Material.cs index 5600cf871..7e4e2e12d 100644 --- a/src/ACadSharp/Objects/Material.cs +++ b/src/ACadSharp/Objects/Material.cs @@ -1,9 +1,10 @@ using ACadSharp.Attributes; +using CSMath; using CSUtilities.Extensions; namespace ACadSharp.Objects { - public enum AmbientColorMethod + public enum ColorMethod { Current = 0, Override = 1, @@ -99,7 +100,7 @@ public override string Name /// Ambient color method. /// [DxfCodeValue(70)] - public AmbientColorMethod AmbientColorMethod { get; set; } = AmbientColorMethod.Current; + public ColorMethod AmbientColorMethod { get; set; } = ColorMethod.Current; /// /// Ambient color factor. @@ -113,7 +114,7 @@ public double AmbientColorFactor get { return this._ambientColorFactor; } set { - ObjectExtensions.InRange(value, 0, 1, $"{nameof(AmbientColorFactor)} valid values are from 0.0 to 1.0"); + ObjectExtensions.InRange(value, 0, 1); this._ambientColorFactor = value; } } @@ -130,7 +131,7 @@ public double AmbientColorFactor /// Ambient color method. /// [DxfCodeValue(71)] - public AmbientColorMethod DiffuseColorMethod { get; set; } = AmbientColorMethod.Current; + public ColorMethod DiffuseColorMethod { get; set; } = ColorMethod.Current; /// /// Diffuse color factor. @@ -144,7 +145,7 @@ public double DiffuseColorFactor get { return this._diffuseColorFactor; } set { - ObjectExtensions.InRange(value, 0, 1, $"{nameof(DiffuseColorFactor)} valid values are from 0.0 to 1.0"); + ObjectExtensions.InRange(value, 0, 1); this._diffuseColorFactor = value; } } @@ -176,13 +177,13 @@ public double DiffuseColorFactor /// null file name specifies no map. /// [DxfCodeValue(3)] - public string DiffuseMapRileName { get; set; } + public string DiffuseMapFileName { get; set; } /// /// Projection method of diffuse map mapper. /// [DxfCodeValue(73)] - public ProjectionMethod ProjectionMethod { get; set; } = ProjectionMethod.Planar; + public ProjectionMethod DiffuseProjectionMethod { get; set; } = ProjectionMethod.Planar; /// /// Tiling method of diffuse map mapper. @@ -194,303 +195,306 @@ public double DiffuseColorFactor /// Auto transform method of diffuse map mapper. /// [DxfCodeValue(75)] - public AutoTransformMethodFlags AutoTransformDiffuse { get; set; } = AutoTransformMethodFlags.NoAutoTransform; + public AutoTransformMethodFlags DiffuseAutoTransform { get; set; } = AutoTransformMethodFlags.NoAutoTransform; - //43 - - //Transform matrix of diffuse map mapper(16 reals; row major format; default = identity matrix) - - //44 - - //Specular gloss factor(real, default = 0.5) - - //76 - - //Specular color method(default = 0) : - - //0 = Use current color - - //1 = Override current color - - //45 - - //Specular color factor(real, default = 1.0; valid range is 0.0 to 1.0) - - //92 - - //Specular color value(unsigned 32-bit integer representing an AcCmEntityColor) - - //46 - - //Specular map blend factor(real; default = 1.0) - - //77 - - //Specular map source(default = 1) : - - //0 = Use current scene - - //1 = Use image file(specified by file name; null file name specifies no map) - - //4 - - //Specular map file name(string; default = null string) - - //78 - - //Projection method of specular map mapper(default = 1): - - //1 = Planar - - //2 = Box - - //3 = Cylinder - - //4 = Sphere - - //79 - - //Tiling method of specular map mapper(default = 1): - - //1 = Tile - - //2 = Crop - - //3 = Clamp - - //170 - - //Auto transform method of specular map mapper(bitset; default = 1): - - //1 = No auto transform - - //2 = Scale mapper to current entity extents; translate mapper to entity origin - - //4 = Include current block transform in mapper transform - - //47 - - //Transform matrix of specular map mapper(16 reals; row major format; default = identity matrix) - - //48 - - //Blend factor of reflection map(real, default = 1.0) - - //171 - - //Reflection map source(default = 1) : - - //0 = Use current scene - - //1 = Use image file(specified by file name; null file name specifies no map) - - //6 - - //Reflection map file name(string; default = null string) - - //172 - - //Projection method of reflection map mapper(default = 1): - - //1 = Planar - - //2 = Box - - //3 = Cylinder - - //4 = Sphere - - //173 - - //Tiling method of reflection map mapper(default = 1): - - //1 = Tile - - //2 = Crop - - //3 = Clamp - - //174 - - //Auto transform method of reflection map mapper(bitset; default = 1): - - //1 = No auto transform - - //2 = Scale mapper to current entity extents; translate mapper to entity origin - - //4 = Include current block transform in mapper transform - - //49 - - //Transform matrix of reflection map mapper(16 reals; row major format; default = identity matrix) - - //140 - - //Opacity percent(real; default = 1.0) - - //141 - - //Blend factor of opacity map(real; default = 1.0) - - //175 - - //Opacity map source(default = 1) : - - //0 = Use current scene - - //1 = Use image file(specified by file name; null file name specifies no map) - - //7 - - //Opacity map file name(string; default = null string) - - //176 - - //Projection method of opacity map mapper(default = 1): - - //1 = Planar - - //2 = Box - - //3 = Cylinder - - //4 = Sphere - - //177 - - //Tiling method of opacity map mapper(default = 1): - - //1 = Tile - - //2 = Crop - - //3 = Clamp - - //178 - - //Auto transform method of opacity map mapper(bitset; default = 1): - - //1 = No auto transform - - //2 = Scale mapper to current entity extents; translate mapper to entity origin - - //4 = Include current block transform in mapper transform - - //142 - - //Transform matrix of opacity map mapper(16 reals; row major format; default = identity matrix) - - //143 - - //Blend factor of bump map(real; default = 1.0) - - //179 - - //Bump map source(default = 1) : - - //0 = Use current scene - - //1 = Use image file(specified by file name; null file name specifies no map) - - //8 - - //Bump map file name(string; default = null string) - - //270 - - //Projection method of bump map mapper(default = 1): - - //1 = Planar - - //2 = Box + /// + /// Transform matrix of diffuse map mapper. + /// + [DxfCodeValue(43)] + public Matrix4 DiffuseMatrix { get; set; } = Matrix4.Identity; - //3 = Cylinder + /// + /// Specular gloss factor. + /// + /// + /// default = 0.5 + /// + [DxfCodeValue(44)] + public double SpecularGlossFactor { get; set; } = 0.5; - //4 = Sphere + /// + /// Specular color method. + /// + [DxfCodeValue(76)] + public ColorMethod SpecularColorMethod { get; set; } = ColorMethod.Current; - //271 + /// + /// Specular color factor. + /// + /// + /// valid range is 0.0 to 1.0) + /// + [DxfCodeValue(45)] + public double SpecularColorFactor + { + get { return this._specularColorFactor; } + set + { + ObjectExtensions.InRange(value, 0, 1); + this._specularColorFactor = value; + } + } - //Tiling method of bump map mapper(default = 1): + private double _specularColorFactor = 1.0; - //1 = Tile + /// + /// Specular color. + /// + [DxfCodeValue(92)] + public Color SpecularColor { get; set; } - //2 = Crop + /// + /// Specular map blend factor. + /// + /// + /// default = 1.0 + /// + [DxfCodeValue(46)] + public double SpecularMapBlendFactor { get; set; } = 1.0; - //3 = Clamp + /// + /// Specular map source. + /// + [DxfCodeValue(77)] + public MapSource SpecularMapSource { get; set; } = MapSource.UseImageFile; - //272 + /// + /// Specular map file name. + /// + /// + /// null file name specifies no map. + /// + [DxfCodeValue(4)] + public string SpecularMapFileName { get; set; } - //Auto transform method of bump map mapper(bitset; default = 1): + /// + /// Projection method of specular map mapper. + /// + [DxfCodeValue(78)] + public ProjectionMethod SpecularProjectionMethod { get; set; } = ProjectionMethod.Planar; - //1 = No auto transform + /// + /// Tiling method of specular map mapper. + /// + [DxfCodeValue(79)] + public TilingMethod SpecularMapper { get; set; } = TilingMethod.Tile; - //2 = Scale mapper to current entity extents; translate mapper to entity origin + /// + /// Auto transform method of specular map mapper. + /// + [DxfCodeValue(170)] + public AutoTransformMethodFlags SpecularAutoTransform { get; set; } = AutoTransformMethodFlags.NoAutoTransform; - //4 = Include current block transform in mapper transform + /// + /// Transform matrix of specular map mapper. + /// + [DxfCodeValue(47)] + public Matrix4 SpecularMatrix { get; set; } = Matrix4.Identity; - //144 + /// + /// Blend factor of reflection map. + /// + [DxfCodeValue(48)] + public double ReflectionMapBlendFactor { get; set; } = 1.0; - //Transform matrix of bump map mapper(16 reals; row major format; default = identity matrix) + /// + /// Reflection map source. + /// + [DxfCodeValue(171)] + public MapSource ReflectionMapSource { get; set; } = MapSource.UseImageFile; - //145 + /// + /// Reflection map file name. + /// + /// + /// null file name specifies no map. + /// + [DxfCodeValue(6)] + public string ReflectionMapFileName { get; set; } - //Refraction index(real; default = 1.0) + /// + /// Projection method of specular map mapper. + /// + [DxfCodeValue(172)] + public ProjectionMethod ReflectionProjectionMethod { get; set; } = ProjectionMethod.Planar; - //146 + /// + /// Tiling method of reflection map mapper. + /// + [DxfCodeValue(173)] + public TilingMethod ReflectionMapper { get; set; } = TilingMethod.Tile; - //Blend factor of refraction map(real; default = 1.0) + /// + /// Auto transform method of reflection map mapper. + /// + [DxfCodeValue(174)] + public AutoTransformMethodFlags ReflectionAutoTransform { get; set; } = AutoTransformMethodFlags.NoAutoTransform; - //273 + /// + /// Transform matrix of reflection map mapper. + /// + [DxfCodeValue(49)] + public Matrix4 ReflectionMatrix { get; set; } = Matrix4.Identity; - //Refraction map source(default = 1) : + /// + /// Opacity percent. + /// + [DxfCodeValue(140)] + public double Opacity { get; set; } = 1.0; - //0 = Use current scene + /// + /// Opacity map blend factor. + /// + /// + /// default = 1.0 + /// + [DxfCodeValue(141)] + public double OpacityMapBlendFactor { get; set; } = 1.0; - //1 = Use image file(specified by file name; null file name specifies no map) + /// + /// Opacity map source. + /// + [DxfCodeValue(175)] + public MapSource OpacityMapSource { get; set; } = MapSource.UseImageFile; - //9 + /// + /// Opacity map file name. + /// + /// + /// null file name specifies no map. + /// + [DxfCodeValue(7)] + public string OpacityMapFileName { get; set; } - //Refraction map file name(string; default = null string) + /// + /// Opacity method of specular map mapper. + /// + [DxfCodeValue(176)] + public ProjectionMethod OpacityProjectionMethod { get; set; } = ProjectionMethod.Planar; - //274 + /// + /// Tiling method of opacity map mapper. + /// + [DxfCodeValue(177)] + public TilingMethod OpacityMapper { get; set; } = TilingMethod.Tile; - //Projection method of refraction map mapper(default = 1): + /// + /// Auto transform method of opacity map mapper. + /// + [DxfCodeValue(178)] + public AutoTransformMethodFlags OpacityAutoTransform { get; set; } = AutoTransformMethodFlags.NoAutoTransform; - //1 = Planar + /// + /// Transform matrix of opacity map mapper. + /// + [DxfCodeValue(142)] + public Matrix4 OpacityMatrix { get; set; } = Matrix4.Identity; - //2 = Box + /// + /// Bump map blend factor. + /// + /// + /// default = 1.0 + /// + [DxfCodeValue(143)] + public double BumpMapBlendFactor { get; set; } = 1.0; - //3 = Cylinder + /// + /// Bump map source. + /// + [DxfCodeValue(179)] + public MapSource BumpMapSource { get; set; } = MapSource.UseImageFile; - //4 = Sphere + /// + /// Bump map file name. + /// + /// + /// null file name specifies no map. + /// + [DxfCodeValue(8)] + public string BumpMapFileName { get; set; } - //275 + /// + /// Bump method of specular map mapper. + /// + [DxfCodeValue(270)] + public ProjectionMethod BumpProjectionMethod { get; set; } = ProjectionMethod.Planar; - //Tiling method of refraction map mapper(default = 1): + /// + /// Tiling method of bump map mapper. + /// + [DxfCodeValue(271)] + public TilingMethod BumpMapper { get; set; } = TilingMethod.Tile; - //1 = Tile + /// + /// Auto transform method of bump map mapper. + /// + [DxfCodeValue(272)] + public AutoTransformMethodFlags BumpAutoTransform { get; set; } = AutoTransformMethodFlags.NoAutoTransform; - //2 = Crop + /// + /// Transform matrix of bump map mapper. + /// + [DxfCodeValue(144)] + public Matrix4 BumpMatrix { get; set; } = Matrix4.Identity; - //3 = Clamp + /// + /// Refraction index. + /// + [DxfCodeValue(145)] + public double RefractionIndex { get; set; } = 1.0; - //276 + /// + /// Bump map refraction factor. + /// + /// + /// default = 1.0 + /// + [DxfCodeValue(146)] + public double RefractionMapBlendFactor { get; set; } = 1.0; - //Auto transform method of refraction map mapper(bitset; default = 1): + /// + /// Refraction map source. + /// + [DxfCodeValue(273)] + public MapSource RefractionMapSource { get; set; } = MapSource.UseImageFile; - //1 = No auto transform + /// + /// Refraction map file name. + /// + /// + /// null file name specifies no map. + /// + [DxfCodeValue(9)] + public string RefractionMapFileName { get; set; } - //2 = Scale mapper to current entity extents; translate mapper to entity origin + /// + /// Projection method of refraction map mapper. + /// + [DxfCodeValue(274)] + public ProjectionMethod RefractionProjectionMethod { get; set; } = ProjectionMethod.Planar; - //4 = Include current block transform in mapper transform + /// + /// Tiling method of refraction map mapper. + /// + [DxfCodeValue(275)] + public TilingMethod RefractionMapper { get; set; } = TilingMethod.Tile; - //147 + /// + /// Auto transform method of refraction map mapper. + /// + [DxfCodeValue(276)] + public AutoTransformMethodFlags RefractionAutoTransform { get; set; } = AutoTransformMethodFlags.NoAutoTransform; - //Transform matrix of refraction map mapper(16 reals; row major format; default = identity matrix) + /// + /// Transform matrix of refraction map mapper. + /// + [DxfCodeValue(147)] + public Matrix4 RefractionMatrix { get; set; } = Matrix4.Identity; //460 - //Color Bleed Scale + //461 Indirect Dump Scale //462 Reflectance Scale //463 @@ -531,6 +535,11 @@ public double DiffuseColorFactor //90 Self-Illuminaton //468 Reflectivity //93 Illumination Model - //94 Channel Flags + + /// + /// Channel Flags. + /// + [DxfCodeValue(94)] + public int ChannelFlags { get; set; } } } diff --git a/src/CSUtilities b/src/CSUtilities index c1fb0e4ac..2ef2a715d 160000 --- a/src/CSUtilities +++ b/src/CSUtilities @@ -1 +1 @@ -Subproject commit c1fb0e4acde28ca7ca856971b4bde0b749d19121 +Subproject commit 2ef2a715dabd7218f29bf10bd7c86f7e37e425e8 From a64d42aea8196b27aed87bca52b8e6b978815b01 Mon Sep 17 00:00:00 2001 From: DomCR Date: Wed, 19 Mar 2025 19:18:00 +0100 Subject: [PATCH 5/5] dwgReader test --- .../DWG/DwgStreamReaders/DwgObjectReader.cs | 19 +++++++++++++++++++ .../IO/Templates/CadMaterialTemplate.cs | 2 ++ 2 files changed, 21 insertions(+) diff --git a/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs b/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs index cd7904ed3..69d1ebfb7 100644 --- a/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs +++ b/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs @@ -1048,6 +1048,7 @@ private CadTemplate readUnlistedType(short classNumber) template = this.readLWPolyline(); break; case "MATERIAL": + template = this.readMaterial(); break; case "MESH": template = this.readMesh(); @@ -5226,6 +5227,24 @@ private CadTemplate readLWPolyline() return template; } + private CadTemplate readMaterial() + { + Material material = new Material(); + CadMaterialTemplate template = new CadMaterialTemplate(material); + + this.readCommonNonEntityData(template); + + material.Name = this._mergedReaders.ReadVariableText(); + material.Description = this._mergedReaders.ReadVariableText(); + +#if TEST + var obj = DwgStreamReaderBase.Explore(this._objectReader); + var text = DwgStreamReaderBase.Explore(this._textReader); +#endif + + return null; + } + private CadTemplate readHatch() { Hatch hatch = new Hatch(); diff --git a/src/ACadSharp/IO/Templates/CadMaterialTemplate.cs b/src/ACadSharp/IO/Templates/CadMaterialTemplate.cs index 222abf0d8..3aa6e63e3 100644 --- a/src/ACadSharp/IO/Templates/CadMaterialTemplate.cs +++ b/src/ACadSharp/IO/Templates/CadMaterialTemplate.cs @@ -6,6 +6,8 @@ internal class CadMaterialTemplate : CadTemplate { public CadMaterialTemplate() : base(new Material()) { } + public CadMaterialTemplate(Material material) : base(material) { } + public override void Build(CadDocumentBuilder builder) { base.Build(builder);