去掉空白间隙的问题

This commit is contained in:
hesuicong committed 2026-10-13 14:17:40 +08:00
1 parent 73044aa575
commit 5f06661d9b
1 file changed
+8 -15
+8 -15
View File
@@ -15724,9 +15724,6 @@ void MeshTexture::ApplyGlobalSeamLevelingOnRCPatches(
{ {
if (rcPatches.empty()) return; if (rcPatches.empty()) return;
Image8U3 localAtlas(textureSize, textureSize);
localAtlas.memset(0); // 全部填 0 = 黑色
DEBUG_EXTRA("ApplyGlobalSeamLevelingOnRCPatches: bridging %zu rcPatches...", rcPatches.size()); DEBUG_EXTRA("ApplyGlobalSeamLevelingOnRCPatches: bridging %zu rcPatches...", rcPatches.size());
DEBUG_EXTRA("faceTexcoords ptr=%p, scene ptr=%p", &faceTexcoords, &scene.mesh.faceTexcoords); DEBUG_EXTRA("faceTexcoords ptr=%p, scene ptr=%p", &faceTexcoords, &scene.mesh.faceTexcoords);
// ========== 1. 构建 texturePatches ========== // ========== 1. 构建 texturePatches ==========
@@ -16009,23 +16006,19 @@ void MeshTexture::ApplyGlobalSeamLevelingOnRCPatches(
cv::Mat remapped; cv::Mat remapped;
cv::remap(correctedPatch, remapped, mapX, mapY, cv::INTER_LINEAR, cv::BORDER_CONSTANT, cv::Scalar(0,0,0)); cv::remap(correctedPatch, remapped, mapX, mapY, cv::INTER_LINEAR, cv::BORDER_CONSTANT, cv::Scalar(0,0,0));
for (int y = 0; y < patchH; ++y) for (int y = 0; y < patchH; ++y) {
{
for (int x = 0; x < patchW; ++x) { for (int x = 0; x < patchW; ++x) {
cv::Vec3b color = remapped.at<cv::Vec3b>(y, x); cv::Vec3b color = remapped.at<cv::Vec3b>(y, x);
if (color[0] == 0 && color[1] == 0 && color[2] == 0) continue; if (color[0] == 0 && color[1] == 0 && color[2] == 0) continue;
int atlasX = x + minX, atlasY = y + minY; int atlasX = x + minX, atlasY = y + minY;
if (atlasX < 0 || atlasX >= textureSize || atlasY < 0 || atlasY >= textureSize) continue; if (atlasX < 0 || atlasX >= textureSize || atlasY < 0 || atlasY >= textureSize) continue;
// atlas(atlasY, atlasX) = Pixel8U{color[2], color[1], color[0]};
if (atlasY >= 0 && atlasY < atlas.rows && atlasX >= 0 && atlasX < atlas.cols) { cv::Vec3b& pixel = atlas.at<cv::Vec3b>(atlasY, atlasX);
// 用 cv::Mat 的 at 方法,它内部有边界检查(Debug 模式下)
cv::Vec3b& pixel = localAtlas.at<cv::Vec3b>(atlasY, atlasX);
pixel[0] = color[0]; pixel[0] = color[0];
pixel[1] = color[1]; pixel[1] = color[1];
pixel[2] = color[2]; pixel[2] = color[2];
} }
}
} }
// // 调试用:导出调整后的 atlas // // 调试用:导出调整后的 atlas
@@ -16035,7 +16028,6 @@ void MeshTexture::ApplyGlobalSeamLevelingOnRCPatches(
// cv::imwrite(dbgName, atlas); // cv::imwrite(dbgName, atlas);
// DEBUG_EXTRA("Exported %s", dbgName); // DEBUG_EXTRA("Exported %s", dbgName);
} }
atlas = localAtlas;
} }
DEBUG_EXTRA("Re-rasterization done."); DEBUG_EXTRA("Re-rasterization done.");
@@ -16372,10 +16364,11 @@ bool MeshTexture::RasterizeVirtualFaces(
float currentScore = virtualFaceViewWeights[i].empty() ? -1.0f : virtualFaceViewWeights[i][0]; float currentScore = virtualFaceViewWeights[i].empty() ? -1.0f : virtualFaceViewWeights[i][0];
int minX = std::max(0, (int)floor(geom.uvBounds.ptMin.x() * textureSize)); int pad = 4;
int maxX = std::min(textureSize - 1, (int)ceil(geom.uvBounds.ptMax.x() * textureSize)); int minX = std::max(0, (int)floor(geom.uvBounds.ptMin.x() * textureSize - pad));
int minY = std::max(0, (int)floor(geom.uvBounds.ptMin.y() * textureSize)); int maxX = std::min(textureSize - 1, (int)ceil(geom.uvBounds.ptMax.x() * textureSize + pad));
int maxY = std::min(textureSize - 1, (int)ceil(geom.uvBounds.ptMax.y() * textureSize)); int minY = std::max(0, (int)floor(geom.uvBounds.ptMin.y() * textureSize - pad));
int maxY = std::min(textureSize - 1, (int)ceil(geom.uvBounds.ptMax.y() * textureSize + pad));
if (minX > maxX || minY > maxY) continue; if (minX > maxX || minY > maxY) continue;
int patchW = maxX - minX + 1, patchH = maxY - minY + 1; int patchW = maxX - minX + 1, patchH = maxY - minY + 1;