mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
Merge branch 'master' of https://github.com/prusa3d/Slic3r into sidebar_fixes
This commit is contained in:
commit
883e09fbcd
9 changed files with 168 additions and 49 deletions
|
@ -3751,14 +3751,9 @@ GLCanvas3D::LegendTexture::LegendTexture()
|
|||
{
|
||||
}
|
||||
|
||||
bool GLCanvas3D::LegendTexture::generate(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors, const GLCanvas3D& canvas, bool use_error_colors)
|
||||
void GLCanvas3D::LegendTexture::fill_color_print_legend_values(const GCodePreviewData& preview_data, const GLCanvas3D& canvas,
|
||||
std::vector<std::pair<double, double>>& cp_legend_values)
|
||||
{
|
||||
reset();
|
||||
|
||||
// collects items to render
|
||||
auto title = _(preview_data.get_legend_title());
|
||||
|
||||
std::vector<std::pair<double, double>> cp_legend_values;
|
||||
if (preview_data.extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint)
|
||||
{
|
||||
const auto& config = wxGetApp().preset_bundle->full_config();
|
||||
|
@ -3782,7 +3777,19 @@ bool GLCanvas3D::LegendTexture::generate(const GCodePreviewData& preview_data, c
|
|||
}
|
||||
}
|
||||
}
|
||||
const GCodePreviewData::LegendItemsList& items = preview_data.get_legend_items(tool_colors, /*color_print_values*/cp_legend_values);
|
||||
}
|
||||
|
||||
bool GLCanvas3D::LegendTexture::generate(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors, const GLCanvas3D& canvas, bool use_error_colors)
|
||||
{
|
||||
reset();
|
||||
|
||||
// collects items to render
|
||||
auto title = _(preview_data.get_legend_title());
|
||||
|
||||
std::vector<std::pair<double, double>> cp_legend_values;
|
||||
fill_color_print_legend_values(preview_data, canvas, cp_legend_values);
|
||||
|
||||
const GCodePreviewData::LegendItemsList& items = preview_data.get_legend_items(tool_colors, cp_legend_values);
|
||||
|
||||
unsigned int items_count = (unsigned int)items.size();
|
||||
if (items_count == 0)
|
||||
|
@ -4968,7 +4975,7 @@ void GLCanvas3D::load_sla_preview()
|
|||
}
|
||||
}
|
||||
|
||||
void GLCanvas3D::load_preview(const std::vector<std::string>& str_tool_colors)
|
||||
void GLCanvas3D::load_preview(const std::vector<std::string>& str_tool_colors, const std::vector<double>& color_print_values)
|
||||
{
|
||||
const Print *print = this->fff_print();
|
||||
if (print == nullptr)
|
||||
|
@ -4979,7 +4986,7 @@ void GLCanvas3D::load_preview(const std::vector<std::string>& str_tool_colors)
|
|||
for (const PrintObject* object : print->objects())
|
||||
{
|
||||
if (object != nullptr)
|
||||
_load_print_object_toolpaths(*object, str_tool_colors);
|
||||
_load_print_object_toolpaths(*object, str_tool_colors, color_print_values);
|
||||
}
|
||||
|
||||
for (GLVolume* volume : m_volumes.volumes)
|
||||
|
@ -4989,7 +4996,14 @@ void GLCanvas3D::load_preview(const std::vector<std::string>& str_tool_colors)
|
|||
|
||||
_update_toolpath_volumes_outside_state();
|
||||
_show_warning_texture_if_needed();
|
||||
reset_legend_texture();
|
||||
if (color_print_values.empty())
|
||||
reset_legend_texture();
|
||||
else {
|
||||
auto preview_data = GCodePreviewData();
|
||||
preview_data.extrusion.view_type = GCodePreviewData::Extrusion::ColorPrint;
|
||||
const std::vector<float> tool_colors = _parse_colors(str_tool_colors);
|
||||
_generate_legend_texture(preview_data, tool_colors);
|
||||
}
|
||||
}
|
||||
|
||||
void GLCanvas3D::bind_event_handlers()
|
||||
|
@ -7213,7 +7227,7 @@ void GLCanvas3D::_load_print_toolpaths()
|
|||
volume.indexed_vertex_array.finalize_geometry(m_use_VBOs && m_initialized);
|
||||
}
|
||||
|
||||
void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, const std::vector<std::string>& str_tool_colors)
|
||||
void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, const std::vector<std::string>& str_tool_colors, const std::vector<double>& color_print_values)
|
||||
{
|
||||
std::vector<float> tool_colors = _parse_colors(str_tool_colors);
|
||||
|
||||
|
@ -7225,6 +7239,7 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
|
|||
bool has_infill;
|
||||
bool has_support;
|
||||
const std::vector<float>* tool_colors;
|
||||
const std::vector<double>* color_print_values;
|
||||
|
||||
// Number of vertices (each vertex is 6x4=24 bytes long)
|
||||
static const size_t alloc_size_max() { return 131072; } // 3.15MB
|
||||
|
@ -7242,7 +7257,15 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
|
|||
const float* color_tool(size_t tool) const { return tool_colors->data() + tool * 4; }
|
||||
int volume_idx(int extruder, int feature) const
|
||||
{
|
||||
return this->color_by_tool() ? std::min<int>(this->number_tools() - 1, std::max<int>(extruder - 1, 0)) : feature;
|
||||
return this->color_by_color_print() ? 0 : this->color_by_tool() ? std::min<int>(this->number_tools() - 1, std::max<int>(extruder - 1, 0)) : feature;
|
||||
}
|
||||
|
||||
// For coloring by a color_print(M600), return a parsed color.
|
||||
bool color_by_color_print() const { return color_print_values!=nullptr; }
|
||||
const float* color_print_by_layer_idx(const size_t layer_idx) const
|
||||
{
|
||||
auto it = std::lower_bound(color_print_values->begin(), color_print_values->end(), layers[layer_idx]->print_z - EPSILON);
|
||||
return color_tool((it - color_print_values->begin()) % number_tools());
|
||||
}
|
||||
} ctxt;
|
||||
|
||||
|
@ -7250,6 +7273,7 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
|
|||
ctxt.has_infill = print_object.is_step_done(posInfill);
|
||||
ctxt.has_support = print_object.is_step_done(posSupportMaterial);
|
||||
ctxt.tool_colors = tool_colors.empty() ? nullptr : &tool_colors;
|
||||
ctxt.color_print_values = color_print_values.empty() ? nullptr : &color_print_values;
|
||||
|
||||
ctxt.shifted_copies = &print_object.copies();
|
||||
|
||||
|
@ -7274,7 +7298,7 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
|
|||
BOOST_LOG_TRIVIAL(debug) << "Loading print object toolpaths in parallel - start";
|
||||
|
||||
//FIXME Improve the heuristics for a grain size.
|
||||
size_t grain_size = std::max(ctxt.layers.size() / 16, size_t(1));
|
||||
size_t grain_size = ctxt.color_by_color_print() ? size_t(1) : std::max(ctxt.layers.size() / 16, size_t(1));
|
||||
tbb::spin_mutex new_volume_mutex;
|
||||
auto new_volume = [this, &new_volume_mutex](const float *color) -> GLVolume* {
|
||||
auto *volume = new GLVolume(color);
|
||||
|
@ -7289,7 +7313,9 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
|
|||
tbb::blocked_range<size_t>(0, ctxt.layers.size(), grain_size),
|
||||
[&ctxt, &new_volume](const tbb::blocked_range<size_t>& range) {
|
||||
GLVolumePtrs vols;
|
||||
if (ctxt.color_by_tool()) {
|
||||
if (ctxt.color_by_color_print())
|
||||
vols.emplace_back(new_volume(ctxt.color_print_by_layer_idx(range.begin())));
|
||||
else if (ctxt.color_by_tool()) {
|
||||
for (size_t i = 0; i < ctxt.number_tools(); ++i)
|
||||
vols.emplace_back(new_volume(ctxt.color_tool(i)));
|
||||
}
|
||||
|
@ -7607,11 +7633,15 @@ void GLCanvas3D::_load_gcode_extrusion_paths(const GCodePreviewData& preview_dat
|
|||
}
|
||||
case GCodePreviewData::Extrusion::ColorPrint:
|
||||
{
|
||||
const size_t color_cnt = tool_colors.size() / 4;
|
||||
|
||||
int val = int(value);
|
||||
while (val >= GCodePreviewData::Range::Colors_Count)
|
||||
val -= GCodePreviewData::Range::Colors_Count;
|
||||
while (val >= color_cnt)
|
||||
val -= color_cnt;
|
||||
|
||||
GCodePreviewData::Color color = GCodePreviewData::Range::Default_Colors[val];
|
||||
GCodePreviewData::Color color;
|
||||
::memcpy((void*)color.rgba, (const void*)(tool_colors.data() + val * 4), 4 * sizeof(float));
|
||||
|
||||
return color;
|
||||
}
|
||||
default:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue