Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate NormalMaps and HeightMaps #1092

Merged
merged 28 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
22e59c4
[software] Texturing: compute NormalMap (WIP)
Thomas-Zorroche Jul 23, 2021
524d3b2
[software] fix GeoVec type error and add debug
Thomas-Zorroche Jul 26, 2021
adc8443
[software] GenerateNormalMap: remap uv between [0,1]
Thomas-Zorroche Jul 29, 2021
75678d7
[software] Texturing: add normalsParams struct for normalMaps
Thomas-Zorroche Jul 29, 2021
f9fb592
[software] change normal maps suffix (1001 + atlasId)
Thomas-Zorroche Jul 29, 2021
c782569
[software] remap pixel color between 0 and 1 for exr
Thomas-Zorroche Aug 5, 2021
59a68f1
[software] fix rebase conflicts
Thomas-Zorroche Aug 6, 2021
8d3a026
[git] gitignore: ignore nfs temp files
Thomas-Zorroche Aug 9, 2021
3b806ea
[Texturing] height map usage
Thomas-Zorroche Aug 9, 2021
1770632
[Texturing] saveAs with different mesh file types
Thomas-Zorroche Aug 10, 2021
4559acb
[software] replace all saveToObj by save with different filetype
Thomas-Zorroche Aug 13, 2021
d1e9773
[convert] use assimp to convert mesh instead of geogram
Thomas-Zorroche Aug 13, 2021
f6956c0
[texturing] fix filename export
Thomas-Zorroche Aug 16, 2021
bb837c3
[texturing] change bumpMappingParams struct
Thomas-Zorroche Aug 16, 2021
96b5c7a
[texturing] flip uv when exporting mesh
Thomas-Zorroche Aug 17, 2021
ac087cb
[pipeline] receive two file type parameters for bump mapping
Thomas-Zorroche Aug 17, 2021
633cc5b
[Texturing] add flags for flipUV (only for .gltf)
Thomas-Zorroche Aug 18, 2021
3956c1a
[Texturing] add EBumpMappingType enum (Normal, Height)
Thomas-Zorroche Aug 18, 2021
6bdc933
[pipeline] add outputMeshFileType parameter for meshMasking
Thomas-Zorroche Aug 18, 2021
51aab84
[pipeline] rename loading functions
Thomas-Zorroche Aug 20, 2021
053ee8a
[Texturing] FlipUV: add comment from github issue
Thomas-Zorroche Aug 23, 2021
58546b8
[Texturing] add assimp flag for generating normals when export to gltf
Thomas-Zorroche Aug 23, 2021
9bb1574
[Mesh] add debug: vertices count for export / import
Thomas-Zorroche Aug 24, 2021
29a16fd
[Mesh] change Assimp flags for importer
Thomas-Zorroche Aug 26, 2021
470ffe9
[pipeline] change default format to obj
Thomas-Zorroche Aug 27, 2021
ec13480
[software] convertMesh: remove output type arguments
fabiencastan Sep 2, 2021
b69839d
[mvsData] use forward declaration to avoid new dependencies
fabiencastan Sep 2, 2021
8232794
[mesh] minor code style
fabiencastan Sep 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# temporary files
*~
.nfs*
.*.swp # vim
*.flc # xemacs
.DS_Store # MacOS
Expand Down
22 changes: 11 additions & 11 deletions src/aliceVision/fuseCut/DelaunayGraphCut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3271,7 +3271,7 @@ void DelaunayGraphCut::voteFullEmptyScore(const StaticVector<int>& cams, const s
if(false)
{
std::unique_ptr<mesh::Mesh> meshf(createTetrahedralMesh(false, 0.9f, [](const fuseCut::GC_cellInfo& c) { return c.emptinessScore; }));
meshf->saveToObj(folderName + "tetrahedralMesh_beforeForceTEdge_emptiness.obj");
meshf->save(folderName + "tetrahedralMesh_beforeForceTEdge_emptiness");
}

if(forceTEdge)
Expand Down Expand Up @@ -3789,47 +3789,47 @@ void DelaunayGraphCut::exportDebugMesh(const std::string& filename, const Point3
}

const std::string tempDirPath = boost::filesystem::temp_directory_path().generic_string();
mesh->saveToObj(tempDirPath + "/" + filename + ".obj");
meshf->saveToObj(tempDirPath + "/" + filename + "Filtered.obj");
mesh->save(tempDirPath + "/" + filename);
meshf->save(tempDirPath + "/" + filename);
}

