WIP: prepare frontend to use new sla backend interface

This commit is contained in:
tamasmeszaros 2022-10-18 18:29:00 +02:00
parent ab9f231c0c
commit 39a1ed0e1a
3 changed files with 97 additions and 95 deletions

View File

@ -1000,72 +1000,74 @@ const ExPolygons &SliceRecord::get_slice(SliceOrigin o) const
return idx >= v.size() ? EMPTY_SLICE : v[idx]; return idx >= v.size() ? EMPTY_SLICE : v[idx];
} }
bool SLAPrintObject::has_mesh(SLAPrintObjectStep step) const //bool SLAPrintObject::has_mesh(SLAPrintObjectStep step) const
{ //{
switch (step) { // switch (step) {
case slaposAssembly: // case slaposAssembly:
return true; // return true;
case slaposObjectSlice: // case slaposObjectSlice:
return ! this->m_mesh_from_slices.empty(); // return ! this->m_mesh_from_slices.empty();
case slaposDrillHoles: // case slaposDrillHoles:
return ! this->m_mesh_from_slices.empty(); // return ! this->m_mesh_from_slices.empty();
case slaposSupportTree: // case slaposSupportTree:
return ! this->support_mesh().empty(); // return ! this->support_mesh().empty();
case slaposPad: // case slaposPad:
return ! this->pad_mesh().empty(); // return ! this->pad_mesh().empty();
default: // default:
return false; // return false;
} // }
} //}
TriangleMesh SLAPrintObject::get_mesh(SLAPrintObjectStep step) const //TriangleMesh SLAPrintObject::get_mesh(SLAPrintObjectStep step) const
{ //{
switch (step) { // switch (step) {
case slaposAssembly: // case slaposAssembly:
return m_transformed_rmesh; // return m_transformed_rmesh;
case slaposObjectSlice: // case slaposObjectSlice:
return this->m_mesh_from_slices; // return this->m_mesh_from_slices;
case slaposSupportTree: // case slaposSupportTree:
return this->support_mesh(); // return this->support_mesh();
case slaposPad: // case slaposPad:
return this->pad_mesh(); // return this->pad_mesh();
case slaposDrillHoles: // case slaposDrillHoles:
// if (m_hollowing_data) //// if (m_hollowing_data)
return get_mesh_to_print(); // return get_mesh_to_print();
[[fallthrough]]; // [[fallthrough]];
default: // default:
return TriangleMesh(); // return TriangleMesh();
} // }
} //}
const TriangleMesh& SLAPrintObject::support_mesh() const const TriangleMesh& SLAPrintObject::support_mesh() const
{ {
if(m_config.supports_enable.getBool() && m_supportdata) if (m_config.supports_enable.getBool() &&
is_step_done(slaposSupportTree) &&
m_supportdata)
return m_supportdata->tree_mesh; return m_supportdata->tree_mesh;
return EMPTY_MESH; return EMPTY_MESH;
} }
const TriangleMesh& SLAPrintObject::pad_mesh() const const TriangleMesh& SLAPrintObject::pad_mesh() const
{ {
if(m_config.pad_enable.getBool() && m_supportdata) if(m_config.pad_enable.getBool() && is_step_done(slaposPad) && m_supportdata)
return m_supportdata->pad_mesh; return m_supportdata->pad_mesh;
return EMPTY_MESH; return EMPTY_MESH;
} }
const indexed_triangle_set &SLAPrintObject::hollowed_interior_mesh() const //const indexed_triangle_set &SLAPrintObject::hollowed_interior_mesh() const
{ //{
if (m_hollowing_data && m_hollowing_data->interior && // if (m_hollowing_data && m_hollowing_data->interior &&
m_config.hollowing_enable.getBool()) // m_config.hollowing_enable.getBool())
return sla::get_mesh(*m_hollowing_data->interior); // return sla::get_mesh(*m_hollowing_data->interior);
return EMPTY_TRIANGLE_SET; // return EMPTY_TRIANGLE_SET;
} //}
const TriangleMesh &SLAPrintObject::transformed_mesh() const { //const TriangleMesh &SLAPrintObject::transformed_mesh() const {
return m_transformed_rmesh; // return m_transformed_rmesh;
} //}
sla::SupportPoints SLAPrintObject::transformed_support_points() const sla::SupportPoints SLAPrintObject::transformed_support_points() const
{ {

View File

@ -119,8 +119,8 @@ public:
}; };
const std::vector<Instance>& instances() const { return m_instances; } const std::vector<Instance>& instances() const { return m_instances; }
bool has_mesh(SLAPrintObjectStep step) const; // bool has_mesh(SLAPrintObjectStep step) const;
TriangleMesh get_mesh(SLAPrintObjectStep step) const; // TriangleMesh get_mesh(SLAPrintObjectStep step) const;
// Get a support mesh centered around origin in XY, and with zero rotation around Z applied. // Get a support mesh centered around origin in XY, and with zero rotation around Z applied.
// Support mesh is only valid if this->is_step_done(slaposSupportTree) is true. // Support mesh is only valid if this->is_step_done(slaposSupportTree) is true.
@ -129,17 +129,17 @@ public:
// Support mesh is only valid if this->is_step_done(slaposPad) is true. // Support mesh is only valid if this->is_step_done(slaposPad) is true.
const TriangleMesh& pad_mesh() const; const TriangleMesh& pad_mesh() const;
// Ready after this->is_step_done(slaposDrillHoles) is true // // Ready after this->is_step_done(slaposDrillHoles) is true
const indexed_triangle_set &hollowed_interior_mesh() const; // const indexed_triangle_set &hollowed_interior_mesh() const;
// Get the mesh that is going to be printed with all the modifications // Get the mesh that is going to be printed with all the modifications
// like hollowing and drilled holes. // like hollowing and drilled holes.
const TriangleMesh & get_mesh_to_print() const { const TriangleMesh & get_mesh_to_print() const {
return !m_mesh_from_slices.empty() ? m_mesh_from_slices : transformed_mesh(); return !m_mesh_from_slices.empty() ? m_mesh_from_slices : m_transformed_rmesh;
} }
// This will return the transformed mesh which is cached // // This will return the transformed mesh which is cached
const TriangleMesh& transformed_mesh() const; // const TriangleMesh& transformed_mesh() const;
sla::SupportPoints transformed_support_points() const; sla::SupportPoints transformed_support_points() const;
sla::DrainHoles transformed_drainhole_points() const; sla::DrainHoles transformed_drainhole_points() const;

