diff --git a/src/MeshIO.GLTF/Readers/GltfBinaryReaderBase.cs b/src/MeshIO.GLTF/Readers/GltfBinaryReaderBase.cs index ff03864..c588d2e 100644 --- a/src/MeshIO.GLTF/Readers/GltfBinaryReaderBase.cs +++ b/src/MeshIO.GLTF/Readers/GltfBinaryReaderBase.cs @@ -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; @@ -118,12 +118,12 @@ 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) => @@ -131,7 +131,7 @@ protected Node readNode(int index) Node n = readNode(i); if (n != null) - node.Children.Add(n); + node.Nodes.Add(n); }); return node; @@ -166,7 +166,7 @@ protected List 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; diff --git a/src/MeshIO.STL.Tests/StlWriterTest.cs b/src/MeshIO.STL.Tests/StlWriterTest.cs index f501fed..294e7ea 100644 --- a/src/MeshIO.STL.Tests/StlWriterTest.cs +++ b/src/MeshIO.STL.Tests/StlWriterTest.cs @@ -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().Normals.Add(new XYZ(0, 0, 1)); } diff --git a/src/MeshIO.STL/StlReader.cs b/src/MeshIO.STL/StlReader.cs index 051978c..d5d09ec 100644 --- a/src/MeshIO.STL/StlReader.cs +++ b/src/MeshIO.STL/StlReader.cs @@ -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(); } @@ -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"); diff --git a/src/MeshIO/Entities/Geometries/Layers/LayerElement.cs b/src/MeshIO/Entities/Geometries/Layers/LayerElement.cs index c16b3e7..a7a482d 100644 --- a/src/MeshIO/Entities/Geometries/Layers/LayerElement.cs +++ b/src/MeshIO/Entities/Geometries/Layers/LayerElement.cs @@ -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; - } } } diff --git a/src/MeshIO/Entities/Geometries/Mesh.cs b/src/MeshIO/Entities/Geometries/Mesh.cs index 3fbb56d..e8ce5d8 100644 --- a/src/MeshIO/Entities/Geometries/Mesh.cs +++ b/src/MeshIO/Entities/Geometries/Mesh.cs @@ -15,12 +15,30 @@ public Mesh() : base() { } public Mesh(string name) : base(name) { } - [Obsolete] - public void AddTriangles(params XYZ[] vertices) + /// + /// + /// + /// + /// + 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"); @@ -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 + )); + } + } } } diff --git a/src/MeshIO/Node.cs b/src/MeshIO/Node.cs index 6639b94..b0a5a44 100644 --- a/src/MeshIO/Node.cs +++ b/src/MeshIO/Node.cs @@ -7,9 +7,6 @@ namespace MeshIO { public class Node : SceneElement { - [Obsolete] - public bool Shading { get; set; } = true; - /// /// The node and all the components are visible or not /// @@ -25,12 +22,6 @@ public class Node : SceneElement /// public Element3D Parent { get; } - /// - /// Get all linked elements to this node - /// - [Obsolete("Replace for the different collections, ")] - public List Children { get; } = new(); - public List Nodes { get; } = new(); public List Materials { get; } = new();