mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-19 11:23:42 +00:00
Some optimizations of the color print preview.
This commit is contained in:
@@ -7288,31 +7288,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
|
||||
{
|
||||
double z = layers[layer_idx]->print_z;
|
||||
size_t layer = 0;
|
||||
const size_t clr_change_cnt = color_print_values->size();
|
||||
for (size_t i = 0; i < clr_change_cnt; i++)
|
||||
{
|
||||
if (z < (*color_print_values)[i]-EPSILON) {
|
||||
layer = i;
|
||||
break;
|
||||
}
|
||||
if (layer == 0 && i == clr_change_cnt - 1)
|
||||
layer = clr_change_cnt;
|
||||
}
|
||||
|
||||
const size_t clr_cnt = number_tools();
|
||||
while (layer >= clr_cnt)
|
||||
layer -= clr_cnt;
|
||||
|
||||
return color_tool(layer);
|
||||
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;
|
||||
|
||||
|
||||
@@ -737,9 +737,12 @@ void Preview::load_print_as_fff()
|
||||
if (m_gcode_preview_data->extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint)
|
||||
{
|
||||
colors = GCodePreviewData::ColorPrintColors();
|
||||
|
||||
const auto& config = wxGetApp().preset_bundle->full_config();
|
||||
color_print_values = config.option<ConfigOptionFloats>("colorprint_heights")->values;
|
||||
if (! gcode_preview_data_valid) {
|
||||
//FIXME accessing full_config() is pretty expensive.
|
||||
// Only initialize color_print_values for the initial preview, not for the full preview where the color_print_values is extracted from the G-code.
|
||||
const auto& config = wxGetApp().preset_bundle->full_config();
|
||||
color_print_values = config.option<ConfigOptionFloats>("colorprint_heights")->values;
|
||||
}
|
||||
}
|
||||
else if (gcode_preview_data_valid || (m_gcode_preview_data->extrusion.view_type == GCodePreviewData::Extrusion::Tool) )
|
||||
{
|
||||
@@ -758,10 +761,9 @@ void Preview::load_print_as_fff()
|
||||
color = "#FFFFFF";
|
||||
}
|
||||
|
||||
colors.push_back(color);
|
||||
colors.emplace_back(color);
|
||||
}
|
||||
if (!color_print_values.empty())
|
||||
color_print_values.clear();
|
||||
color_print_values.clear();
|
||||
}
|
||||
|
||||
if (IsShown())
|
||||
|
||||
Reference in New Issue
Block a user