From 7c984e12da23b88cfb4660835a701ab5a0ff4948 Mon Sep 17 00:00:00 2001 From: Paolo Cignoni Date: Tue, 20 Feb 2018 10:24:29 +0100 Subject: [PATCH] Added WedgeTexMergeClose that Merge supposedly wrong texcoords --- vcg/complex/algorithms/update/texture.h | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/vcg/complex/algorithms/update/texture.h b/vcg/complex/algorithms/update/texture.h index c2ff6f92..5b380366 100644 --- a/vcg/complex/algorithms/update/texture.h +++ b/vcg/complex/algorithms/update/texture.h @@ -48,6 +48,7 @@ typedef typename MeshType::VertexIterator VertexIterator; typedef typename MeshType::FaceType FaceType; typedef typename MeshType::FacePointer FacePointer; typedef typename MeshType::FaceIterator FaceIterator; +typedef typename vcg::Point2 UVCoordType; static void WedgeTexFromPlane(ComputeMeshType &m, const Point3 &uVec, const Point3 &vVec, bool aspectRatio, ScalarType sideGutter=0.0) { @@ -138,6 +139,38 @@ static void WedgeTexRemoveNull(ComputeMeshType &m, const std::string &texturenam } } +/** \brief Merge supposedly wrong texcoords + * It can happens that for rounding errors texcoords on different wedges but on the same vertex have different tex coords. + * This function merges them according a threshold. It requires initialized VF adjacency. + * the default for merging is if two textures dist less than one 16th of texel on a 4k texture... +*/ + +static void WedgeTexMergeClose(ComputeMeshType &m, ScalarType mergeThr = ScalarType(1.0/65536.0) ) +{ + tri::RequireVFAdjacency(m); + + ForEachVertex(m, [&](VertexType &v){ + face::VFIterator vfi(&v); + std::vector clusterVec; + clusterVec.push_back(vfi.F()->WT(vfi.I()).P()); + ++vfi; + while(!vfi.End()) + { + UVCoordType cur= vfi.F()->WT(vfi.I()).P(); + bool merged=false; + for(auto p:clusterVec) { + if(Distance(p,cur) < mergeThr){ + vfi.F()->WT(vfi.I()).P()=p; + merged=true; + } + } + if(!merged) + clusterVec.push_back(cur); + + ++vfi; + } + }); +} }; // end class