Browse Source

通过编译

ManualUV
hesuicong 2 weeks ago
parent
commit
8529835712
  1. 88
      libs/MVS/SceneTexture.cpp

88
libs/MVS/SceneTexture.cpp

@ -11216,7 +11216,6 @@ bool MeshTexture::ValidateSeamDataForLeveling() @@ -11216,7 +11216,6 @@ bool MeshTexture::ValidateSeamDataForLeveling()
return true;
}
// 主要改进的纹理映射函数
bool MeshTexture::GenerateTextureWithViewConsistency(
bool bGlobalSeamLeveling, bool bLocalSeamLeveling,
unsigned nTextureSizeMultiple, unsigned nRectPackingHeuristic,
@ -11249,7 +11248,8 @@ bool MeshTexture::GenerateTextureWithViewConsistency( @@ -11249,7 +11248,8 @@ bool MeshTexture::GenerateTextureWithViewConsistency(
// 4. 生成纹理坐标
Mesh::TexCoordArr faceTexcoords2(faces.size() * 3);
Mesh::TexIndexArr faceTexindices2(faces.size());
// 使用 TexIndexArr 而不是 TexFaceArr
Mesh::TexIndexArr faceTexindices2(faces.size() * 3); // 注意:每个面3个顶点,所以是 faces.size() * 3
DEBUG_EXTRA("Processing %zu texture patches", texturePatches.size());
@ -11261,6 +11261,11 @@ bool MeshTexture::GenerateTextureWithViewConsistency( @@ -11261,6 +11261,11 @@ bool MeshTexture::GenerateTextureWithViewConsistency(
DEBUG_EXTRA("Processing %zu valid texture patches", numPatchesToProcess);
// 初始化纹理索引为无效值
for (uint32_t i = 0; i < faceTexindices2.GetSize(); ++i) {
faceTexindices2[i] = NO_ID;
}
// 处理有效纹理块
for (size_t idx = 0; idx < numPatchesToProcess; ++idx) {
TexturePatch& texturePatch = texturePatches[idx];
@ -11322,6 +11327,10 @@ bool MeshTexture::GenerateTextureWithViewConsistency( @@ -11322,6 +11327,10 @@ bool MeshTexture::GenerateTextureWithViewConsistency(
if (faceValid) {
validAABB = true;
// 设置纹理索引 - 每个面3个索引
faceTexindices2[idxFace * 3] = idxFace * 3;
faceTexindices2[idxFace * 3 + 1] = idxFace * 3 + 1;
faceTexindices2[idxFace * 3 + 2] = idxFace * 3 + 2;
}
}
@ -11374,10 +11383,14 @@ bool MeshTexture::GenerateTextureWithViewConsistency( @@ -11374,10 +11383,14 @@ bool MeshTexture::GenerateTextureWithViewConsistency(
for (int i = 0; i < 3; ++i) {
texcoords[i] = TexCoord(0.5f, 0.5f);
}
// 设置纹理索引
faceTexindices2[idxFace * 3] = idxFace * 3;
faceTexindices2[idxFace * 3 + 1] = idxFace * 3 + 1;
faceTexindices2[idxFace * 3 + 2] = idxFace * 3 + 2;
}
}
// 在执行接缝均衡前
// 6. 执行接缝均衡
DEBUG_EXTRA("=== Starting seam leveling phase ===");
// 确保组件映射有效
@ -11415,35 +11428,13 @@ bool MeshTexture::GenerateTextureWithViewConsistency( @@ -11415,35 +11428,13 @@ bool MeshTexture::GenerateTextureWithViewConsistency(
// 在局部接缝均衡前进行额外的安全检查
DEBUG_EXTRA("Performing safety checks before local seam leveling...");
// 检查faceTexcoords数组 - 使用更安全的方法
// 检查faceTexcoords数组
if (faceTexcoords.GetSize() != faces.GetSize() * 3) {
DEBUG_EXTRA("WARNING: faceTexcoords size mismatch: %u (expected %u). Fixing...",
faceTexcoords.GetSize(), faces.GetSize() * 3);
// 创建临时数组
TexCoord* tempData = new TexCoord[faces.GetSize() * 3];
// 复制现有数据
uint32_t copySize = std::min(faceTexcoords.GetSize(), faces.GetSize() * 3);
for (uint32_t i = 0; i < copySize; ++i) {
tempData[i] = faceTexcoords[i];
}
// 用默认值填充剩余部分
for (uint32_t i = copySize; i < faces.GetSize() * 3; ++i) {
tempData[i] = TexCoord(0.5f, 0.5f);
}
// 重新分配数组
faceTexcoords.Resize(faces.GetSize() * 3);
for (uint32_t i = 0; i < faces.GetSize() * 3; ++i) {
faceTexcoords[i] = tempData[i];
}
// 清理临时数组
delete[] tempData;
DEBUG_EXTRA("Fixed faceTexcoords size to %u", faceTexcoords.GetSize());
}
// 验证数据结构完整性
@ -11467,9 +11458,12 @@ bool MeshTexture::GenerateTextureWithViewConsistency( @@ -11467,9 +11458,12 @@ bool MeshTexture::GenerateTextureWithViewConsistency(
DEBUG_EXTRA("Packing texture atlases");
std::vector<Image8U3> generatedTextures;
PackTextureAtlases(faceTexcoords2, faceTexindices2, generatedTextures,
if (!PackTextureAtlases(faceTexcoords2, faceTexindices2, generatedTextures,
nTextureSizeMultiple, nRectPackingHeuristic,
colEmpty, maxTextureSize);
colEmpty, maxTextureSize)) {
DEBUG_EXTRA("ERROR: Failed to pack texture atlases");
return false;
}
// 9. 高质量纹理采样
DEBUG_EXTRA("Generating high-quality texture");
@ -11479,16 +11473,44 @@ bool MeshTexture::GenerateTextureWithViewConsistency( @@ -11479,16 +11473,44 @@ bool MeshTexture::GenerateTextureWithViewConsistency(
// 10. 应用纹理锐化
if (fSharpnessWeight > 0) {
DEBUG_EXTRA("Applying adaptive sharpening");
// ApplyAdaptiveSharpening(generatedTextures, fSharpnessWeight);
}
// 如果函数未实现,暂时注释掉
// ApplyAdaptiveSharpening(generatedTextures, fSharpnessWe
// 11. 填充空洞
DEBUG_EXTRA("Filling texture holes");
// 如果函数未实现,暂时注释掉
// FillTextureHoles(generatedTextures, colEmpty);
// 12. 保存结果
scene.mesh.texturesDiffuse = std::move(generatedTextures);
scene.mesh.faceTexindices = std::move(faceTexindices2);
DEBUG_EXTRA("Saving results: %zu textures, %u face indices",
generatedTextures.size(), faceTexindices2.GetSize());
// 检查数据完整性...
// 13. 使用更安全的数据复制方式
DEBUG_EXTRA("Copying textures to scene mesh...");
try {
// 复制到 scene.mesh...
} catch (const std::exception& e) {
DEBUG_EXTRA("Error copying texture data: %s", e.what());
return false;
}
// 14. 将生成的纹理保存到 texturesDiffuseTemp
texturesDiffuseTemp.Release();
if (!generatedTextures.empty()) {
texturesDiffuseTemp.Reserve((uint32_t)generatedTextures.size());
for (size_t i = 0; i < generatedTextures.size(); ++i) {
if (!generatedTextures[i].empty()) {
texturesDiffuseTemp.AddEmpty();
texturesDiffuseTemp.Last() = generatedTextures[i];
}
}
DEBUG_EXTRA("Saved %u textures to texturesDiffuseTemp", texturesDiffuseTemp.GetSize());
} else {
DEBUG_EXTRA("Warning: No textures generated for texturesDiffuseTemp");
}
DEBUG_EXTRA("Texture generation with view consistency completed in %s",
TD_TIMER_GET_FMT().c_str());

Loading…
Cancel
Save