Use CGAL triangulation

Replace triangulation algorithm with CGAL triangulate_faces, the quality of generated mesh improved a lot.
This commit also reduced max uv packer times.
master
Jeremy Hu 2019-03-07 22:43:41 +09:30
parent fe3ad48fb1
commit 499c3f439a
2 changed files with 23 additions and 16 deletions

View File

@ -4,6 +4,7 @@
#include <nodemesh/cgalmesh.h>
#include <CGAL/Polygon_mesh_processing/corefinement.h>
#include <CGAL/Polygon_mesh_processing/repair.h>
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
#include <QDebug>
#include <map>
@ -17,14 +18,14 @@ Combiner::Mesh::Mesh(const std::vector<QVector3D> &vertices, const std::vector<s
{
ExactMesh *cgalMesh = nullptr;
if (!faces.empty()) {
std::vector<std::vector<size_t>> triangles;
triangulate(vertices, faces, triangles);
cgalMesh = buildCgalMesh<ExactKernel>(vertices, triangles);
cgalMesh = buildCgalMesh<ExactKernel>(vertices, faces);
if (!CGAL::is_valid_polygon_mesh(*cgalMesh)) {
//qDebug() << "Mesh is not valid polygon";
qDebug() << "Mesh is not valid polygon";
delete cgalMesh;
cgalMesh = nullptr;
} else if (CGAL::Polygon_mesh_processing::does_self_intersect(*cgalMesh)) {
} else {
if (CGAL::Polygon_mesh_processing::triangulate_faces(*cgalMesh)) {
if (CGAL::Polygon_mesh_processing::does_self_intersect(*cgalMesh)) {
//nodemesh::exportMeshAsObj(vertices, triangles, "/Users/jeremy/Desktop/test.obj");
m_isSelfIntersected = true;
if (removeSelfIntersects) {
@ -41,6 +42,12 @@ Combiner::Mesh::Mesh(const std::vector<QVector3D> &vertices, const std::vector<s
//qDebug() << "Mesh does self intersect";
}
}
} else {
qDebug() << "Mesh triangulate failed";
delete cgalMesh;
cgalMesh = nullptr;
}
}
}
m_privateData = cgalMesh;
}

View File

@ -24,7 +24,7 @@ private:
float m_floatToIntFactor = 10000;
size_t m_tryNum = 0;
float m_textureSizeFactor = 1.0;
size_t m_maxTryNum = 10000;
size_t m_maxTryNum = 100;
};
}