diff --git a/src/meshcombiner.cpp b/src/meshcombiner.cpp index 970f8b0a..b33b12e2 100644 --- a/src/meshcombiner.cpp +++ b/src/meshcombiner.cpp @@ -28,7 +28,16 @@ MeshCombiner::Mesh::Mesh(const std::vector &vertices, const std::vect delete cgalMesh; cgalMesh = nullptr; } else { - m_isCombinable = true; + std::vector fetchedVertices; + std::vector> fetchedFaces; + fetchFromCgalMesh(cgalMesh, fetchedVertices, fetchedFaces); + if (!isManifold(fetchedFaces)) { + qDebug() << "Mesh does not self intersect but is not manifold"; + delete cgalMesh; + cgalMesh = nullptr; + } else { + m_isCombinable = true; + } } } else { qDebug() << "Mesh triangulate failed"; diff --git a/src/util.cpp b/src/util.cpp index 031295c1..7e0b9e0a 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include "util.h" @@ -488,3 +489,24 @@ QVector3D choosenBaseAxis(const QVector3D &layoutDirection) return first.first < second.first; })->second]; } + +void saveAsObj(const char *filename, const std::vector &vertices, + const std::vector> &faces) +{ + QFile file(filename); + if (!file.open(QIODevice::WriteOnly)) + return; + + QTextStream stream(&file); + + for (std::vector::const_iterator it = vertices.begin() ; it != vertices.end(); ++it) { + stream << "v " << (*it).x() << " " << (*it).y() << " " << (*it).z() << endl; + } + for (std::vector>::const_iterator it = faces.begin() ; it != faces.end(); ++it) { + stream << "f"; + for (std::vector::const_iterator subIt = (*it).begin() ; subIt != (*it).end(); ++subIt) { + stream << " " << (1 + *subIt); + } + stream << endl; + } +} diff --git a/src/util.h b/src/util.h index 4ea6ac5b..2b3f0fa3 100644 --- a/src/util.h +++ b/src/util.h @@ -45,5 +45,7 @@ void trim(std::vector *vertices, bool normalize=false); void chamferFace2D(std::vector *face); void subdivideFace2D(std::vector *face); QVector3D choosenBaseAxis(const QVector3D &layoutDirection); +void saveAsObj(const char *filename, const std::vector &vertices, + const std::vector> &faces); #endif diff --git a/thirdparty/instant-meshes/instant-meshes-api.cpp b/thirdparty/instant-meshes/instant-meshes-api.cpp index d78a2d57..b67ed3c3 100644 --- a/thirdparty/instant-meshes/instant-meshes-api.cpp +++ b/thirdparty/instant-meshes/instant-meshes-api.cpp @@ -311,6 +311,9 @@ void DUST3D_INSTANT_MESHES_FUNCTION_CONVENTION Dust3D_instantMeshesRemesh(const } }; outputMesh(O_extr, F_extr); + + if (bvh) + delete bvh; *nResultVertices = g_resultVertices.size(); *resultVertices = g_resultVertices.data();