Skip to content

Commit

Permalink
Merge pull request #39 from DomCR/remove-obsolete
Browse files Browse the repository at this point in the history
obsolete
  • Loading branch information
DomCR authored Feb 10, 2024
2 parents d5bbf5f + ca66c22 commit 414c6f3
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 27 deletions.
10 changes: 5 additions & 5 deletions src/MeshIO.GLTF/Readers/GltfBinaryReaderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Scene Read()
Node n = readNode(nodeIndex);

if (n != null)
scene.RootNode.Children.Add(n);
scene.RootNode.Nodes.Add(n);
}

return scene;
Expand Down Expand Up @@ -118,20 +118,20 @@ protected Node readNode(int index)

if (gltfNode.Mesh.HasValue)
{
node.Children.AddRange(readPrimitivesInMesh(gltfNode.Mesh.Value, node));
node.Entities.AddRange(readPrimitivesInMesh(gltfNode.Mesh.Value, node));
}

if (gltfNode.Camera.HasValue)
{
node.Children.Add(readCamera(gltfNode.Camera.Value));
node.Entities.Add(readCamera(gltfNode.Camera.Value));
}

gltfNode.Children?.ToList().ForEach((i) =>
{
Node n = readNode(i);

if (n != null)
node.Children.Add(n);
node.Nodes.Add(n);
});

return node;
Expand Down Expand Up @@ -166,7 +166,7 @@ protected List<Mesh> readPrimitivesInMesh(int index, Node parent)
mesh.Name = gltfMesh.Name;
meshes.Add(mesh);

parent.Children.Add(material); //TODO: fix the material reference
parent.Materials.Add(material); //TODO: fix the material reference
}

return meshes;
Expand Down
2 changes: 1 addition & 1 deletion src/MeshIO.STL.Tests/StlWriterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static StlWriterTest()
XYZ v2 = new XYZ(0, 1, 0);
XYZ v3 = new XYZ(1, 1, 0);

_mesh.AddTriangles(v1, v2, v3);
_mesh.AddPolygons(v1, v2, v3);
_mesh.Layers.GetLayer<LayerElementNormal>().Normals.Add(new XYZ(0, 0, 1));
}

Expand Down
4 changes: 2 additions & 2 deletions src/MeshIO.STL/StlReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Mesh Read()
XYZ v2 = new XYZ(this._stream.ReadSingle(), this._stream.ReadSingle(), this._stream.ReadSingle());
XYZ v3 = new XYZ(this._stream.ReadSingle(), this._stream.ReadSingle(), this._stream.ReadSingle());

mesh.AddTriangles(v1, v2, v3);
mesh.AddPolygons(v1, v2, v3);

ushort attByteCount = this._stream.ReadUShort();
}
Expand All @@ -112,7 +112,7 @@ public Mesh Read()
XYZ v2 = this.readPoint(this._stream.ReadUntil('\n'), "vertex");
XYZ v3 = this.readPoint(this._stream.ReadUntil('\n'), "vertex");

mesh.AddTriangles(v1, v2, v3);
mesh.AddPolygons(v1, v2, v3);

this.checkLine(this._stream.ReadUntil('\n'), "endloop");
this.checkLine(this._stream.ReadUntil('\n'), "endfacet");
Expand Down
6 changes: 0 additions & 6 deletions src/MeshIO/Entities/Geometries/Layers/LayerElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,5 @@ public LayerElement(MappingMode mappingMode, ReferenceMode referenceMode)
this.MappingMode = mappingMode;
this.ReferenceMode = referenceMode;
}

[Obsolete]
public LayerElement(Geometry owner) : this()
{
this.Owner = owner;
}
}
}
46 changes: 42 additions & 4 deletions src/MeshIO/Entities/Geometries/Mesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,30 @@ public Mesh() : base() { }

public Mesh(string name) : base(name) { }

[Obsolete]
public void AddTriangles(params XYZ[] vertices)
/// <summary>
///
/// </summary>
/// <param name="vertices"></param>
/// <exception cref="ArgumentException"></exception>
public void AddPolygons(params XYZ[] vertices)
{
if (vertices.Count() % 3 != 0)
throw new ArgumentException("The array of vertices should be multiple of 3", nameof(vertices));
int count = vertices.Count();
if (vertices.Count() % 3 == 0)
{
this.addTriangles(vertices);
}
else if (vertices.Count() % 4 == 0)
{
this.addQuads(vertices);
}
else
{
throw new ArgumentException("The array of vertices should be multiple of 3 or 4", nameof(vertices));
}
}

private void addTriangles(XYZ[] vertices)
{
if (this.Polygons.Any() && this.Polygons.First().GetType() != typeof(Triangle))
throw new ArgumentException("This mesh is not formed by Triangles");

Expand All @@ -38,5 +56,25 @@ public void AddTriangles(params XYZ[] vertices)
}
}

private void addQuads(XYZ[] vertices)
{
if (this.Polygons.Any() && this.Polygons.First().GetType() != typeof(Quad))
throw new ArgumentException("This mesh is not formed by Quads");

for (int i = 0; i < vertices.Count(); i += 4)
{
this.Vertices.Add(vertices.ElementAt(i));
this.Vertices.Add(vertices.ElementAt(i + 1));
this.Vertices.Add(vertices.ElementAt(i + 2));
this.Vertices.Add(vertices.ElementAt(i + 3));

this.Polygons.Add(new Quad(
this.Vertices.Count - 4,
this.Vertices.Count - 3,
this.Vertices.Count - 2,
this.Vertices.Count - 1
));
}
}
}
}
9 changes: 0 additions & 9 deletions src/MeshIO/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ namespace MeshIO
{
public class Node : SceneElement
{
[Obsolete]
public bool Shading { get; set; } = true;

/// <summary>
/// The node and all the components are visible or not
/// </summary>
Expand All @@ -25,12 +22,6 @@ public class Node : SceneElement
/// </summary>
public Element3D Parent { get; }

/// <summary>
/// Get all linked elements to this node
/// </summary>
[Obsolete("Replace for the different collections, ")]
public List<Element3D> Children { get; } = new();

public List<Node> Nodes { get; } = new();

public List<Material> Materials { get; } = new();
Expand Down

0 comments on commit 414c6f3

Please sign in to comment.