SLA slices preview - wip
This commit is contained in:
parent
2a31f5e6fc
commit
4ca302ba6a
@ -4250,7 +4250,7 @@ void GLCanvas3D::load_gcode_preview(const GCodePreviewData& preview_data, const
|
||||
m_volumes.volumes.erase(std::remove_if(m_volumes.volumes.begin(), m_volumes.volumes.end(),
|
||||
[](const GLVolume* volume) { return volume->print_zs.empty(); }), m_volumes.volumes.end());
|
||||
|
||||
_load_shells();
|
||||
_load_shells_fff();
|
||||
}
|
||||
_update_toolpath_volumes_outside_state();
|
||||
}
|
||||
@ -4260,6 +4260,15 @@ void GLCanvas3D::load_gcode_preview(const GCodePreviewData& preview_data, const
|
||||
}
|
||||
}
|
||||
|
||||
void GLCanvas3D::load_sla_preview()
|
||||
{
|
||||
const SLAPrint* print = this->sla_print();
|
||||
if ((m_canvas != nullptr) && (print != nullptr))
|
||||
{
|
||||
_load_shells_sla();
|
||||
}
|
||||
}
|
||||
|
||||
void GLCanvas3D::load_preview(const std::vector<std::string>& str_tool_colors)
|
||||
{
|
||||
const Print *print = this->fff_print();
|
||||
@ -6921,7 +6930,7 @@ void GLCanvas3D::_load_gcode_unretractions(const GCodePreviewData& preview_data)
|
||||
}
|
||||
}
|
||||
|
||||
void GLCanvas3D::_load_shells()
|
||||
void GLCanvas3D::_load_shells_fff()
|
||||
{
|
||||
size_t initial_volumes_count = m_volumes.volumes.size();
|
||||
m_gcode_preview_volume_index.first_volumes.emplace_back(GCodePreviewVolumeIndex::Shell, 0, (unsigned int)initial_volumes_count);
|
||||
@ -6932,7 +6941,7 @@ void GLCanvas3D::_load_shells()
|
||||
return;
|
||||
|
||||
// adds objects' volumes
|
||||
unsigned int object_id = 0;
|
||||
int object_id = 0;
|
||||
for (const PrintObject* obj : print->objects())
|
||||
{
|
||||
const ModelObject* model_obj = obj->model_object();
|
||||
@ -6963,6 +6972,95 @@ void GLCanvas3D::_load_shells()
|
||||
}
|
||||
}
|
||||
|
||||
void GLCanvas3D::_load_shells_sla()
|
||||
{
|
||||
const SLAPrint* print = this->sla_print();
|
||||
if (print->objects().empty())
|
||||
// nothing to render, return
|
||||
return;
|
||||
|
||||
// adds objects' volumes
|
||||
int obj_idx = 0;
|
||||
for (const SLAPrintObject* obj : print->objects())
|
||||
{
|
||||
unsigned int initial_volumes_count = (unsigned int)m_volumes.volumes.size();
|
||||
|
||||
const ModelObject* model_obj = obj->model_object();
|
||||
std::vector<int> instance_idxs(model_obj->instances.size());
|
||||
for (int i = 0; i < (int)model_obj->instances.size(); ++i)
|
||||
{
|
||||
instance_idxs[i] = i;
|
||||
}
|
||||
|
||||
m_volumes.load_object(model_obj, obj_idx, instance_idxs, "object", m_use_VBOs && m_initialized);
|
||||
|
||||
const std::vector<SLAPrintObject::Instance>& instances = obj->instances();
|
||||
|
||||
for (const SLAPrintObject::Instance& instance : instances)
|
||||
{
|
||||
Vec3d offset = unscale(instance.shift(0), instance.shift(1), 0);
|
||||
Vec3d rotation(0.0, 0.0, (double)instance.rotation);
|
||||
|
||||
unsigned int partial_volumes_count = (unsigned int)m_volumes.volumes.size();
|
||||
|
||||
// add supports
|
||||
if (obj->is_step_done(slaposSupportTree))
|
||||
{
|
||||
const TriangleMesh& mesh = obj->support_mesh();
|
||||
m_volumes.volumes.emplace_back(new GLVolume(GLVolume::SLA_SUPPORT_COLOR));
|
||||
GLVolume& v = *m_volumes.volumes.back();
|
||||
|
||||
if (m_use_VBOs)
|
||||
v.indexed_vertex_array.load_mesh_full_shading(mesh);
|
||||
else
|
||||
v.indexed_vertex_array.load_mesh_flat_shading(mesh);
|
||||
|
||||
v.shader_outside_printer_detection_enabled = true;
|
||||
v.composite_id.volume_id = -1;
|
||||
v.set_instance_offset(offset);
|
||||
v.set_instance_rotation(rotation);
|
||||
}
|
||||
|
||||
// add pad
|
||||
if (obj->is_step_done(slaposBasePool))
|
||||
{
|
||||
const TriangleMesh& mesh = obj->pad_mesh();
|
||||
m_volumes.volumes.emplace_back(new GLVolume(GLVolume::SLA_PAD_COLOR));
|
||||
GLVolume& v = *m_volumes.volumes.back();
|
||||
|
||||
if (m_use_VBOs)
|
||||
v.indexed_vertex_array.load_mesh_full_shading(mesh);
|
||||
else
|
||||
v.indexed_vertex_array.load_mesh_flat_shading(mesh);
|
||||
|
||||
v.shader_outside_printer_detection_enabled = true;
|
||||
v.composite_id.volume_id = -1;
|
||||
v.set_instance_offset(offset);
|
||||
v.set_instance_rotation(rotation);
|
||||
}
|
||||
|
||||
// finalize volumes and sends geometry to gpu
|
||||
for (unsigned int i = partial_volumes_count; i < m_volumes.volumes.size(); ++i)
|
||||
{
|
||||
GLVolume& v = *m_volumes.volumes[i];
|
||||
v.bounding_box = v.indexed_vertex_array.bounding_box();
|
||||
v.indexed_vertex_array.finalize_geometry(m_use_VBOs);
|
||||
}
|
||||
|
||||
++obj_idx;
|
||||
}
|
||||
|
||||
// apply shift z
|
||||
double shift_z = obj->get_current_elevation();
|
||||
for (unsigned int i = initial_volumes_count; i < m_volumes.volumes.size(); ++i)
|
||||
{
|
||||
m_volumes.volumes[i]->set_sla_shift_z(shift_z);
|
||||
}
|
||||
}
|
||||
|
||||
update_volumes_colors_by_extruder();
|
||||
}
|
||||
|
||||
void GLCanvas3D::_update_gcode_volumes_visibility(const GCodePreviewData& preview_data)
|
||||
{
|
||||
unsigned int size = (unsigned int)m_gcode_preview_volume_index.first_volumes.size();
|
||||
|
@ -835,6 +835,7 @@ public:
|
||||
void reload_scene(bool refresh_immediately, bool force_full_scene_refresh = false);
|
||||
|
||||
void load_gcode_preview(const GCodePreviewData& preview_data, const std::vector<std::string>& str_tool_colors);
|
||||
void load_sla_preview();
|
||||
void load_preview(const std::vector<std::string>& str_tool_colors);
|
||||
|
||||
void bind_event_handlers();
|
||||
@ -944,7 +945,8 @@ private:
|
||||
// generates gcode unretractions geometry
|
||||
void _load_gcode_unretractions(const GCodePreviewData& preview_data);
|
||||
// generates objects and wipe tower geometry
|
||||
void _load_shells();
|
||||
void _load_shells_fff();
|
||||
void _load_shells_sla();
|
||||
// sets gcode geometry visibility according to user selection
|
||||
void _update_gcode_volumes_visibility(const GCodePreviewData& preview_data);
|
||||
void _update_toolpath_volumes_outside_state();
|
||||
|
@ -244,111 +244,11 @@ void Preview::set_drop_target(wxDropTarget* target)
|
||||
|
||||
void Preview::load_print()
|
||||
{
|
||||
if (m_loaded || m_process->current_printer_technology() != ptFFF)
|
||||
return;
|
||||
|
||||
// we require that there's at least one object and the posSlice step
|
||||
// is performed on all of them(this ensures that _shifted_copies was
|
||||
// populated and we know the number of layers)
|
||||
unsigned int n_layers = 0;
|
||||
const Print *print = m_process->fff_print();
|
||||
if (print->is_step_done(posSlice))
|
||||
{
|
||||
std::set<float> zs;
|
||||
for (const PrintObject* print_object : print->objects())
|
||||
{
|
||||
const LayerPtrs& layers = print_object->layers();
|
||||
const SupportLayerPtrs& support_layers = print_object->support_layers();
|
||||
for (const Layer* layer : layers)
|
||||
{
|
||||
zs.insert(layer->print_z);
|
||||
}
|
||||
for (const SupportLayer* layer : support_layers)
|
||||
{
|
||||
zs.insert(layer->print_z);
|
||||
}
|
||||
}
|
||||
|
||||
n_layers = (unsigned int)zs.size();
|
||||
}
|
||||
|
||||
if (n_layers == 0)
|
||||
{
|
||||
reset_sliders();
|
||||
m_canvas->reset_legend_texture();
|
||||
m_canvas_widget->Refresh();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_preferred_color_mode == "tool_or_feature")
|
||||
{
|
||||
// It is left to Slic3r to decide whether the print shall be colored by the tool or by the feature.
|
||||
// Color by feature if it is a single extruder print.
|
||||
unsigned int number_extruders = (unsigned int)print->extruders().size();
|
||||
int tool_idx = m_choice_view_type->FindString(_(L("Tool")));
|
||||
int type = (number_extruders > 1) ? tool_idx /* color by a tool number */ : 0; // color by a feature type
|
||||
m_choice_view_type->SetSelection(type);
|
||||
if ((0 <= type) && (type < (int)GCodePreviewData::Extrusion::Num_View_Types))
|
||||
m_gcode_preview_data->extrusion.view_type = (GCodePreviewData::Extrusion::EViewType)type;
|
||||
// If the->SetSelection changed the following line, revert it to "decide yourself".
|
||||
m_preferred_color_mode = "tool_or_feature";
|
||||
}
|
||||
|
||||
// Collect colors per extruder.
|
||||
std::vector<std::string> colors;
|
||||
if (!m_gcode_preview_data->empty() || (m_gcode_preview_data->extrusion.view_type == GCodePreviewData::Extrusion::Tool))
|
||||
{
|
||||
const ConfigOptionStrings* extruders_opt = dynamic_cast<const ConfigOptionStrings*>(m_config->option("extruder_colour"));
|
||||
const ConfigOptionStrings* filamemts_opt = dynamic_cast<const ConfigOptionStrings*>(m_config->option("filament_colour"));
|
||||
unsigned int colors_count = std::max((unsigned int)extruders_opt->values.size(), (unsigned int)filamemts_opt->values.size());
|
||||
|
||||
unsigned char rgb[3];
|
||||
for (unsigned int i = 0; i < colors_count; ++i)
|
||||
{
|
||||
std::string color = m_config->opt_string("extruder_colour", i);
|
||||
if (!PresetBundle::parse_color(color, rgb))
|
||||
{
|
||||
color = m_config->opt_string("filament_colour", i);
|
||||
if (!PresetBundle::parse_color(color, rgb))
|
||||
color = "#FFFFFF";
|
||||
}
|
||||
|
||||
colors.push_back(color);
|
||||
}
|
||||
}
|
||||
|
||||
if (IsShown())
|
||||
{
|
||||
// used to set the sliders to the extremes of the current zs range
|
||||
m_force_sliders_full_range = false;
|
||||
|
||||
if (m_gcode_preview_data->empty())
|
||||
{
|
||||
// load skirt and brim
|
||||
m_canvas->load_preview(colors);
|
||||
show_hide_ui_elements("simple");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_force_sliders_full_range = (m_canvas->get_volumes_count() == 0);
|
||||
m_canvas->load_gcode_preview(*m_gcode_preview_data, colors);
|
||||
show_hide_ui_elements("full");
|
||||
|
||||
// recalculates zs and update sliders accordingly
|
||||
n_layers = (unsigned int)m_canvas->get_current_print_zs( true).size();
|
||||
if (n_layers == 0)
|
||||
{
|
||||
// all layers filtered out
|
||||
reset_sliders();
|
||||
m_canvas_widget->Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
if (n_layers > 0)
|
||||
update_sliders();
|
||||
|
||||
m_loaded = true;
|
||||
}
|
||||
PrinterTechnology tech = m_process->current_printer_technology();
|
||||
if (tech == ptFFF)
|
||||
load_print_as_fff();
|
||||
else if (tech == ptSLA)
|
||||
load_print_as_sla();
|
||||
}
|
||||
|
||||
void Preview::reload_print(bool force)
|
||||
@ -407,6 +307,16 @@ void Preview::show_hide_ui_elements(const std::string& what)
|
||||
enable = (what != "none");
|
||||
m_label_view_type->Enable(enable);
|
||||
m_choice_view_type->Enable(enable);
|
||||
|
||||
bool visible = (what != "none");
|
||||
m_label_show_features->Show(visible);
|
||||
m_combochecklist_features->Show(visible);
|
||||
m_checkbox_travel->Show(visible);
|
||||
m_checkbox_retractions->Show(visible);
|
||||
m_checkbox_unretractions->Show(visible);
|
||||
m_checkbox_shells->Show(visible);
|
||||
m_label_view_type->Show(visible);
|
||||
m_choice_view_type->Show(visible);
|
||||
}
|
||||
|
||||
void Preview::reset_sliders()
|
||||
@ -593,5 +503,124 @@ void Preview::update_double_slider_from_canvas(wxKeyEvent& event)
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void Preview::load_print_as_fff()
|
||||
{
|
||||
if (m_loaded || m_process->current_printer_technology() != ptFFF)
|
||||
return;
|
||||
|
||||
// we require that there's at least one object and the posSlice step
|
||||
// is performed on all of them(this ensures that _shifted_copies was
|
||||
// populated and we know the number of layers)
|
||||
unsigned int n_layers = 0;
|
||||
const Print *print = m_process->fff_print();
|
||||
if (print->is_step_done(posSlice))
|
||||
{
|
||||
std::set<float> zs;
|
||||
for (const PrintObject* print_object : print->objects())
|
||||
{
|
||||
const LayerPtrs& layers = print_object->layers();
|
||||
const SupportLayerPtrs& support_layers = print_object->support_layers();
|
||||
for (const Layer* layer : layers)
|
||||
{
|
||||
zs.insert(layer->print_z);
|
||||
}
|
||||
for (const SupportLayer* layer : support_layers)
|
||||
{
|
||||
zs.insert(layer->print_z);
|
||||
}
|
||||
}
|
||||
|
||||
n_layers = (unsigned int)zs.size();
|
||||
}
|
||||
|
||||
if (n_layers == 0)
|
||||
{
|
||||
reset_sliders();
|
||||
m_canvas->reset_legend_texture();
|
||||
m_canvas_widget->Refresh();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_preferred_color_mode == "tool_or_feature")
|
||||
{
|
||||
// It is left to Slic3r to decide whether the print shall be colored by the tool or by the feature.
|
||||
// Color by feature if it is a single extruder print.
|
||||
unsigned int number_extruders = (unsigned int)print->extruders().size();
|
||||
int tool_idx = m_choice_view_type->FindString(_(L("Tool")));
|
||||
int type = (number_extruders > 1) ? tool_idx /* color by a tool number */ : 0; // color by a feature type
|
||||
m_choice_view_type->SetSelection(type);
|
||||
if ((0 <= type) && (type < (int)GCodePreviewData::Extrusion::Num_View_Types))
|
||||
m_gcode_preview_data->extrusion.view_type = (GCodePreviewData::Extrusion::EViewType)type;
|
||||
// If the->SetSelection changed the following line, revert it to "decide yourself".
|
||||
m_preferred_color_mode = "tool_or_feature";
|
||||
}
|
||||
|
||||
// Collect colors per extruder.
|
||||
std::vector<std::string> colors;
|
||||
if (!m_gcode_preview_data->empty() || (m_gcode_preview_data->extrusion.view_type == GCodePreviewData::Extrusion::Tool))
|
||||
{
|
||||
const ConfigOptionStrings* extruders_opt = dynamic_cast<const ConfigOptionStrings*>(m_config->option("extruder_colour"));
|
||||
const ConfigOptionStrings* filamemts_opt = dynamic_cast<const ConfigOptionStrings*>(m_config->option("filament_colour"));
|
||||
unsigned int colors_count = std::max((unsigned int)extruders_opt->values.size(), (unsigned int)filamemts_opt->values.size());
|
||||
|
||||
unsigned char rgb[3];
|
||||
for (unsigned int i = 0; i < colors_count; ++i)
|
||||
{
|
||||
std::string color = m_config->opt_string("extruder_colour", i);
|
||||
if (!PresetBundle::parse_color(color, rgb))
|
||||
{
|
||||
color = m_config->opt_string("filament_colour", i);
|
||||
if (!PresetBundle::parse_color(color, rgb))
|
||||
color = "#FFFFFF";
|
||||
}
|
||||
|
||||
colors.push_back(color);
|
||||
}
|
||||
}
|
||||
|
||||
if (IsShown())
|
||||
{
|
||||
// used to set the sliders to the extremes of the current zs range
|
||||
m_force_sliders_full_range = false;
|
||||
|
||||
if (m_gcode_preview_data->empty())
|
||||
{
|
||||
// load skirt and brim
|
||||
m_canvas->load_preview(colors);
|
||||
show_hide_ui_elements("simple");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_force_sliders_full_range = (m_canvas->get_volumes_count() == 0);
|
||||
m_canvas->load_gcode_preview(*m_gcode_preview_data, colors);
|
||||
show_hide_ui_elements("full");
|
||||
|
||||
// recalculates zs and update sliders accordingly
|
||||
n_layers = (unsigned int)m_canvas->get_current_print_zs(true).size();
|
||||
if (n_layers == 0)
|
||||
{
|
||||
// all layers filtered out
|
||||
reset_sliders();
|
||||
m_canvas_widget->Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
if (n_layers > 0)
|
||||
update_sliders();
|
||||
|
||||
m_loaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Preview::load_print_as_sla()
|
||||
{
|
||||
if (m_loaded || (m_process->current_printer_technology() != ptSLA))
|
||||
return;
|
||||
|
||||
std::cout << "Preview::load_print_as_sla()" << std::endl;
|
||||
m_canvas->load_sla_preview();
|
||||
show_hide_ui_elements("none");
|
||||
}
|
||||
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
@ -107,6 +107,9 @@ private:
|
||||
void reset_double_slider();
|
||||
// update DoubleSlider after keyDown in canvas
|
||||
void update_double_slider_from_canvas(wxKeyEvent& event);
|
||||
|
||||
void load_print_as_fff();
|
||||
void load_print_as_sla();
|
||||
};
|
||||
|
||||
} // namespace GUI
|
||||
|
Loading…
Reference in New Issue
Block a user