Split object : Check if new objects don't have a zero volume

Related to :
 * #8931 - Split to objects crashes Prusa Slicer
 * SPE-1221(https://dev.prusa3d.com/browse/SPE-1221) - Split to objects fail
This commit is contained in:
YuSanka 2022-09-23 16:37:33 +02:00
parent 70be93d112
commit 7a1c118924
3 changed files with 11 additions and 2 deletions

View File

@ -1359,7 +1359,7 @@ void ModelObject::split(ModelObjectPtrs* new_objects)
size_t counter = 1; size_t counter = 1;
for (TriangleMesh &mesh : meshes) { for (TriangleMesh &mesh : meshes) {
// FIXME: crashes if not satisfied // FIXME: crashes if not satisfied
if (mesh.facets_count() < 3) if (mesh.facets_count() < 3 || mesh.has_zero_volume())
continue; continue;
// XXX: this seems to be the only real usage of m_model, maybe refactor this so that it's not needed? // XXX: this seems to be the only real usage of m_model, maybe refactor this so that it's not needed?
@ -1833,7 +1833,7 @@ size_t ModelVolume::split(unsigned int max_extruders)
const Vec3d offset = this->get_offset(); const Vec3d offset = this->get_offset();
for (TriangleMesh &mesh : meshes) { for (TriangleMesh &mesh : meshes) {
if (mesh.empty()) if (mesh.empty() || mesh.has_zero_volume())
// Repair may have removed unconnected triangles, thus emptying the mesh. // Repair may have removed unconnected triangles, thus emptying the mesh.
continue; continue;

View File

@ -378,6 +378,14 @@ bool TriangleMesh::is_splittable() const
return its_is_splittable(this->its); return its_is_splittable(this->its);
} }
bool TriangleMesh::has_zero_volume() const
{
const Vec3d sz = size();
const double volume_val = sz.x() * sz.y() * sz.z();
return is_approx(volume_val, 0.0);
}
std::vector<TriangleMesh> TriangleMesh::split() const std::vector<TriangleMesh> TriangleMesh::split() const
{ {
std::vector<indexed_triangle_set> itss = its_split(this->its); std::vector<indexed_triangle_set> itss = its_split(this->its);

View File

@ -139,6 +139,7 @@ public:
bool empty() const { return this->facets_count() == 0; } bool empty() const { return this->facets_count() == 0; }
bool repaired() const; bool repaired() const;
bool is_splittable() const; bool is_splittable() const;
bool has_zero_volume() const;
// Estimate of the memory occupied by this structure, important for keeping an eye on the Undo / Redo stack allocation. // Estimate of the memory occupied by this structure, important for keeping an eye on the Undo / Redo stack allocation.
size_t memsize() const; size_t memsize() const;