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 <nodemesh/cgalmesh.h>
#include <CGAL/Polygon_mesh_processing/corefinement.h> #include <CGAL/Polygon_mesh_processing/corefinement.h>
#include <CGAL/Polygon_mesh_processing/repair.h> #include <CGAL/Polygon_mesh_processing/repair.h>
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
#include <QDebug> #include <QDebug>
#include <map> #include <map>
@ -17,28 +18,34 @@ Combiner::Mesh::Mesh(const std::vector<QVector3D> &vertices, const std::vector<s
{ {
ExactMesh *cgalMesh = nullptr; ExactMesh *cgalMesh = nullptr;
if (!faces.empty()) { if (!faces.empty()) {
std::vector<std::vector<size_t>> triangles; cgalMesh = buildCgalMesh<ExactKernel>(vertices, faces);
triangulate(vertices, faces, triangles);
cgalMesh = buildCgalMesh<ExactKernel>(vertices, triangles);
if (!CGAL::is_valid_polygon_mesh(*cgalMesh)) { if (!CGAL::is_valid_polygon_mesh(*cgalMesh)) {
//qDebug() << "Mesh is not valid polygon"; qDebug() << "Mesh is not valid polygon";
delete cgalMesh; delete cgalMesh;
cgalMesh = nullptr; cgalMesh = nullptr;
} else if (CGAL::Polygon_mesh_processing::does_self_intersect(*cgalMesh)) { } else {
//nodemesh::exportMeshAsObj(vertices, triangles, "/Users/jeremy/Desktop/test.obj"); if (CGAL::Polygon_mesh_processing::triangulate_faces(*cgalMesh)) {
m_isSelfIntersected = true; if (CGAL::Polygon_mesh_processing::does_self_intersect(*cgalMesh)) {
if (removeSelfIntersects) { //nodemesh::exportMeshAsObj(vertices, triangles, "/Users/jeremy/Desktop/test.obj");
if (!CGAL::Polygon_mesh_processing::remove_self_intersections(*cgalMesh)) { m_isSelfIntersected = true;
//qDebug() << "Mesh does self intersect and cann't remove intersections"; if (removeSelfIntersects) {
delete cgalMesh; if (!CGAL::Polygon_mesh_processing::remove_self_intersections(*cgalMesh)) {
cgalMesh = nullptr; //qDebug() << "Mesh does self intersect and cann't remove intersections";
} else { delete cgalMesh;
//qDebug() << "Mesh does self intersect but intersections got removed"; cgalMesh = nullptr;
} else {
//qDebug() << "Mesh does self intersect but intersections got removed";
}
} else {
delete cgalMesh;
cgalMesh = nullptr;
//qDebug() << "Mesh does self intersect";
}
} }
} else { } else {
qDebug() << "Mesh triangulate failed";
delete cgalMesh; delete cgalMesh;
cgalMesh = nullptr; cgalMesh = nullptr;
//qDebug() << "Mesh does self intersect";
} }
} }
} }

View File

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