diff --git a/src/meshlabplugins/filter_texture/filter_texture.cpp b/src/meshlabplugins/filter_texture/filter_texture.cpp index 5bc652932..113b3e46a 100644 --- a/src/meshlabplugins/filter_texture/filter_texture.cpp +++ b/src/meshlabplugins/filter_texture/filter_texture.cpp @@ -1053,10 +1053,11 @@ bool FilterTexturePlugin::applyFilter(QAction *filter, MeshDocument &md, RichPar vector srcImgs; srcImgs.resize(srcMesh->cm.textures.size()); - QString path(srcMesh->fullName()); + QString path; for (int textInd = 0; textInd < srcMesh->cm.textures.size(); textInd++) { + path = m.fullName(); path = path.left(std::max(path.lastIndexOf('\\'), path.lastIndexOf('/')) + 1).append(srcMesh->cm.textures[textInd].c_str()); CheckError(!QFile(path).exists(), QString("Source texture \"").append(path).append("\" doesn't exists")); CheckError(!srcImgs[textInd].load(path), QString("Source texture \"").append(path).append("\" cannot be opened")); @@ -1090,6 +1091,8 @@ bool FilterTexturePlugin::applyFilter(QAction *filter, MeshDocument &md, RichPar if (trgMesh->cm.Tr != Matrix44m::Identity()) tri::UpdatePosition::Matrix(trgMesh->cm, Inverse(trgMesh->cm.Tr), true); } + + srcMesh->clearDataMask(MeshModel::MM_FACEMARK); } break; diff --git a/src/meshlabplugins/filter_texture/rastering.h b/src/meshlabplugins/filter_texture/rastering.h index a8c302326..ab28b6d79 100644 --- a/src/meshlabplugins/filter_texture/rastering.h +++ b/src/meshlabplugins/filter_texture/rastering.h @@ -80,15 +80,23 @@ public: assert(ret); interp[2]=1.0-interp[1]-interp[0]; - int w = srcImgs[nearestF->cWT(0).N()].width(), h = srcImgs[nearestF->cWT(0).N()].height(); - int x, y; - x = w * (interp[0]*nearestF->cWT(0).U()+interp[1]*nearestF->cWT(1).U()+interp[2]*nearestF->cWT(2).U()); - y = h * (1.0 - (interp[0]*nearestF->cWT(0).V()+interp[1]*nearestF->cWT(1).V()+interp[2]*nearestF->cWT(2).V())); - // repeat mode - x = (x%w + w)%w; - y = (y%h + h)%h; - QRgb px = srcImgs[nearestF->cWT(0).N()].pixel(x, y); - v.C() = CMeshO::VertexType::ColorType(qRed(px), qGreen(px), qBlue(px), 255); + int tIndex = nearestF->cWT(0).N(); + if ((tIndex >= 0) && (tIndex < srcImgs.size())) + { + int w = srcImgs[tIndex].width(), h = srcImgs[tIndex].height(); + int x, y; + x = w * (interp[0] * nearestF->cWT(0).U() + interp[1] * nearestF->cWT(1).U() + interp[2] * nearestF->cWT(2).U()); + y = h * (1.0 - (interp[0] * nearestF->cWT(0).V() + interp[1] * nearestF->cWT(1).V() + interp[2] * nearestF->cWT(2).V())); + // repeat mode + x = (x%w + w) % w; + y = (y%h + h) % h; + QRgb px = srcImgs[tIndex].pixel(x, y); + v.C() = CMeshO::VertexType::ColorType(qRed(px), qGreen(px), qBlue(px), 255); + } + else + { + v.C() = CMeshO::VertexType::ColorType(255, 255, 255, 255); + } } };