Export negative parts (#7024)

Porting from Prusa exporting negative parts.

Before:

![image](https://github.com/user-attachments/assets/a5e041ce-7f0f-44e5-95ea-0a8b11252cc4)

After:

![image](https://github.com/user-attachments/assets/f0a6f6bb-13c7-4a6e-afb3-7631e2f4f634)
This commit is contained in:
SoftFever 2024-10-07 16:42:12 +08:00 committed by GitHub
commit 17c0abbe32
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 78 additions and 21 deletions

View file

@ -11686,14 +11686,37 @@ void Plater::export_stl(bool extended, bool selection_only, bool multi_stls)
}
// Following lambda generates a combined mesh for export with normals pointing outwards.
auto mesh_to_export_fff_no_boolean = [](const ModelObject &mo, int instance_id) {
auto mesh_to_export_fff_no_boolean = [this](const ModelObject &mo, int instance_id) {
TriangleMesh mesh;
for (const ModelVolume *v : mo.volumes)
if (v->is_model_part()) {
TriangleMesh vol_mesh(v->mesh());
vol_mesh.transform(v->get_matrix(), true);
mesh.merge(vol_mesh);
}
//Prusa export negative parts
std::vector<csg::CSGPart> csgmesh;
csgmesh.reserve(2 * mo.volumes.size());
csg::model_to_csgmesh(mo, Transform3d::Identity(), std::back_inserter(csgmesh),
csg::mpartsPositive | csg::mpartsNegative | csg::mpartsDoSplits);
auto csgrange = range(csgmesh);
if (csg::is_all_positive(csgrange)) {
mesh = TriangleMesh{csg::csgmesh_merge_positive_parts(csgrange)};
} else if (std::get<2>(csg::check_csgmesh_booleans(csgrange)) == csgrange.end()) {
try {
auto cgalm = csg::perform_csgmesh_booleans(csgrange);
mesh = MeshBoolean::cgal::cgal_to_triangle_mesh(*cgalm);
} catch (...) {}
}
if (mesh.empty()) {
get_notification_manager()->push_plater_error_notification(
_u8L("Unable to perform boolean operation on model meshes. "
"Only positive parts will be exported."));
for (const ModelVolume* v : mo.volumes)
if (v->is_model_part()) {
TriangleMesh vol_mesh(v->mesh());
vol_mesh.transform(v->get_matrix(), true);
mesh.merge(vol_mesh);
}
}
if (instance_id == -1) {
TriangleMesh vols_mesh(mesh);
mesh = TriangleMesh();