Simplified loading of the SLA support structures into the scene.

Fixed referesh of SLA support structures after Undo / Redo
and when moving an object outside / inside the build volume.
This commit is contained in:
bubnikv 2019-07-19 17:14:37 +02:00
parent ba997be812
commit 07a3072622
2 changed files with 12 additions and 55 deletions

View file

@ -1858,6 +1858,10 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
PrinterTechnology printer_technology = m_process->current_printer_technology(); PrinterTechnology printer_technology = m_process->current_printer_technology();
int volume_idx_wipe_tower_old = -1; int volume_idx_wipe_tower_old = -1;
if (printer_technology == ptSLA)
// Always do the full refresh in SLA mode to show / hide SLA support structures when an object is moved outside / inside the build volume.
m_regenerate_volumes = true;
if (m_regenerate_volumes) if (m_regenerate_volumes)
{ {
// Release invalidated volumes to conserve GPU memory in case of delayed refresh (see m_reload_delayed). // Release invalidated volumes to conserve GPU memory in case of delayed refresh (see m_reload_delayed).
@ -1890,7 +1894,10 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
state.step[istep].state = PrintStateBase::INVALID; state.step[istep].state = PrintStateBase::INVALID;
else else
for (const ModelInstance *model_instance : print_object->model_object()->instances) for (const ModelInstance *model_instance : print_object->model_object()->instances)
aux_volume_state.emplace_back(state.step[istep].timestamp, model_instance->id()); // 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.
if (model_instance->is_printable())
aux_volume_state.emplace_back(state.step[istep].timestamp, model_instance->id());
} }
} }
sla_support_state.emplace_back(state); sla_support_state.emplace_back(state);
@ -2042,7 +2049,8 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
// Shift-up all volumes of the object so that it has the right elevation with respect to the print bed // Shift-up all volumes of the object so that it has the right elevation with respect to the print bed
for (GLVolume* volume : m_volumes.volumes) for (GLVolume* volume : m_volumes.volumes)
volume->set_sla_shift_z(shift_zs[volume->object_idx()]); if (volume->object_idx() < m_model->objects.size() && m_model->objects[volume->object_idx()]->instances[volume->instance_idx()]->is_printable())
volume->set_sla_shift_z(shift_zs[volume->object_idx()]);
} }
if (printer_technology == ptFFF && m_config->has("nozzle_diameter")) if (printer_technology == ptFFF && m_config->has("nozzle_diameter"))
@ -2198,7 +2206,8 @@ void GLCanvas3D::load_sla_preview()
if ((m_canvas != nullptr) && (print != nullptr)) if ((m_canvas != nullptr) && (print != nullptr))
{ {
_set_current(); _set_current();
_load_sla_shells(); // Reload the SLA support structures into GLVolumes.
this->reload_scene(true, true);
_update_sla_shells_outside_state(); _update_sla_shells_outside_state();
_show_warning_texture_if_needed(WarningTexture::SlaSupportsOutside); _show_warning_texture_if_needed(WarningTexture::SlaSupportsOutside);
} }
@ -5461,56 +5470,6 @@ void GLCanvas3D::_load_fff_shells()
} }
} }
void GLCanvas3D::_load_sla_shells()
{
//FIXME use reload_scene
#if 1
const SLAPrint* print = this->sla_print();
if (print->objects().empty())
// nothing to render, return
return;
auto add_volume = [this](const SLAPrintObject &object, int volume_id, const SLAPrintObject::Instance& instance,
const TriangleMesh &mesh, const float color[4], bool outside_printer_detection_enabled) {
m_volumes.volumes.emplace_back(new GLVolume(color));
GLVolume& v = *m_volumes.volumes.back();
v.indexed_vertex_array.load_mesh(mesh);
v.shader_outside_printer_detection_enabled = outside_printer_detection_enabled;
v.composite_id.volume_id = volume_id;
v.set_instance_offset(unscale(instance.shift(0), instance.shift(1), 0));
v.set_instance_rotation(Vec3d(0.0, 0.0, (double)instance.rotation));
v.set_instance_mirror(X, object.is_left_handed() ? -1. : 1.);
v.set_convex_hull(mesh.convex_hull_3d());
};
// adds objects' volumes
for (const SLAPrintObject* obj : print->objects())
if (obj->is_step_done(slaposSliceSupports)) {
unsigned int initial_volumes_count = (unsigned int)m_volumes.volumes.size();
for (const SLAPrintObject::Instance& instance : obj->instances()) {
add_volume(*obj, 0, instance, obj->transformed_mesh(), GLVolume::MODEL_COLOR[0], true);
// 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.
m_volumes.volumes.back()->extruder_id = obj->model_object()->volumes.front()->extruder_id();
if (obj->is_step_done(slaposSupportTree) && obj->has_mesh(slaposSupportTree))
add_volume(*obj, -int(slaposSupportTree), instance, obj->support_mesh(), GLVolume::SLA_SUPPORT_COLOR, true);
if (obj->is_step_done(slaposBasePool) && obj->has_mesh(slaposBasePool))
add_volume(*obj, -int(slaposBasePool), instance, obj->pad_mesh(), GLVolume::SLA_PAD_COLOR, false);
}
double shift_z = obj->get_current_elevation();
for (unsigned int i = initial_volumes_count; i < m_volumes.volumes.size(); ++ i) {
GLVolume& v = *m_volumes.volumes[i];
// apply shift z
v.set_sla_shift_z(shift_z);
}
}
update_volumes_colors_by_extruder();
#else
this->reload_scene(true, true);
#endif
}
void GLCanvas3D::_update_gcode_volumes_visibility(const GCodePreviewData& preview_data) void GLCanvas3D::_update_gcode_volumes_visibility(const GCodePreviewData& preview_data)
{ {
unsigned int size = (unsigned int)m_gcode_preview_volume_index.first_volumes.size(); unsigned int size = (unsigned int)m_gcode_preview_volume_index.first_volumes.size();

View file

@ -730,8 +730,6 @@ private:
void _load_gcode_unretractions(const GCodePreviewData& preview_data); void _load_gcode_unretractions(const GCodePreviewData& preview_data);
// generates objects and wipe tower geometry // generates objects and wipe tower geometry
void _load_fff_shells(); void _load_fff_shells();
// generates objects geometry for sla
void _load_sla_shells();
// sets gcode geometry visibility according to user selection // sets gcode geometry visibility according to user selection
void _update_gcode_volumes_visibility(const GCodePreviewData& preview_data); void _update_gcode_volumes_visibility(const GCodePreviewData& preview_data);
void _update_toolpath_volumes_outside_state(); void _update_toolpath_volumes_outside_state();