Drill holes one by one and display warning of any of them fails

Drill with cgal::minus for now
This commit is contained in:
tamasmeszaros 2021-03-08 17:32:40 +01:00
parent d0febbec32
commit 4b9de0398f
5 changed files with 54 additions and 29 deletions

View File

@ -36,6 +36,7 @@ struct DrainHole
Vec3f normal;
float radius;
float height;
bool failed = false;
DrainHole()
: pos(Vec3f::Zero()), normal(Vec3f::UnitZ()), radius(5.f), height(10.f)

View File

@ -244,6 +244,8 @@ static std::vector<bool> create_exclude_mask(
Vec3f face_normal = C.normalized();
for (const sla::DrainHole &dh : holes) {
if (dh.failed) continue;
Vec3d dhpos = dh.pos.cast<double>();
Vec3d dhend = dhpos + dh.normal.cast<double>() * dh.height;
@ -313,25 +315,32 @@ void SLAPrint::Steps::drill_holes(SLAPrintObject &po)
BOOST_LOG_TRIVIAL(info) << "Drilling drainage holes.";
sla::DrainHoles drainholes = po.transformed_drainhole_points();
std::uniform_real_distribution<float> dist(0., float(EPSILON));
auto holes_mesh_cgal = MeshBoolean::cgal::triangle_mesh_to_cgal({});
for (sla::DrainHole holept : drainholes) {
holept.normal += Vec3f{dist(m_rng), dist(m_rng), dist(m_rng)};
holept.normal.normalize();
holept.pos += Vec3f{dist(m_rng), dist(m_rng), dist(m_rng)};
auto hollowed_mesh_cgal = MeshBoolean::cgal::triangle_mesh_to_cgal(hollowed_mesh);
bool hole_fail = false;
for (size_t i = 0; i < drainholes.size(); ++i) {
const sla::DrainHole &holept = drainholes[i];
po.model_object()->sla_drain_holes[i].failed = false;
TriangleMesh m = sla::to_triangle_mesh(holept.to_mesh());
m.require_shared_vertices();
auto cgal_m = MeshBoolean::cgal::triangle_mesh_to_cgal(m);
MeshBoolean::cgal::plus(*holes_mesh_cgal, *cgal_m);
}
if (MeshBoolean::cgal::does_self_intersect(*holes_mesh_cgal))
throw Slic3r::SlicingError(L("Too many overlapping holes."));
auto hollowed_mesh_cgal = MeshBoolean::cgal::triangle_mesh_to_cgal(hollowed_mesh);
try {
MeshBoolean::cgal::minus(*hollowed_mesh_cgal, *holes_mesh_cgal);
MeshBoolean::cgal::minus(*hollowed_mesh_cgal, *cgal_m);
} catch (const std::runtime_error &) {
BOOST_LOG_TRIVIAL(error) << "Failed to drill hole";
hole_fail = drainholes[i].failed =
po.model_object()->sla_drain_holes[i].failed = true;
}
}
if (hole_fail)
po.active_step_add_warning(PrintStateBase::WarningLevel::NON_CRITICAL,
L("Failed to drill some holes into the model"));
hollowed_mesh = MeshBoolean::cgal::cgal_to_triangle_mesh(*hollowed_mesh_cgal);
mesh_view = hollowed_mesh;
@ -342,12 +351,6 @@ void SLAPrint::Steps::drill_holes(SLAPrintObject &po)
sla::remove_inside_triangles(mesh_view, interior, exclude_mask);
}
} catch (const std::runtime_error &) {
throw Slic3r::SlicingError(L(
"Drilling holes into the mesh failed. "
"This is usually caused by broken model. Try to fix it first."));
}
}
// The slicing will be performed on an imaginary 1D grid which starts from

View File

@ -125,6 +125,8 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking) cons
float render_color[4];
const sla::DrainHoles& drain_holes = m_c->selection_info()->model_object()->sla_drain_holes;
size_t cache_size = drain_holes.size();
const auto *hollowed_mesh = m_c->hollowed_mesh();
for (size_t i = 0; i < cache_size; ++i)
{
const sla::DrainHole& drain_hole = drain_holes[i];
@ -136,6 +138,13 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking) cons
// First decide about the color of the point.
if (picking) {
std::array<float, 4> color = picking_color_component(i);
if (hollowed_mesh && i < hollowed_mesh->get_drainholes().size() && hollowed_mesh->get_drainholes()[i].failed) {
render_color[0] = 1.f;
render_color[1] = 1.f;
render_color[2] = 0.f;
render_color[3] = color[3];
}
render_color[0] = color[0];
render_color[1] = color[1];
render_color[2] = color[2];
@ -149,9 +158,15 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking) cons
render_color[2] = 1.0f;
}
else { // neigher hover nor picking
if (hollowed_mesh && i < hollowed_mesh->get_drainholes().size() && hollowed_mesh->get_drainholes()[i].failed) {
render_color[0] = 1.f;
render_color[1] = 1.f;
render_color[2] = 0.f;
} else {
render_color[0] = point_selected ? 1.0f : 0.7f;
render_color[1] = point_selected ? 0.3f : 0.7f;
render_color[2] = point_selected ? 0.3f : 0.7f;
}
render_color[3] = 0.5f;
}
}

View File

@ -205,6 +205,7 @@ void HollowedMesh::on_update()
m_hollowed_mesh_transformed.reset(new TriangleMesh(backend_mesh));
Transform3d trafo_inv = canvas->sla_print()->sla_trafo(*mo).inverse();
m_hollowed_mesh_transformed->transform(trafo_inv);
m_drainholes = print_object->model_object()->sla_drain_holes;
m_old_hollowing_timestamp = timestamp;
const TriangleMesh &interior = print_object->hollowed_interior_mesh();
@ -215,10 +216,11 @@ void HollowedMesh::on_update()
m_hollowed_interior_transformed->transform(trafo_inv);
}
}
else
else {
m_hollowed_mesh_transformed.reset(nullptr);
}
}
}
else
m_hollowed_mesh_transformed.reset(nullptr);
}

View File

@ -5,6 +5,7 @@
#include <map>
#include "slic3r/GUI/MeshUtils.hpp"
#include "libslic3r/SLA/Hollowing.hpp"
namespace Slic3r {
@ -198,6 +199,8 @@ public:
CommonGizmosDataID get_dependencies() const override { return CommonGizmosDataID::SelectionInfo; }
#endif // NDEBUG
const sla::DrainHoles &get_drainholes() const { return m_drainholes; }
const TriangleMesh* get_hollowed_mesh() const;
const TriangleMesh* get_hollowed_interior() const;
@ -211,6 +214,7 @@ private:
size_t m_old_hollowing_timestamp = 0;
int m_print_object_idx = -1;
int m_print_objects_count = 0;
sla::DrainHoles m_drainholes;
};