From e9d669c4dd9f163f5e658530aeab3da006efcf53 Mon Sep 17 00:00:00 2001 From: David Kekesi Date: Thu, 31 Oct 2024 18:15:08 +0100 Subject: [PATCH] do not merge - hack for exporting gridlines - each edge is a separate polyline --- .../Speckle/Record/Element/ModelElement.cpp | 56 ++++++++++++------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/SpeckleLib/Speckle/Record/Element/ModelElement.cpp b/SpeckleLib/Speckle/Record/Element/ModelElement.cpp index 2616c41..fc9e006 100644 --- a/SpeckleLib/Speckle/Record/Element/ModelElement.cpp +++ b/SpeckleLib/Speckle/Record/Element/ModelElement.cpp @@ -33,6 +33,8 @@ using namespace speckle::utility; #include #include +#include + namespace speckle::record::element { class ModelElement::Data { @@ -278,29 +280,45 @@ ModelElement::Body* ModelElement::getBody() const { if (polyCount == 0) { std::vector vertexIndices; - std::vector points; + Int32 edgeCount = body.GetEdgeCount(); ModelerAPI::Edge edge{}; for (Int32 edgeIndex = 1; edgeIndex <= edgeCount; ++edgeIndex) { body.GetEdge(edgeIndex, &edge); vertexIndices.push_back(edge.GetVertexIndex1()); + vertexIndices.push_back(edge.GetVertexIndex2()); } vertexIndices.push_back(edge.GetVertexIndex2()); + vertexIndices.push_back(edge.GetVertexIndex2()); - for (int i : vertexIndices) { - ModelerAPI::Vertex vertex{}; - body.GetVertex(i, &vertex); - // Collect vertices (as doubles for now, but should be changed to Vertex type) - points.push_back(vertex.x); - points.push_back(vertex.y); - points.push_back(vertex.z); + for (int i = 0; i < vertexIndices.size(); i += 2) { + ModelerAPI::Vertex v1{}; + ModelerAPI::Vertex v2{}; + body.GetVertex(vertexIndices[i], &v1); + body.GetVertex(vertexIndices[i + 1], &v2); + + std::vector points{}; + + points.push_back(v1.x); + points.push_back(v1.y); + points.push_back(v1.z); + + points.push_back(v2.x); + points.push_back(v2.y); + points.push_back(v2.z); + + points.push_back(v2.x); + points.push_back(v2.y); + points.push_back(v2.z); + + record::attribute::Finish f(tmpmat); + primitive::Mesh mesh(std::move(points), f); + mesh.setToPolyline(); + elementBody->push_back(mesh); + + points.clear(); } - - record::attribute::Finish f(tmpmat); - primitive::Mesh mesh(std::move(points), f); - mesh.setToPolyline(); - elementBody->push_back(mesh); } @@ -344,13 +362,11 @@ ModelElement::Body* ModelElement::getBody() const { for (auto& [materialName, mesh] : materialMeshMap) elementBody->push_back(std::move(mesh)); - //std::vector points = { 0, 0, 0, 1, 0, 0, 1, 1, 0 }; - //Guid finishID{ Guid::fromInt(5) }; - //auto faceFinish = ModelElement::getFinish(finishID); - //record::attribute::Finish f(tmpmat); - //primitive::Mesh mesh(std::move(points), f); - //mesh.setToPolyline(); - //elementBody->push_back(mesh); + /*std::vector points = {0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0}; + record::attribute::Finish f(tmpmat); + primitive::Mesh mesh(std::move(points), f); + mesh.setToPolyline(); + elementBody->push_back(mesh);*/ m_data = std::make_unique(); m_data->m_cache.reset(elementBody);