void DelaunayGraphCut::exportFullScoreMeshs(const std::string& outputFolder, const std::string& name) const
{
const std::string nameExt = (name.empty() ? "" : "_" + name) + ".obj";
const std::string nameExt = (name.empty() ? "" : "_" + name);
{
std::unique_ptr<mesh::Mesh> meshEmptiness(
createTetrahedralMesh(false, 0.999f, [](const GC_cellInfo& c) { return c.emptinessScore; }));
meshEmptiness->saveToObj(outputFolder + "/mesh_emptiness" + nameExt);
meshEmptiness->save(outputFolder + "/mesh_emptiness" + nameExt);
}
{
std::unique_ptr<mesh::Mesh> meshFullness(
createTetrahedralMesh(false, 0.999f, [](const GC_cellInfo& c) { return c.fullnessScore; }));
meshFullness->saveToObj(outputFolder + "/mesh_fullness" + nameExt);
meshFullness->save(outputFolder + "/mesh_fullness" + nameExt);
}
{
std::unique_ptr<mesh::Mesh> meshSWeight(
createTetrahedralMesh(false, 0.999f, [](const GC_cellInfo& c) { return c.cellSWeight; }));
meshSWeight->saveToObj(outputFolder + "/mesh_sWeight" + nameExt);
meshSWeight->save(outputFolder + "/mesh_sWeight" + nameExt);
}
{
std::unique_ptr<mesh::Mesh> meshTWeight(
createTetrahedralMesh(false, 0.999f, [](const GC_cellInfo& c) { return c.cellTWeight; }));
meshTWeight->saveToObj(outputFolder + "/mesh_tWeight" + nameExt);
meshTWeight->save(outputFolder + "/mesh_tWeight" + nameExt);
}
{
std::unique_ptr<mesh::Mesh> meshOn(
createTetrahedralMesh(false, 0.999f, [](const GC_cellInfo& c) { return c.on; }));
meshOn->saveToObj(outputFolder + "/mesh_on" + nameExt);
meshOn->save(outputFolder + "/mesh_on" + nameExt);
}
{
std::unique_ptr<mesh::Mesh> mesh(createTetrahedralMesh(
false, 0.99f, [](const fuseCut::GC_cellInfo& c) { return c.fullnessScore - c.emptinessScore; }));
mesh->saveToObj(outputFolder + "/mesh_fullness-emptiness" + nameExt);
mesh->save(outputFolder + "/mesh_fullness-emptiness" + nameExt);
}
{
std::unique_ptr<mesh::Mesh> mesh(createTetrahedralMesh(
false, 0.99f, [](const fuseCut::GC_cellInfo& c) { return c.cellSWeight - c.cellTWeight; }));
mesh->saveToObj(outputFolder + "/mesh_s-t" + nameExt);
mesh->save(outputFolder + "/mesh_s-t" + nameExt);
}
}

Expand Down
72 changes: 68 additions & 4 deletions src/aliceVision/mesh/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <geogram/points/kd_tree.h>

#include <boost/filesystem.hpp>
#include <boost/algorithm/string/case_conv.hpp>

#include <assimp/Importer.hpp>
#include <assimp/Exporter.hpp>
Expand All @@ -36,9 +37,56 @@ Mesh::~Mesh()
{
}

void Mesh::saveToObj(const std::string& filename)

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

EFileType EFileType_stringToEnum(const std::string& meshFileType)
{
std::string m = meshFileType;
boost::to_lower(m);

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

std::ostream& operator<<(std::ostream& os, EFileType meshFileType)
{
return os << EFileType_enumToString(meshFileType);
}
std::istream& operator>>(std::istream& in, EFileType& meshFileType)
{
ALICEVISION_LOG_INFO("Writing obj and mtl file.");
std::string token;
in >> token;
meshFileType = EFileType_stringToEnum(token);
return in;
}

void Mesh::save(const std::string& filename, EFileType filetype)
{
const std::string filetypeStr = EFileType_enumToString(filetype);

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

aiScene scene;

Expand Down Expand Up @@ -85,10 +133,26 @@ void Mesh::saveToObj(const std::string& filename)
}
}

std::string formatId;
// If gltf, use gltf 2.0
if (filetypeStr == "gltf")
{
formatId = "gltf2";
}
// If obj, do not use material
else if (filetypeStr == "obj")
{
formatId = "objnomtl";
}
else
{
formatId = filetypeStr;
}

Assimp::Exporter exporter;
exporter.Export(&scene, "objnomtl", filename);
exporter.Export(&scene, formatId, filename);

ALICEVISION_LOG_INFO("Save mesh to obj done.");
ALICEVISION_LOG_INFO("Save mesh to " << filetypeStr << " done.");
}

bool Mesh::loadFromBin(const std::string& binFileName)
Expand Down
18 changes: 17 additions & 1 deletion src/aliceVision/mesh/Mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ ALICEVISION_BITMASK(EVisibilityRemappingMethod);
EVisibilityRemappingMethod EVisibilityRemappingMethod_stringToEnum(const std::string& method);
std::string EVisibilityRemappingMethod_enumToString(EVisibilityRemappingMethod method);

/**
* @brief File type available for exporting mesh
*/
enum class EFileType
{
OBJ = 0,
FBX,
GLTF,
STL
};

EFileType EFileType_stringToEnum(const std::string& filetype);
std::string EFileType_enumToString(const EFileType filetype);
std::istream& operator>>(std::istream& in, EFileType& meshFileType);
std::ostream& operator<<(std::ostream& os, EFileType meshFileType);


class Mesh
{
Expand Down Expand Up @@ -148,7 +164,7 @@ class Mesh
Mesh();
~Mesh();

void saveToObj(const std::string& filename);
void save(const std::string& filename, EFileType filetype = EFileType::GLTF);

bool loadFromBin(const std::string& binFileName);
void saveToBin(const std::string& binFileName);
Expand Down
2 changes: 1 addition & 1 deletion src/aliceVision/mesh/MeshEnergyOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ bool MeshEnergyOpt::optimizeSmooth(float lambda, int niter, StaticVectorBool& pt
ALICEVISION_LOG_INFO("Optimizing mesh smooth: iteration " << i);
updateGradientParallel(lambda, LU, RD, ptsCanMove);
//if(saveDebug)
// saveToObj(folder + "mesh_smoothed_" + std::to_string(i) + ".obj");
// save(folder + "mesh_smoothed_" + std::to_string(i));
}

return true;
Expand Down
Loading