View File

@ -2011,14 +2011,14 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
size_t volume_idx; size_t volume_idx;
}; };
// SLA steps to pull the preview meshes for. // // SLA steps to pull the preview meshes for.
typedef std::array<SLAPrintObjectStep, 3> SLASteps; // typedef std::array<SLAPrintObjectStep, 3> SLASteps;
SLASteps sla_steps = { slaposDrillHoles, slaposSupportTree, slaposPad }; // SLASteps sla_steps = { slaposDrillHoles, slaposSupportTree, slaposPad };
struct SLASupportState { // struct SLASupportState {
std::array<PrintStateBase::StateWithTimeStamp, std::tuple_size<SLASteps>::value> step; // std::array<PrintStateBase::StateWithTimeStamp, std::tuple_size<SLASteps>::value> step;
}; // };
// State of the sla_steps for all SLAPrintObjects. // // State of the sla_steps for all SLAPrintObjects.
std::vector<SLASupportState> sla_support_state; // std::vector<SLASupportState> sla_support_state;
std::vector<size_t> instance_ids_selected; std::vector<size_t> instance_ids_selected;
std::vector<size_t> map_glvolume_old_to_new(m_volumes.volumes.size(), size_t(-1)); std::vector<size_t> map_glvolume_old_to_new(m_volumes.volumes.size(), size_t(-1));
@ -2044,33 +2044,33 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
} }
} }
} }
if (printer_technology == ptSLA) { // if (printer_technology == ptSLA) {
const SLAPrint* sla_print = this->sla_print(); // const SLAPrint* sla_print = this->sla_print();
#ifndef NDEBUG //#ifndef NDEBUG
// Verify that the SLAPrint object is synchronized with m_model. // // Verify that the SLAPrint object is synchronized with m_model.
check_model_ids_equal(*m_model, sla_print->model()); // check_model_ids_equal(*m_model, sla_print->model());
#endif /* NDEBUG */ //#endif /* NDEBUG */
sla_support_state.reserve(sla_print->objects().size()); // sla_support_state.reserve(sla_print->objects().size());
for (const SLAPrintObject* print_object : sla_print->objects()) { // for (const SLAPrintObject* print_object : sla_print->objects()) {
SLASupportState state; // SLASupportState state;
for (size_t istep = 0; istep < sla_steps.size(); ++istep) { // for (size_t istep = 0; istep < sla_steps.size(); ++istep) {
state.step[istep] = print_object->step_state_with_timestamp(sla_steps[istep]); // state.step[istep] = print_object->step_state_with_timestamp(sla_steps[istep]);
if (state.step[istep].state == PrintStateBase::DONE) { // if (state.step[istep].state == PrintStateBase::DONE) {
if (!print_object->has_mesh(sla_steps[istep])) // if (!print_object->has_mesh(sla_steps[istep]))
// Consider the DONE step without a valid mesh as invalid for the purpose // // Consider the DONE step without a valid mesh as invalid for the purpose
// of mesh visualization. // // of mesh visualization.
state.step[istep].state = PrintStateBase::INVALID; // state.step[istep].state = PrintStateBase::INVALID;
else if (sla_steps[istep] != slaposDrillHoles) // else if (sla_steps[istep] != slaposDrillHoles)
for (const ModelInstance* model_instance : print_object->model_object()->instances) // for (const ModelInstance* model_instance : print_object->model_object()->instances)
// Only the instances, which are currently printable, will have the SLA support structures kept. // // Only the instances, which are currently printable, will have the SLA support structures kept.
// The instances outside the print bed will have the GLVolumes of their support structures released. // // The instances outside the print bed will have the GLVolumes of their support structures released.
if (model_instance->is_printable()) // if (model_instance->is_printable())
aux_volume_state.emplace_back(state.step[istep].timestamp, model_instance->id()); // aux_volume_state.emplace_back(state.step[istep].timestamp, model_instance->id());
} // }
} // }
sla_support_state.emplace_back(state); // sla_support_state.emplace_back(state);
} // }
} // }
std::sort(model_volume_state.begin(), model_volume_state.end(), model_volume_state_lower); std::sort(model_volume_state.begin(), model_volume_state.end(), model_volume_state_lower);
std::sort(aux_volume_state.begin(), aux_volume_state.end(), model_volume_state_lower); std::sort(aux_volume_state.begin(), aux_volume_state.end(), model_volume_state_lower);
// Release all ModelVolume based GLVolumes not found in the current Model. Find the GLVolume of a hollowed mesh. // Release all ModelVolume based GLVolumes not found in the current Model. Find the GLVolume of a hollowed mesh.
@ -7642,10 +7642,10 @@ void GLCanvas3D::_load_sla_shells()
// Set the extruder_id and volume_id to achieve the same color as in the 3D scene when // Set the extruder_id and volume_id to achieve the same color as in the 3D scene when
// through the update_volumes_colors_by_extruder() call. // through the update_volumes_colors_by_extruder() call.
m_volumes.volumes.back()->extruder_id = obj->model_object()->volumes.front()->extruder_id(); m_volumes.volumes.back()->extruder_id = obj->model_object()->volumes.front()->extruder_id();
if (obj->is_step_done(slaposSupportTree) && obj->has_mesh(slaposSupportTree)) if (auto &tree_mesh = obj->support_mesh(); !tree_mesh.empty())
add_volume(*obj, -int(slaposSupportTree), instance, obj->support_mesh(), GLVolume::SLA_SUPPORT_COLOR, true); add_volume(*obj, -int(slaposSupportTree), instance, tree_mesh, GLVolume::SLA_SUPPORT_COLOR, true);
if (obj->is_step_done(slaposPad) && obj->has_mesh(slaposPad)) if (auto &pad_mesh = obj->pad_mesh(); !pad_mesh.empty())
add_volume(*obj, -int(slaposPad), instance, obj->pad_mesh(), GLVolume::SLA_PAD_COLOR, false); add_volume(*obj, -int(slaposPad), instance, pad_mesh, GLVolume::SLA_PAD_COLOR, false);
} }
double shift_z = obj->get_current_elevation(); double shift_z = obj->get_current_elevation();
for (unsigned int i = initial_volumes_count; i < m_volumes.volumes.size(); ++ i) { for (unsigned int i = initial_volumes_count; i < m_volumes.volumes.size(); ++ i) {