From 4e861d3d2dc292fec0c8a8048a31937f87fa25f7 Mon Sep 17 00:00:00 2001 From: Jeremy HU Date: Tue, 1 Nov 2022 23:10:21 +1100 Subject: [PATCH] Collect seam triangle UVs --- application/sources/uv_map_generator.cc | 26 +++++++++++++++++++++++++ application/sources/uv_map_generator.h | 1 + dust3d/mesh/mesh_generator.cc | 4 +--- dust3d/mesh/mesh_state.cc | 5 +++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/application/sources/uv_map_generator.cc b/application/sources/uv_map_generator.cc index ba28a91a..dda507a8 100644 --- a/application/sources/uv_map_generator.cc +++ b/application/sources/uv_map_generator.cc @@ -3,6 +3,7 @@ #include #include #include +#include size_t UvMapGenerator::m_textureSize = 4096; @@ -117,6 +118,30 @@ void UvMapGenerator::packUvs() m_mapPacker->pack(); } +void UvMapGenerator::filterSeamUvs() +{ + /* + dust3dDebug << "m_object->seamTriangleUvs.size():" << m_object->seamTriangleUvs.size(); + std::map, size_t> triangleMap; + for (size_t i = 0; i < m_object->seamTriangleUvs.size(); ++i) { + for (const auto& it : m_object->seamTriangleUvs[i]) { + triangleMap.insert({ it.first, i }); + } + // TODO: + } + std::unordered_set seams; + size_t uvTriangleCount = 0; + for (const auto& triangle : m_object->triangles) { + auto findResult = triangleMap.find(std::array { m_object->vertices[triangle[0]], m_object->vertices[triangle[1]], m_object->vertices[triangle[2]] }); + if (triangleMap.end() != findResult) { + ++uvTriangleCount; + seams.insert(findResult->second); + } + } + dust3dDebug << "uvTriangleCount:" << uvTriangleCount << "seams:" << seams.size(); + */ +} + void UvMapGenerator::generateTextureColorImage() { m_textureColorImage = std::make_unique(UvMapGenerator::m_textureSize, UvMapGenerator::m_textureSize, QImage::Format_ARGB32); @@ -189,6 +214,7 @@ void UvMapGenerator::generate() if (nullptr == m_snapshot) return; + filterSeamUvs(); packUvs(); generateTextureColorImage(); generateUvCoords(); diff --git a/application/sources/uv_map_generator.h b/application/sources/uv_map_generator.h index 9e216ce5..404598cc 100644 --- a/application/sources/uv_map_generator.h +++ b/application/sources/uv_map_generator.h @@ -45,6 +45,7 @@ private: void packUvs(); void generateTextureColorImage(); void generateUvCoords(); + void filterSeamUvs(); }; #endif diff --git a/dust3d/mesh/mesh_generator.cc b/dust3d/mesh/mesh_generator.cc index 19bad801..cfb07ab0 100644 --- a/dust3d/mesh/mesh_generator.cc +++ b/dust3d/mesh/mesh_generator.cc @@ -963,8 +963,6 @@ std::unique_ptr MeshGenerator::combineComponentChildGroupMesh(const s componentCache.sharedQuadEdges.insert(it); for (const auto& it : childComponentCache.partTriangleUvs) componentCache.partTriangleUvs.insert({ it.first, it.second }); - for (const auto& it : childComponentCache.seamTriangleUvs) - componentCache.seamTriangleUvs.push_back(it); for (const auto& it : childComponentCache.objectNodes) componentCache.objectNodes.push_back(it); for (const auto& it : childComponentCache.objectEdges) @@ -1298,13 +1296,13 @@ void MeshGenerator::generate() m_object->nodes = componentCache.objectNodes; m_object->edges = componentCache.objectEdges; m_object->partTriangleUvs = componentCache.partTriangleUvs; - m_object->seamTriangleUvs = componentCache.seamTriangleUvs; m_nodeVertices = componentCache.objectNodeVertices; std::vector combinedVertices; std::vector> combinedFaces; if (nullptr != combinedMesh) { combinedMesh->fetch(combinedVertices, combinedFaces); + m_object->seamTriangleUvs = combinedMesh->seamTriangleUvs; if (m_weldEnabled) { size_t totalAffectedNum = 0; size_t affectedNum = 0; diff --git a/dust3d/mesh/mesh_state.cc b/dust3d/mesh/mesh_state.cc index df184404..cc35c8aa 100644 --- a/dust3d/mesh/mesh_state.cc +++ b/dust3d/mesh/mesh_state.cc @@ -20,6 +20,7 @@ * SOFTWARE. */ +#include #include #include @@ -96,6 +97,10 @@ std::unique_ptr MeshState::combine(const MeshState& first, const Mesh return nullptr; } newMeshState->mesh = std::move(newMesh); + for (const auto& it : first.seamTriangleUvs) + newMeshState->seamTriangleUvs.push_back(it); + for (const auto& it : second.seamTriangleUvs) + newMeshState->seamTriangleUvs.push_back(it); return newMeshState; }