From 34cc69f0033939f441e160954ae9d39364dca6a8 Mon Sep 17 00:00:00 2001 From: Jeremy HU Date: Sun, 13 Nov 2022 18:02:53 +1100 Subject: [PATCH] Remove old object nodes --- .../sources/mesh_result_post_processor.cc | 6 ++-- application/sources/model_mesh.cc | 26 +++++++------- dust3d/base/object.h | 4 +-- dust3d/mesh/mesh_generator.cc | 34 +++++++++---------- dust3d/mesh/tube_mesh_builder.cc | 8 +++-- dust3d/mesh/tube_mesh_builder.h | 2 ++ 6 files changed, 43 insertions(+), 37 deletions(-) diff --git a/application/sources/mesh_result_post_processor.cc b/application/sources/mesh_result_post_processor.cc index 1edd71ae..3ae71225 100644 --- a/application/sources/mesh_result_post_processor.cc +++ b/application/sources/mesh_result_post_processor.cc @@ -22,8 +22,8 @@ dust3d::Object* MeshResultPostProcessor::takePostProcessedObject() void MeshResultPostProcessor::poseProcess() { - if (!m_object->nodes.empty()) { - /* + //if (!m_object->nodes.empty()) { + /* { std::vector> triangleVertexUvs; std::set seamVertices; @@ -39,7 +39,7 @@ void MeshResultPostProcessor::poseProcess() m_object->setTriangleTangents(triangleTangents); } */ - } + //} } void MeshResultPostProcessor::process() diff --git a/application/sources/model_mesh.cc b/application/sources/model_mesh.cc index b931e0ea..3f6a9aa2 100644 --- a/application/sources/model_mesh.cc +++ b/application/sources/model_mesh.cc @@ -130,11 +130,11 @@ ModelMesh::ModelMesh(dust3d::Object& object) m_vertices = object.vertices; m_faces = object.triangleAndQuads; - std::map, const dust3d::ObjectNode*> nodeMap; - for (size_t i = 0; i < object.nodes.size(); ++i) { - const auto& node = object.nodes[i]; - nodeMap.insert({ { node.partId, node.nodeId }, &node }); - } + //std::map, const dust3d::ObjectNode*> nodeMap; + //for (size_t i = 0; i < object.nodes.size(); ++i) { + // const auto& node = object.nodes[i]; + // nodeMap.insert({ { node.partId, node.nodeId }, &node }); + //} m_triangleVertexCount = (int)object.triangles.size() * 3; m_triangleVertices = new ModelOpenGLVertex[m_triangleVertexCount]; @@ -172,14 +172,14 @@ ModelMesh::ModelMesh(dust3d::Object& object) dest->normX = srcNormal->x(); dest->normY = srcNormal->y(); dest->normZ = srcNormal->z(); - auto findNode = nodeMap.find(object.vertexSourceNodes[vertexIndex]); - if (findNode != nodeMap.end()) { - dest->metalness = findNode->second->metalness; - dest->roughness = findNode->second->roughness; - } else { - dest->metalness = m_defaultMetalness; - dest->roughness = m_defaultRoughness; - } + //auto findNode = nodeMap.find(object.vertexSourceNodes[vertexIndex]); + //if (findNode != nodeMap.end()) { + // dest->metalness = findNode->second->metalness; + // dest->roughness = findNode->second->roughness; + //} else { + dest->metalness = m_defaultMetalness; + dest->roughness = m_defaultRoughness; + //} dest->tangentX = srcTangent->x(); dest->tangentY = srcTangent->y(); dest->tangentZ = srcTangent->z(); diff --git a/dust3d/base/object.h b/dust3d/base/object.h index 33c887e1..4028b73b 100644 --- a/dust3d/base/object.h +++ b/dust3d/base/object.h @@ -56,8 +56,8 @@ struct ObjectNode { class Object { public: - std::vector nodes; - std::vector, std::pair>> edges; + //std::vector nodes; + //std::vector, std::pair>> edges; std::vector vertices; std::vector> vertexSourceNodes; std::vector> triangleAndQuads; diff --git a/dust3d/mesh/mesh_generator.cc b/dust3d/mesh/mesh_generator.cc index cfb07ab0..758bce9f 100644 --- a/dust3d/mesh/mesh_generator.cc +++ b/dust3d/mesh/mesh_generator.cc @@ -1055,22 +1055,22 @@ void MeshGenerator::postprocessObject(Object* object) object->triangleNormals = combinedFacesNormals; - std::vector> sourceNodes; - resolveTriangleSourceNode(*object, m_nodeVertices, sourceNodes, &object->vertexSourceNodes); - object->setTriangleSourceNodes(sourceNodes); + //std::vector> sourceNodes; + //resolveTriangleSourceNode(*object, m_nodeVertices, sourceNodes, &object->vertexSourceNodes); + //object->setTriangleSourceNodes(sourceNodes); - std::map, Color> sourceNodeToColorMap; - for (const auto& node : object->nodes) - sourceNodeToColorMap.insert({ { node.partId, node.nodeId }, node.color }); + //std::map, Color> sourceNodeToColorMap; + //for (const auto& node : object->nodes) + // sourceNodeToColorMap.insert({ { node.partId, node.nodeId }, node.color }); object->triangleColors.resize(object->triangles.size(), Color::createWhite()); - const std::vector>* triangleSourceNodes = object->triangleSourceNodes(); - if (nullptr != triangleSourceNodes) { - for (size_t triangleIndex = 0; triangleIndex < object->triangles.size(); triangleIndex++) { - const auto& source = (*triangleSourceNodes)[triangleIndex]; - object->triangleColors[triangleIndex] = sourceNodeToColorMap[source]; - } - } + //const std::vector>* triangleSourceNodes = object->triangleSourceNodes(); + //if (nullptr != triangleSourceNodes) { + //for (size_t triangleIndex = 0; triangleIndex < object->triangles.size(); triangleIndex++) { + //const auto& source = (*triangleSourceNodes)[triangleIndex]; + //object->triangleColors[triangleIndex] = sourceNodeToColorMap[source]; + //} + //} std::vector> triangleVertexNormals; smoothNormal(object->vertices, @@ -1117,8 +1117,8 @@ void MeshGenerator::collectUncombinedComponent(const std::string& componentIdStr return; } - m_object->nodes.insert(m_object->nodes.end(), componentCache.objectNodes.begin(), componentCache.objectNodes.end()); - m_object->edges.insert(m_object->edges.end(), componentCache.objectEdges.begin(), componentCache.objectEdges.end()); + //m_object->nodes.insert(m_object->nodes.end(), componentCache.objectNodes.begin(), componentCache.objectNodes.end()); + //m_object->edges.insert(m_object->edges.end(), componentCache.objectEdges.begin(), componentCache.objectEdges.end()); m_nodeVertices.insert(m_nodeVertices.end(), componentCache.objectNodeVertices.begin(), componentCache.objectNodeVertices.end()); collectIncombinableMesh(componentCache.mesh.get(), componentCache); @@ -1293,8 +1293,8 @@ void MeshGenerator::generate() const auto& componentCache = m_cacheContext->components[to_string(Uuid())]; - m_object->nodes = componentCache.objectNodes; - m_object->edges = componentCache.objectEdges; + //m_object->nodes = componentCache.objectNodes; + //m_object->edges = componentCache.objectEdges; m_object->partTriangleUvs = componentCache.partTriangleUvs; m_nodeVertices = componentCache.objectNodeVertices; diff --git a/dust3d/mesh/tube_mesh_builder.cc b/dust3d/mesh/tube_mesh_builder.cc index d47b4e50..f7537e25 100644 --- a/dust3d/mesh/tube_mesh_builder.cc +++ b/dust3d/mesh/tube_mesh_builder.cc @@ -45,6 +45,11 @@ const std::vector& TubeMeshBuilder::generatedVertices() return m_generatedVertices; } +const std::vector& TubeMeshBuilder::generatedVertexSources() +{ + return m_generatedVertexSources; +} + const std::vector>& TubeMeshBuilder::generatedFaces() { return m_generatedFaces; @@ -113,8 +118,6 @@ void TubeMeshBuilder::preprocessNodes() { applyInterpolation(); applyRoundEnd(); - - // TODO: Interpolate... } void TubeMeshBuilder::buildNodePositionAndDirections() @@ -260,6 +263,7 @@ void TubeMeshBuilder::build() for (size_t k = 0; k < cutFaceVertices.size(); ++k) { cutFaceIndices[i][k] = m_generatedVertices.size(); m_generatedVertices.emplace_back(cutFaceVertices[k]); + m_generatedVertexSources.emplace_back(m_nodes[i].sourceId); } } diff --git a/dust3d/mesh/tube_mesh_builder.h b/dust3d/mesh/tube_mesh_builder.h index 800ab673..6a184be2 100644 --- a/dust3d/mesh/tube_mesh_builder.h +++ b/dust3d/mesh/tube_mesh_builder.h @@ -47,6 +47,7 @@ public: void build(); const Vector3& generatedBaseNormal(); const std::vector& generatedVertices(); + const std::vector& generatedVertexSources(); const std::vector>& generatedFaces(); const std::vector>& generatedFaceUvs(); @@ -56,6 +57,7 @@ private: std::vector m_nodePositions; std::vector m_nodeForwardDirections; std::vector m_nodeForwardDistances; + std::vector m_generatedVertexSources; std::vector m_generatedVertices; std::vector> m_generatedFaces; std::vector> m_generatedFaceUvs;