Merge branch 'tm_openvdb_integration' into lm_tm_hollowing

This commit is contained in:
tamasmeszaros 2019-11-11 16:19:03 +01:00
commit 98e2327a9f
4 changed files with 70 additions and 31 deletions

View File

@ -216,10 +216,6 @@ add_library(libslic3r STATIC
encoding_check(libslic3r)
if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY)
add_precompiled_header(libslic3r pchheader.hpp FORCEINCLUDE)
endif ()
target_compile_definitions(libslic3r PUBLIC -DUSE_TBB -DTBB_USE_CAPTURED_EXCEPTION=0)
target_include_directories(libslic3r PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${LIBNEST2D_INCLUDES} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(libslic3r
@ -252,3 +248,7 @@ endif()
if(SLIC3R_PROFILE)
target_link_libraries(slic3r Shiny)
endif()
if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY)
add_precompiled_header(libslic3r pchheader.hpp FORCEINCLUDE)
endif ()

View File

@ -571,30 +571,35 @@ std::pair<const TriangleMesh *, sla::HollowingConfig> GLGizmoHollow::get_hollowi
return std::make_pair(m_mesh, sla::HollowingConfig{double(m_offset), double(m_accuracy), double(m_closing_d)});
}
void GLGizmoHollow::set_hollowing_result(std::unique_ptr<TriangleMesh> mesh)
{
// Called from Plater when the UI job finishes
m_cavity_mesh = std::move(mesh);
m_mesh_raycaster.reset(new MeshRaycaster(*m_cavity_mesh.get()));
m_object_clipper.reset();
m_volume_with_cavity.reset();
if(m_cavity_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));
m_volume_with_cavity->indexed_vertex_array.load_mesh(*m_cavity_mesh.get());
m_volume_with_cavity->set_volume_transformation(volume_trafo);
m_volume_with_cavity->set_instance_transformation(m_model_object->instances[size_t(m_active_instance)]->get_transformation());
}
}
void GLGizmoHollow::hollow_mesh()
{
// Trigger a UI job to hollow the mesh.
wxGetApp().plater()->hollow();
}
void GLGizmoHollow::update_hollowed_mesh(std::unique_ptr<TriangleMesh> mesh)
void GLGizmoHollow::update_hollowed_mesh()
{
// Called from Plater when the UI job finishes
m_cavity_mesh = std::move(mesh);
m_mesh_raycaster.reset(new MeshRaycaster(*m_cavity_mesh.get()));
m_object_clipper.reset();
m_volume_with_cavity.reset();
if(m_cavity_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));
m_volume_with_cavity->indexed_vertex_array.load_mesh(*m_cavity_mesh.get());
m_volume_with_cavity->finalize_geometry(true);
m_volume_with_cavity->set_volume_transformation(volume_trafo);
m_volume_with_cavity->set_instance_transformation(m_model_object->instances[m_active_instance]->get_transformation());
}
if (m_volume_with_cavity) m_volume_with_cavity->finalize_geometry(true);
m_parent.toggle_model_objects_visibility(! m_cavity_mesh, m_model_object, m_active_instance);
}

View File

@ -76,8 +76,11 @@ public:
bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down);
void delete_selected_points(bool force = false);
ClippingPlane get_sla_clipping_plane() const;
void update_hollowed_mesh(std::unique_ptr<TriangleMesh> mesh);
std::pair<const TriangleMesh *, sla::HollowingConfig> get_hollowing_parameters() const;
void set_hollowing_result(std::unique_ptr<TriangleMesh> mesh);
void update_hollowed_mesh();
bool is_selection_rectangle_dragging() const { return m_selection_rectangle.is_dragging(); }

View File

@ -1714,6 +1714,9 @@ struct Plater::priv
void process() override;
void finalize() override;
private:
GLGizmoHollow * get_gizmo();
const GLGizmoHollow * get_gizmo() const;
std::unique_ptr<TriangleMesh> m_output;
const TriangleMesh* m_object_mesh = nullptr;
sla::HollowingConfig m_cfg;
@ -2873,22 +2876,50 @@ void Plater::priv::HollowJob::prepare()
void Plater::priv::HollowJob::process()
{
sla::JobController ctl;
ctl.stopcondition = [this]{ return was_canceled(); };
ctl.statuscb = [this](unsigned st, const std::string &s) {
if (st < 100) update_status(int(st), s);
};
TriangleMesh omesh = sla::generate_interior(*m_object_mesh, m_cfg, ctl);
if (omesh.empty()) return;
m_output.reset(new TriangleMesh{*m_object_mesh});
m_output->merge(omesh);
m_output->require_shared_vertices();
if (!omesh.empty()) {
m_output.reset(new TriangleMesh{*m_object_mesh});
m_output->merge(omesh);
m_output->require_shared_vertices();
update_status(90, "Rendering hollowed object");
auto gizmo = get_gizmo();
if (gizmo) gizmo->set_hollowing_result(std::move(m_output));
update_status(100, was_canceled() ? _(L("Hollowing cancelled.")) :
_(L("Hollowing done.")));
} else {
update_status(100, _(L("Hollowing failed.")));
}
}
void Plater::priv::HollowJob::finalize()
{
auto gizmo = get_gizmo();
if (gizmo) gizmo->update_hollowed_mesh();
}
GLGizmoHollow *Plater::priv::HollowJob::get_gizmo()
{
const GLGizmosManager& gizmo_manager = plater().q->canvas3D()->get_gizmos_manager();
GLGizmoHollow* gizmo_hollow = dynamic_cast<GLGizmoHollow*>(gizmo_manager.get_current());
assert(gizmo_hollow);
gizmo_hollow->update_hollowed_mesh(std::move(m_output));
auto ret = dynamic_cast<GLGizmoHollow*>(gizmo_manager.get_current());
assert(ret);
return ret;
}
const GLGizmoHollow *Plater::priv::HollowJob::get_gizmo() const
{
const GLGizmosManager& gizmo_manager = plater().q->canvas3D()->get_gizmos_manager();
auto ret = dynamic_cast<const GLGizmoHollow*>(gizmo_manager.get_current());
assert(ret);
return ret;
}
void Plater::priv::split_object()
@ -2896,7 +2927,7 @@ void Plater::priv::split_object()
int obj_idx = get_selected_object_idx();
if (obj_idx == -1)
return;
// we clone model object because split_object() adds the split volumes
// into the same model object, thus causing duplicates when we call load_model_objects()
Model new_model = model;