Skip to content

Commit

Permalink
wip height map usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-Zorroche committed Aug 9, 2021
1 parent 9097ce2 commit 41c66db
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
12 changes: 10 additions & 2 deletions src/aliceVision/mesh/Texturing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ void Texturing::unwrap(mvsUtils::MultiViewParams& mp, EUnwrapMethod method)
}

void Texturing::saveAsOBJ(const bfs::path& dir, const std::string& basename, imageIO::EImageFileType textureFileType,
imageIO::EImageFileType normalMapFileType, imageIO::EImageFileType heightMapFileType)
imageIO::EImageFileType normalMapFileType, imageIO::EImageFileType heightMapFileType, const std::string& heightMapUsage)
{
ALICEVISION_LOG_INFO("Writing obj and mtl file.");

Expand Down Expand Up @@ -1045,9 +1045,17 @@ void Texturing::saveAsOBJ(const bfs::path& dir, const std::string& basename, ima
if(heightMapFileType != imageIO::EImageFileType::NONE)
{
const aiString texFileHeightMap("Heightmap_" + std::to_string(textureId) + "." + EImageFileType_enumToString(heightMapFileType));
scene.mMaterials[atlasId]->AddProperty(&texFileHeightMap, AI_MATKEY_TEXTURE_DISPLACEMENT(0));
if (heightMapUsage == "displacement")
{
scene.mMaterials[atlasId]->AddProperty(&texFileHeightMap, AI_MATKEY_TEXTURE_DISPLACEMENT(0));
}
else if (heightMapUsage == "bump")
{
scene.mMaterials[atlasId]->AddProperty(&texFileHeightMap, AI_MATKEY_TEXTURE_HEIGHT(0));
}
}


scene.mRootNode->mMeshes[atlasId] = atlasId;
scene.mMeshes[atlasId] = new aiMesh;
aiMesh * aimesh = scene.mMeshes[atlasId];
Expand Down
11 changes: 7 additions & 4 deletions src/aliceVision/mesh/Texturing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ struct NormalsParams
{
imageIO::EImageFileType normalMapFileType;
imageIO::EImageFileType heightMapFileType;

std::string heightMapUsage = "displacement";
};

struct TexturingParams
Expand All @@ -75,7 +77,7 @@ struct TexturingParams
double bestScoreThreshold = 0.1; //< 0.0 to disable filtering based on threshold to relative best score
double angleHardThreshold = 90.0; //< 0.0 to disable angle hard threshold filtering

imageIO::EImageFileType textureFileType;
imageIO::EImageFileType textureFileType = imageIO::EImageFileType::NONE;
imageIO::EImageColorSpace processColorspace = imageIO::EImageColorSpace::SRGB; // colorspace for the texturing internal computation
mvsUtils::ImagesCache::ECorrectEV correctEV{mvsUtils::ImagesCache::ECorrectEV::NO_CORRECTION};

Expand Down Expand Up @@ -198,9 +200,10 @@ struct Texturing

/// Save textured mesh as an OBJ + MTL file
void saveAsOBJ(const bfs::path& dir, const std::string& basename,
imageIO::EImageFileType textureFileType = imageIO::EImageFileType::PNG,
imageIO::EImageFileType normalMapFileType = imageIO::EImageFileType::PNG,
imageIO::EImageFileType heightMapFileType = imageIO::EImageFileType::PNG);
imageIO::EImageFileType textureFileType = imageIO::EImageFileType::EXR,
imageIO::EImageFileType normalMapFileType = imageIO::EImageFileType::EXR,
imageIO::EImageFileType heightMapFileType = imageIO::EImageFileType::EXR,
const std::string& heightMapUsage = "displacement");
};

} // namespace mesh
Expand Down
12 changes: 5 additions & 7 deletions src/software/pipeline/main_texturing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ int aliceVision_main(int argc, char* argv[])
imageIO::EImageFileType_informations().c_str())
("outputHeightMapFileType", po::value<imageIO::EImageFileType>(&normalsParams.heightMapFileType)->default_value(imageIO::EImageFileType::NONE),
imageIO::EImageFileType_informations().c_str())
("heightMapUsage", po::value<std::string>(&normalsParams.heightMapUsage)->default_value(normalsParams.heightMapUsage),
"Use HeightMap for displacement or bump mapping")
("unwrapMethod", po::value<std::string>(&unwrapMethod)->default_value(unwrapMethod),
"Method to unwrap input mesh if it does not have UV coordinates.\n"
" * Basic (> 600k faces) fast and simple. Can generate multiple atlases.\n"
Expand Down Expand Up @@ -219,7 +221,7 @@ int aliceVision_main(int argc, char* argv[])
if(!inputMeshFilepath.empty())
{
mesh.saveAsOBJ(outputFolder, "texturedMesh", texParams.textureFileType,
normalsParams.normalMapFileType, normalsParams.heightMapFileType);
normalsParams.normalMapFileType, normalsParams.heightMapFileType, normalsParams.heightMapUsage);
}

if(texParams.subdivisionTargetRatio > 0)
Expand Down Expand Up @@ -256,12 +258,8 @@ int aliceVision_main(int argc, char* argv[])
ALICEVISION_LOG_INFO("Generate height and normal maps.");

mesh::Mesh denseMesh;
{
if(!denseMesh.loadFromObjAscii(inputRefMeshFilepath))
{
throw std::runtime_error("Unable to load: " + inputRefMeshFilepath);
}
}
denseMesh.loadFromObjAscii(inputRefMeshFilepath);

mesh.generateNormalAndHeightMaps(mp, denseMesh, outputFolder, normalsParams);
}

Expand Down

0 comments on commit 41c66db

Please sign in to comment.