From 2cb30f3641d13ccbc93bcaebd35ac2892e1e606b Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 13 Dec 2019 13:42:10 +0100 Subject: [PATCH] First prototype of CGAL hole-drilling --- src/libslic3r/CMakeLists.txt | 2 ++ src/slic3r/CMakeLists.txt | 2 +- src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp | 30 ++++++++++++++++++++----- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index 2571748fd..922d153e4 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -117,6 +117,8 @@ add_library(libslic3r STATIC "${CMAKE_CURRENT_BINARY_DIR}/libslic3r_version.h" Line.cpp Line.hpp + MeshBoolean.cpp + MeshBoolean.hpp Model.cpp Model.hpp Arrange.hpp diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 859c17e89..eec2b6a01 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -176,7 +176,7 @@ add_library(libslic3r_gui STATIC ${SLIC3R_GUI_SOURCES}) encoding_check(libslic3r_gui) -target_link_libraries(libslic3r_gui libslic3r avrdude cereal imgui GLEW::GLEW OpenGL::GL OpenGL::GLU hidapi) +target_link_libraries(libslic3r_gui libslic3r avrdude cereal imgui GLEW::GLEW OpenGL::GL OpenGL::GLU hidapi CGAL::CGAL) if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY) add_precompiled_header(libslic3r_gui pchheader.hpp FORCEINCLUDE) endif () diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp index 0bbaa19c4..cad0243f0 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp @@ -1,4 +1,3 @@ -// Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro. #include "GLGizmoHollow.hpp" #include "slic3r/GUI/GLCanvas3D.hpp" #include "slic3r/GUI/Gizmos/GLGizmos.hpp" @@ -12,6 +11,8 @@ #include "slic3r/GUI/Plater.hpp" #include "slic3r/GUI/PresetBundle.hpp" #include "libslic3r/SLAPrint.hpp" +#include "libslic3r/TriangleMesh.hpp" +#include "libslic3r/MeshBoolean.hpp" namespace Slic3r { @@ -107,15 +108,15 @@ void GLGizmoHollow::on_render() const if (! m_mesh) const_cast(this)->update_mesh(); + glsafe(::glEnable(GL_BLEND)); + glsafe(::glEnable(GL_DEPTH_TEST)); + if (m_volume_with_cavity) { m_parent.get_shader().start_using(); m_volume_with_cavity->render(); m_parent.get_shader().stop_using(); } - glsafe(::glEnable(GL_BLEND)); - glsafe(::glEnable(GL_DEPTH_TEST)); - m_z_shift = selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z(); if (m_quadric != nullptr && selection.is_from_single_instance()) @@ -583,12 +584,31 @@ void GLGizmoHollow::hollow_mesh() wxGetApp().plater()->hollow(); } + void GLGizmoHollow::update_hollowed_mesh(std::unique_ptr &&mesh) { // Called from Plater when the UI job finishes m_cavity_mesh = std::move(mesh); - if(m_cavity_mesh) {// create a new GLVolume that only has the cavity inside + if(m_cavity_mesh) { + // First subtract the holes: + if (! m_model_object->sla_drain_holes.empty()) { + TriangleMesh holes_mesh; + for (const sla::DrainHole& hole : m_model_object->sla_drain_holes) { + TriangleMesh hole_mesh = make_cylinder(hole.radius, hole.height, 2*M_PI/8); + Eigen::Quaternionf q; + Transform3f m = Transform3f::Identity(); + m.matrix().block(0, 0, 3, 3) = q.setFromTwoVectors(Vec3f::UnitZ(), hole.normal).toRotationMatrix(); + hole_mesh.transform(m.cast()); + hole_mesh.translate(hole.pos); + holes_mesh.merge(hole_mesh); + //MeshBoolean::minus(*m_cavity_mesh.get(), hole_mesh); + } + MeshBoolean::minus(*m_cavity_mesh.get(), holes_mesh); + } + + + // create a new GLVolume that only has the cavity inside Geometry::Transformation volume_trafo = m_model_object->volumes.front()->get_transformation(); volume_trafo.set_offset(volume_trafo.get_offset() + Vec3d(0., 0., m_z_shift)); m_volume_with_cavity.reset(new GLVolume(1.f, 0.f, 0.f, 0.5f));