Collect seam triangle UVs

master
Jeremy HU 2022-11-01 23:10:21 +11:00
parent 1fa1e0e199
commit 4e861d3d2d
4 changed files with 33 additions and 3 deletions

View File

@ -3,6 +3,7 @@
#include <QMatrix> #include <QMatrix>
#include <QPainter> #include <QPainter>
#include <dust3d/uv/uv_map_packer.h> #include <dust3d/uv/uv_map_packer.h>
#include <unordered_set>
size_t UvMapGenerator::m_textureSize = 4096; size_t UvMapGenerator::m_textureSize = 4096;
@ -117,6 +118,30 @@ void UvMapGenerator::packUvs()
m_mapPacker->pack(); m_mapPacker->pack();
} }
void UvMapGenerator::filterSeamUvs()
{
/*
dust3dDebug << "m_object->seamTriangleUvs.size():" << m_object->seamTriangleUvs.size();
std::map<std::array<dust3d::PositionKey, 3>, 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<size_t> seams;
size_t uvTriangleCount = 0;
for (const auto& triangle : m_object->triangles) {
auto findResult = triangleMap.find(std::array<dust3d::PositionKey, 3> { 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() void UvMapGenerator::generateTextureColorImage()
{ {
m_textureColorImage = std::make_unique<QImage>(UvMapGenerator::m_textureSize, UvMapGenerator::m_textureSize, QImage::Format_ARGB32); m_textureColorImage = std::make_unique<QImage>(UvMapGenerator::m_textureSize, UvMapGenerator::m_textureSize, QImage::Format_ARGB32);
@ -189,6 +214,7 @@ void UvMapGenerator::generate()
if (nullptr == m_snapshot) if (nullptr == m_snapshot)
return; return;
filterSeamUvs();
packUvs(); packUvs();
generateTextureColorImage(); generateTextureColorImage();
generateUvCoords(); generateUvCoords();

View File

@ -45,6 +45,7 @@ private:
void packUvs(); void packUvs();
void generateTextureColorImage(); void generateTextureColorImage();
void generateUvCoords(); void generateUvCoords();
void filterSeamUvs();
}; };
#endif #endif

View File

@ -963,8 +963,6 @@ std::unique_ptr<MeshState> MeshGenerator::combineComponentChildGroupMesh(const s
componentCache.sharedQuadEdges.insert(it); componentCache.sharedQuadEdges.insert(it);
for (const auto& it : childComponentCache.partTriangleUvs) for (const auto& it : childComponentCache.partTriangleUvs)
componentCache.partTriangleUvs.insert({ it.first, it.second }); componentCache.partTriangleUvs.insert({ it.first, it.second });
for (const auto& it : childComponentCache.seamTriangleUvs)
componentCache.seamTriangleUvs.push_back(it);
for (const auto& it : childComponentCache.objectNodes) for (const auto& it : childComponentCache.objectNodes)
componentCache.objectNodes.push_back(it); componentCache.objectNodes.push_back(it);
for (const auto& it : childComponentCache.objectEdges) for (const auto& it : childComponentCache.objectEdges)
@ -1298,13 +1296,13 @@ void MeshGenerator::generate()
m_object->nodes = componentCache.objectNodes; m_object->nodes = componentCache.objectNodes;
m_object->edges = componentCache.objectEdges; m_object->edges = componentCache.objectEdges;
m_object->partTriangleUvs = componentCache.partTriangleUvs; m_object->partTriangleUvs = componentCache.partTriangleUvs;
m_object->seamTriangleUvs = componentCache.seamTriangleUvs;
m_nodeVertices = componentCache.objectNodeVertices; m_nodeVertices = componentCache.objectNodeVertices;
std::vector<Vector3> combinedVertices; std::vector<Vector3> combinedVertices;
std::vector<std::vector<size_t>> combinedFaces; std::vector<std::vector<size_t>> combinedFaces;
if (nullptr != combinedMesh) { if (nullptr != combinedMesh) {
combinedMesh->fetch(combinedVertices, combinedFaces); combinedMesh->fetch(combinedVertices, combinedFaces);
m_object->seamTriangleUvs = combinedMesh->seamTriangleUvs;
if (m_weldEnabled) { if (m_weldEnabled) {
size_t totalAffectedNum = 0; size_t totalAffectedNum = 0;
size_t affectedNum = 0; size_t affectedNum = 0;

View File

@ -20,6 +20,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include <dust3d/base/debug.h>
#include <dust3d/mesh/mesh_recombiner.h> #include <dust3d/mesh/mesh_recombiner.h>
#include <dust3d/mesh/mesh_state.h> #include <dust3d/mesh/mesh_state.h>
@ -96,6 +97,10 @@ std::unique_ptr<MeshState> MeshState::combine(const MeshState& first, const Mesh
return nullptr; return nullptr;
} }
newMeshState->mesh = std::move(newMesh); 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; return newMeshState;
} }