mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-06-23 04:01:49 +00:00
ENH: improve mesh boolean
1. Don't use mcut on splitable volumes 2. If MCut fails, try again with CGAL. Change-Id: I55d352b166633db9e4548b5c9e6913cf931f5f8f (cherry picked from commit c1bde5358524d2291db6efa584ff072308ed9d20)
This commit is contained in:
@@ -9945,7 +9945,6 @@ void Plater::export_core_3mf()
|
||||
export_3mf(path_u8, SaveStrategy::Silence);
|
||||
}
|
||||
|
||||
#define USE_CGAL_BOOLEAN 0
|
||||
// Following lambda generates a combined mesh for export with normals pointing outwards.
|
||||
TriangleMesh Plater::combine_mesh_fff(const ModelObject& mo, int instance_id, std::function<void(const std::string&)> notify_func)
|
||||
{
|
||||
@@ -9953,20 +9952,28 @@ TriangleMesh Plater::combine_mesh_fff(const ModelObject& mo, int instance_id, st
|
||||
|
||||
std::vector<csg::CSGPart> csgmesh;
|
||||
csgmesh.reserve(2 * mo.volumes.size());
|
||||
csg::model_to_csgmesh(mo, Transform3d::Identity(), std::back_inserter(csgmesh),
|
||||
bool has_splitable_volume = csg::model_to_csgmesh(mo, Transform3d::Identity(), std::back_inserter(csgmesh),
|
||||
csg::mpartsPositive | csg::mpartsNegative | csg::mpartsDoSplits);
|
||||
|
||||
if (csg::check_csgmesh_booleans(Range{ std::begin(csgmesh), std::end(csgmesh) }) == csgmesh.end()) {
|
||||
if (csg::check_csgmesh_booleans(Range{ std::begin(csgmesh), std::end(csgmesh) }) == csgmesh.end()) {
|
||||
try {
|
||||
// mcut can't handle splitable positive volumes
|
||||
if (!has_splitable_volume) {
|
||||
MeshBoolean::mcut::McutMeshPtr meshPtr = csg::perform_csgmesh_booleans_mcut(Range{ std::begin(csgmesh), std::end(csgmesh) });
|
||||
mesh = MeshBoolean::mcut::mcut_to_triangle_mesh(*meshPtr);
|
||||
}
|
||||
}
|
||||
catch (...) {}
|
||||
|
||||
// if mcut fails, try again with CGAL
|
||||
if (mesh.empty()) {
|
||||
try {
|
||||
#if USE_CGAL_BOOLEAN
|
||||
auto meshPtr = csg::perform_csgmesh_booleans(Range{ std::begin(csgmesh), std::end(csgmesh) });
|
||||
mesh = MeshBoolean::cgal::cgal_to_triangle_mesh(*meshPtr);
|
||||
#else
|
||||
MeshBoolean::mcut::McutMeshPtr meshPtr = csg::perform_csgmesh_booleans_mcut(Range{std::begin(csgmesh), std::end(csgmesh)});
|
||||
mesh = MeshBoolean::mcut::mcut_to_triangle_mesh(*meshPtr);
|
||||
#endif
|
||||
} catch (...) {}
|
||||
}
|
||||
catch (...) {}
|
||||
}
|
||||
}
|
||||
|
||||
if (mesh.empty()) {
|
||||
if (notify_func)
|
||||
|
||||
Reference in New Issue
Block a user