Fix remesh memory leak and add one more check for combinable mesh [skip ci]
parent
fd17185720
commit
3be82de836
|
@ -28,7 +28,16 @@ MeshCombiner::Mesh::Mesh(const std::vector<QVector3D> &vertices, const std::vect
|
|||
delete cgalMesh;
|
||||
cgalMesh = nullptr;
|
||||
} else {
|
||||
m_isCombinable = true;
|
||||
std::vector<QVector3D> fetchedVertices;
|
||||
std::vector<std::vector<size_t>> fetchedFaces;
|
||||
fetchFromCgalMesh<CgalKernel>(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";
|
||||
|
|
22
src/util.cpp
22
src/util.cpp
|
@ -1,5 +1,6 @@
|
|||
#include <cmath>
|
||||
#include <QtMath>
|
||||
#include <QFile>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#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<QVector3D> &vertices,
|
||||
const std::vector<std::vector<size_t>> &faces)
|
||||
{
|
||||
QFile file(filename);
|
||||
if (!file.open(QIODevice::WriteOnly))
|
||||
return;
|
||||
|
||||
QTextStream stream(&file);
|
||||
|
||||
for (std::vector<QVector3D>::const_iterator it = vertices.begin() ; it != vertices.end(); ++it) {
|
||||
stream << "v " << (*it).x() << " " << (*it).y() << " " << (*it).z() << endl;
|
||||
}
|
||||
for (std::vector<std::vector<size_t>>::const_iterator it = faces.begin() ; it != faces.end(); ++it) {
|
||||
stream << "f";
|
||||
for (std::vector<size_t>::const_iterator subIt = (*it).begin() ; subIt != (*it).end(); ++subIt) {
|
||||
stream << " " << (1 + *subIt);
|
||||
}
|
||||
stream << endl;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,5 +45,7 @@ void trim(std::vector<QVector3D> *vertices, bool normalize=false);
|
|||
void chamferFace2D(std::vector<QVector2D> *face);
|
||||
void subdivideFace2D(std::vector<QVector2D> *face);
|
||||
QVector3D choosenBaseAxis(const QVector3D &layoutDirection);
|
||||
void saveAsObj(const char *filename, const std::vector<QVector3D> &vertices,
|
||||
const std::vector<std::vector<size_t>> &faces);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -312,6 +312,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();
|
||||
*nResultTriangles = g_resultTriangles.size();
|
||||
|
|
Loading…
Reference in New Issue