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,28 +18,34 @@ 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)) {
//nodemesh::exportMeshAsObj(vertices, triangles, "/Users/jeremy/Desktop/test.obj");
m_isSelfIntersected = true;
if (removeSelfIntersects) {
if (!CGAL::Polygon_mesh_processing::remove_self_intersections(*cgalMesh)) {
//qDebug() << "Mesh does self intersect and cann't remove intersections";
delete cgalMesh;
cgalMesh = nullptr;
} else {
//qDebug() << "Mesh does self intersect but intersections got removed";
} 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) {
if (!CGAL::Polygon_mesh_processing::remove_self_intersections(*cgalMesh)) {
//qDebug() << "Mesh does self intersect and cann't remove intersections";
delete cgalMesh;
cgalMesh = nullptr;
} else {
//qDebug() << "Mesh does self intersect but intersections got removed";
}
} else {
delete cgalMesh;
cgalMesh = nullptr;
//qDebug() << "Mesh does self intersect";
}
}
} else {
qDebug() << "Mesh triangulate failed";
delete cgalMesh;
cgalMesh = nullptr;
//qDebug() << "Mesh does self intersect";
}
}
}

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;
};
}