Skip to content

Implement Material #581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,9 @@ private CadTemplate readUnlistedType(short classNumber)
case "LWPOLYLINE":
template = this.readLWPolyline();
break;
case "MATERIAL":
template = this.readMaterial();
break;
case "MESH":
template = this.readMesh();
break;
Expand Down Expand Up @@ -5235,6 +5238,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();
Expand Down
93 changes: 93 additions & 0 deletions src/ACadSharp/IO/DXF/DxfStreamReader/DxfObjectsSectionReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,6 +75,8 @@ private CadTemplate readObject()
return this.readObjectCodes<Group>(new CadGroupTemplate(), this.readGroup);
case DxfFileToken.ObjectGeoData:
return this.readObjectCodes<GeoData>(new CadGeoDataTemplate(), this.readGeoData);
case DxfFileToken.ObjectMaterial:
return this.readObjectCodes<Material>(new CadMaterialTemplate(), this.readMaterial);
case DxfFileToken.ObjectScale:
return this.readObjectCodes<Scale>(new CadTemplate<Scale>(new Scale()), this.readScale);
case DxfFileToken.ObjectTableContent:
Expand Down Expand Up @@ -362,6 +365,96 @@ private bool readGeoData(CadTemplate template, DxfMap map)
}
}

private bool readMaterial(CadTemplate template, DxfMap map)
{
CadMaterialTemplate tmp = template as CadMaterialTemplate;
List<double> 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]);
}
}

private bool readScale(CadTemplate template, DxfMap map)
{
switch (this._reader.Code)
Expand Down
16 changes: 16 additions & 0 deletions src/ACadSharp/IO/Templates/CadMaterialTemplate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using ACadSharp.Objects;

namespace ACadSharp.IO.Templates
{
internal class CadMaterialTemplate : CadTemplate<Material>
{
public CadMaterialTemplate() : base(new Material()) { }

public CadMaterialTemplate(Material material) : base(material) { }

public override void Build(CadDocumentBuilder builder)
{
base.Build(builder);
}
}
}
Loading
Loading