Added WedgeTexMergeClose that Merge supposedly wrong texcoords

This commit is contained in:
Paolo Cignoni 2018-02-20 10:24:29 +01:00
parent 23cb998b04
commit 7c984e12da
1 changed files with 33 additions and 0 deletions

View File

@ -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<ScalarType> UVCoordType;
static void WedgeTexFromPlane(ComputeMeshType &m, const Point3<ScalarType> &uVec, const Point3<ScalarType> &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<FaceType> vfi(&v);
std::vector<UVCoordType> 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