From 7713a55d458a92468dac2d9c9e4802cf72644150 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Thu, 10 Sep 2020 13:39:43 +0200 Subject: [PATCH] Do a mesh split before openvdb conversion, unify each part's grid Do a mesh redistance after the part splitting and openvdb csgUnion --- src/libslic3r/OpenVDBUtils.cpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/libslic3r/OpenVDBUtils.cpp b/src/libslic3r/OpenVDBUtils.cpp index c30052036..53a71f194 100644 --- a/src/libslic3r/OpenVDBUtils.cpp +++ b/src/libslic3r/OpenVDBUtils.cpp @@ -2,6 +2,7 @@ #include "OpenVDBUtils.hpp" #include #include +#include #include //#include "MTUtils.hpp" @@ -57,17 +58,42 @@ void Contour3DDataAdapter::getIndexSpacePoint(size_t n, // TODO: Do I need to call initialize? Seems to work without it as well but the // docs say it should be called ones. It does a mutex lock-unlock sequence all // even if was called previously. - openvdb::FloatGrid::Ptr mesh_to_grid(const TriangleMesh &mesh, const openvdb::math::Transform &tr, float exteriorBandWidth, float interiorBandWidth, int flags) { +// openvdb::initialize(); +// return openvdb::tools::meshToVolume( +// TriangleMeshDataAdapter{mesh}, tr, exteriorBandWidth, +// interiorBandWidth, flags); + openvdb::initialize(); - return openvdb::tools::meshToVolume( - TriangleMeshDataAdapter{mesh}, tr, exteriorBandWidth, - interiorBandWidth, flags); + + TriangleMeshPtrs meshparts = mesh.split(); + + auto it = std::remove_if(meshparts.begin(), meshparts.end(), + [](TriangleMesh *m){ + m->require_shared_vertices(); + return !m->is_manifold() || m->volume() < EPSILON; + }); + + meshparts.erase(it, meshparts.end()); + + openvdb::FloatGrid::Ptr grid; + for (TriangleMesh *m : meshparts) { + auto gridptr = openvdb::tools::meshToVolume( + TriangleMeshDataAdapter{*m}, tr, exteriorBandWidth, + interiorBandWidth, flags); + + if (grid && gridptr) openvdb::tools::csgUnion(*grid, *gridptr); + else if (gridptr) grid = std::move(gridptr); + } + + grid = openvdb::tools::levelSetRebuild(*grid, 0., exteriorBandWidth, interiorBandWidth); + + return grid; } openvdb::FloatGrid::Ptr mesh_to_grid(const sla::Contour3D &mesh,