texture 2 vert color (2meshes) fixup

but, still, it screws up the textures IN MEMORY... still to be debugged
This commit is contained in:
Marco Callieri 2018-04-04 18:30:48 +02:00
parent ef9a832dc8
commit 694c39e9f5
2 changed files with 21 additions and 10 deletions

View File

@ -1053,10 +1053,11 @@ bool FilterTexturePlugin::applyFilter(QAction *filter, MeshDocument &md, RichPar
vector <QImage> 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<int>(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<CMeshO>::Matrix(trgMesh->cm, Inverse(trgMesh->cm.Tr), true);
}
srcMesh->clearDataMask(MeshModel::MM_FACEMARK);
}
break;

View File

@ -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);
}
}
};