Skip to content

Commit

Permalink
[Texturing] saveAs with different mesh file types
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-Zorroche committed Aug 12, 2021
1 parent 3b806ea commit 1770632
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 11 deletions.
66 changes: 61 additions & 5 deletions src/aliceVision/mesh/Texturing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,53 @@ std::string EVisibilityRemappingMethod_enumToString(EVisibilityRemappingMethod m
throw std::out_of_range("Unrecognized EVisibilityRemappingMethod");
}

std::string EMeshFileType_enumToString(const EMeshFileType meshFileType)
{
switch(meshFileType)
{
case EMeshFileType::OBJ:
return "obj";
case EMeshFileType::FBX:
return "fbx";
case EMeshFileType::STL:
return "stl";
case EMeshFileType::GLTF2:
return "gltf";
}
throw std::out_of_range("Unrecognized EMeshFileType");
}

EMeshFileType EMeshFileType_stringToEnum(const std::string& meshFileType)
{
std::string m = meshFileType;
boost::to_lower(m);

if(m == "obj")
return EMeshFileType::OBJ;
if(m == "fbx")
return EMeshFileType::FBX;
if(m == "stl")
return EMeshFileType::STL;
if(m == "gltf" || m == "gltf2")
return EMeshFileType::GLTF2;
throw std::out_of_range("Invalid mesh file type " + meshFileType);
}

std::ostream& operator<<(std::ostream& os, EMeshFileType meshFileType)
{
return os << EMeshFileType_enumToString(meshFileType);
}

std::istream& operator>>(std::istream& in, EMeshFileType& meshFileType)
{
std::string token;
in >> token;
meshFileType = EMeshFileType_stringToEnum(token);
return in;
}



/**
* @brief Return whether a pixel is contained in or intersected by a 2D triangle.
* @param[in] triangle the triangle as an array of 3 point2Ds
Expand Down Expand Up @@ -987,12 +1034,18 @@ 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, const std::string& heightMapUsage)
void Texturing::saveAs(const bfs::path& dir, const std::string& basename,
aliceVision::mesh::EMeshFileType meshFileType,
imageIO::EImageFileType textureFileType,
imageIO::EImageFileType normalMapFileType,
imageIO::EImageFileType heightMapFileType,
const std::string& heightMapUsage)
{
ALICEVISION_LOG_INFO("Writing obj and mtl file.");
const std::string fileTypeStr = EMeshFileType_enumToString(meshFileType);
const std::string objFilename = (dir / (basename + "." + fileTypeStr)).string();

ALICEVISION_LOG_INFO("Save " << fileTypeStr << " mesh file");

const std::string objFilename = (dir / (basename + ".obj")).string();

if (_atlases.empty())
{
Expand Down Expand Up @@ -1123,7 +1176,10 @@ void Texturing::saveAsOBJ(const bfs::path& dir, const std::string& basename, ima
}

Assimp::Exporter exporter;
exporter.Export(&scene, "obj", objFilename);
if (fileTypeStr == "gltf")
exporter.Export(&scene, "gltf2", objFilename);
else
exporter.Export(&scene, fileTypeStr, objFilename);
}


Expand Down
23 changes: 18 additions & 5 deletions src/aliceVision/mesh/Texturing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ EUnwrapMethod EUnwrapMethod_stringToEnum(const std::string& method);
*/
std::string EUnwrapMethod_enumToString(EUnwrapMethod method);

enum class EMeshFileType
{
OBJ = 0,
FBX,
GLTF2,
STL
};

EMeshFileType EMeshFileType_stringToEnum(const std::string& meshFileType);
std::string EMeshFileType_enumToString(const EMeshFileType meshFileType);
std::ostream& operator<<(std::ostream& os, EMeshFileType meshFileType);
std::istream& operator>>(std::istream& in, EMeshFileType& meshFileType);

struct NormalsParams
{
Expand Down Expand Up @@ -199,11 +211,12 @@ struct Texturing
imageIO::EImageFileType textureFileType, const int level);

/// Save textured mesh as an OBJ + MTL file
void saveAsOBJ(const bfs::path& dir, const std::string& basename,
imageIO::EImageFileType textureFileType = imageIO::EImageFileType::EXR,
imageIO::EImageFileType normalMapFileType = imageIO::EImageFileType::EXR,
imageIO::EImageFileType heightMapFileType = imageIO::EImageFileType::EXR,
const std::string& heightMapUsage = "displacement");
void saveAs(const bfs::path& dir, const std::string& basename,
aliceVision::mesh::EMeshFileType meshFileType,
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
5 changes: 4 additions & 1 deletion src/software/pipeline/main_texturing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ int aliceVision_main(int argc, char* argv[])

std::string inputMeshFilepath; // Model to texture (HighPoly for diffuse, LowPoly for Diffuse+Normal)
std::string inputRefMeshFilepath; // HighPoly for NormalMap
aliceVision::mesh::EMeshFileType outputMeshFileType;

std::string outputFolder;
std::string imagesFolder;
Expand Down Expand Up @@ -84,6 +85,8 @@ int aliceVision_main(int argc, char* argv[])
"Output texture size")
("downscale", po::value<unsigned int>(&texParams.downscale)->default_value(texParams.downscale),
"Texture downscale factor")
("outputMeshFileType", po::value<aliceVision::mesh::EMeshFileType>(&outputMeshFileType)->default_value(aliceVision::mesh::EMeshFileType::OBJ),
"output mesh file type")
("outputTextureFileType", po::value<imageIO::EImageFileType>(&texParams.textureFileType)->default_value(imageIO::EImageFileType::NONE),
imageIO::EImageFileType_informations().c_str())
("outputNormalMapFileType", po::value<imageIO::EImageFileType>(&normalsParams.normalMapFileType)->default_value(imageIO::EImageFileType::NONE),
Expand Down Expand Up @@ -220,7 +223,7 @@ int aliceVision_main(int argc, char* argv[])
// save final obj file
if(!inputMeshFilepath.empty())
{
mesh.saveAsOBJ(outputFolder, "texturedMesh", texParams.textureFileType,
mesh.saveAs(outputFolder, "texturedMesh", outputMeshFileType, texParams.textureFileType,
normalsParams.normalMapFileType, normalsParams.heightMapFileType, normalsParams.heightMapUsage);
}

Expand Down

0 comments on commit 1770632

Please sign in to comment.