mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 01:07:57 -06:00
Set custom color for color change
This commit is contained in:
parent
c564f693e9
commit
d5f7956a55
5 changed files with 150 additions and 142 deletions
|
@ -4694,6 +4694,7 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
|
|||
// #ys_FIXME_COLOR
|
||||
// const std::vector<double>* color_print_values;
|
||||
bool is_single_material_print;
|
||||
int extruders_cnt;
|
||||
const std::vector<Model::CustomGCode>* color_print_values;
|
||||
|
||||
static const float* color_perimeters() { static float color[4] = { 1.0f, 1.0f, 0.0f, 1.f }; return color; } // yellow
|
||||
|
@ -4711,24 +4712,64 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
|
|||
const size_t color_print_color_idx_by_layer_idx(const size_t layer_idx) const {
|
||||
// #ys_FIXME_COLOR
|
||||
// auto it = std::lower_bound(color_print_values->begin(), color_print_values->end(), layers[layer_idx]->print_z + EPSILON);
|
||||
const Model::CustomGCode value(layers[layer_idx]->print_z + EPSILON, "", 0);
|
||||
const Model::CustomGCode value(layers[layer_idx]->print_z + EPSILON, "", 0, "");
|
||||
auto it = std::lower_bound(color_print_values->begin(), color_print_values->end(), value);
|
||||
return (it - color_print_values->begin()) % number_tools();
|
||||
}
|
||||
|
||||
const bool pause_or_custom_code_layer(const size_t layer_idx) const
|
||||
const size_t color_print_color_idx_by_layer_idx_and_extruder(const size_t layer_idx, const int extruder) const
|
||||
{
|
||||
const coordf_t print_z = layers[layer_idx]->print_z;
|
||||
auto it = std::find_if(color_print_values->begin(), color_print_values->end(),
|
||||
[print_z](const Model::CustomGCode& code)
|
||||
{ return fabs(code.height - print_z) < EPSILON; });
|
||||
if (it == color_print_values->end())
|
||||
return false;
|
||||
|
||||
const std::string& code = (*it).gcode;
|
||||
return code == "M601" || (code != "M600" && code != "tool_change");
|
||||
auto it = std::find_if(color_print_values->begin(), color_print_values->end(),
|
||||
[print_z](const Model::CustomGCode& code)
|
||||
{ return fabs(code.height - print_z) < EPSILON; });
|
||||
if (it != color_print_values->end())
|
||||
{
|
||||
const std::string& code = it->gcode;
|
||||
// pause print or custom Gcode
|
||||
if (code == "M601" || (code != "M600" && code != "tool_change"))
|
||||
return number_tools();
|
||||
|
||||
// change tool (extruder)
|
||||
if (code == "tool_change")
|
||||
return std::min<int>(extruders_cnt - 1, std::max<int>(it->extruder - 1, 0));
|
||||
// change color for current extruder
|
||||
if (code == "M600" && it->extruder == extruder) {
|
||||
int shift = 0;
|
||||
while (it != color_print_values->begin()) {
|
||||
--it;
|
||||
if (it->gcode == "M600")
|
||||
shift++;
|
||||
}
|
||||
return extruders_cnt + shift;
|
||||
}
|
||||
}
|
||||
|
||||
const Model::CustomGCode value(print_z + EPSILON, "", 0, "");
|
||||
it = std::lower_bound(color_print_values->begin(), color_print_values->end(), value);
|
||||
while (it != color_print_values->begin())
|
||||
{
|
||||
--it;
|
||||
const std::string& code = it->gcode;
|
||||
// change color for current extruder
|
||||
if (code == "M600" && it->extruder == extruder) {
|
||||
auto it_n = it;
|
||||
int shift = 0;
|
||||
while (it_n != color_print_values->begin()) {
|
||||
--it_n;
|
||||
if (it_n->gcode == "M600")
|
||||
shift++;
|
||||
}
|
||||
return extruders_cnt + shift;
|
||||
}
|
||||
// change tool (extruder)
|
||||
if (code == "tool_change")
|
||||
return std::min<int>(extruders_cnt - 1, std::max<int>(it->extruder - 1, 0));
|
||||
}
|
||||
|
||||
return std::min<int>(extruders_cnt - 1, std::max<int>(extruder - 1, 0));;
|
||||
}
|
||||
|
||||
} ctxt;
|
||||
|
||||
ctxt.has_perimeters = print_object.is_step_done(posPerimeters);
|
||||
|
@ -4737,6 +4778,7 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
|
|||
ctxt.tool_colors = tool_colors.empty() ? nullptr : &tool_colors;
|
||||
ctxt.color_print_values = color_print_values.empty() ? nullptr : &color_print_values;
|
||||
ctxt.is_single_material_print = this->fff_print()->extruders().size()==1;
|
||||
ctxt.extruders_cnt = wxGetApp().extruders_edited_cnt();
|
||||
|
||||
ctxt.shifted_copies = &print_object.copies();
|
||||
|
||||
|
@ -4782,67 +4824,17 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
|
|||
[&ctxt, &new_volume, is_selected_separate_extruder, this](const tbb::blocked_range<size_t>& range) {
|
||||
GLVolumePtrs vols;
|
||||
std::vector<size_t> color_print_layer_to_glvolume;
|
||||
auto volume = [&ctxt, &vols, &color_print_layer_to_glvolume, &range](size_t layer_idx, int extruder, int feature) -> GLVolume& {
|
||||
if (ctxt.color_by_color_print() && !ctxt.is_single_material_print)
|
||||
{
|
||||
const coordf_t print_z = ctxt.layers[layer_idx]->print_z;
|
||||
const std::vector<Model::CustomGCode>* cp_values = ctxt.color_print_values;
|
||||
|
||||
// pause print or custom Gcode
|
||||
auto it = std::find_if(cp_values->begin(), cp_values->end(),
|
||||
[print_z](const Model::CustomGCode& code)
|
||||
{ return fabs(code.height - print_z) < EPSILON; });
|
||||
if (it != cp_values->end())
|
||||
{
|
||||
const std::string& code = (*it).gcode;
|
||||
if (code == "M601" || (code != "M600" && code != "tool_change"))
|
||||
return *vols[ctxt.number_tools()];//*vols.back();
|
||||
// change tool (extruder)
|
||||
if (code == "tool_change")
|
||||
return *vols[std::min<int>(ctxt.number_tools() - 1, std::max<int>(it->extruder - 1, 0))];
|
||||
if (code == "M600" && it->extruder == extruder) {
|
||||
int shift = 1;
|
||||
while (it != cp_values->begin()) {
|
||||
--it;
|
||||
if (it->gcode == "M600")
|
||||
shift++;
|
||||
}
|
||||
return *vols[ctxt.number_tools()+shift];
|
||||
}
|
||||
}
|
||||
|
||||
const Model::CustomGCode value(print_z + EPSILON, "", 0);
|
||||
it = std::lower_bound(cp_values->begin(), cp_values->end(), value);
|
||||
while (it != cp_values->begin())
|
||||
{
|
||||
--it;
|
||||
const std::string& code = (*it).gcode;
|
||||
if (code == "M600" && it->extruder == extruder) {
|
||||
auto it_n = it;
|
||||
int shift = 1;
|
||||
while (it_n != cp_values->begin()) {
|
||||
--it_n;
|
||||
if (it_n->gcode == "M600")
|
||||
shift++;
|
||||
}
|
||||
return *vols[ctxt.number_tools() + shift];
|
||||
}
|
||||
if (code == "tool_change")
|
||||
return *vols[std::min<int>(ctxt.number_tools() - 1, std::max<int>((*it).extruder - 1, 0))];
|
||||
}
|
||||
|
||||
return *vols[std::min<int>(ctxt.number_tools() - 1, std::max<int>(extruder - 1, 0))];
|
||||
}
|
||||
|
||||
return *vols[ctxt.color_by_color_print() && ctxt.is_single_material_print ?
|
||||
color_print_layer_to_glvolume[layer_idx - range.begin()] :
|
||||
auto volume = [&ctxt, &vols, &color_print_layer_to_glvolume, &range](size_t layer_idx, int extruder, int feature) -> GLVolume& {
|
||||
return *vols[ctxt.color_by_color_print()?
|
||||
//color_print_layer_to_glvolume[layer_idx - range.begin()] :
|
||||
ctxt.color_print_color_idx_by_layer_idx_and_extruder(layer_idx/* - range.begin()*/, extruder) :
|
||||
ctxt.color_by_tool() ?
|
||||
std::min<int>(ctxt.number_tools() - 1, std::max<int>(extruder - 1, 0)) :
|
||||
feature
|
||||
];
|
||||
};
|
||||
if (ctxt.color_by_color_print() && ctxt.is_single_material_print) {
|
||||
// Create a map from the layer index to a GLVolume, which is initialized with the correct layer span color.
|
||||
if (ctxt.color_by_color_print()) {
|
||||
/* // Create a map from the layer index to a GLVolume, which is initialized with the correct layer span color.
|
||||
std::vector<int> color_print_tool_to_glvolume(ctxt.number_tools(), -1);
|
||||
color_print_layer_to_glvolume.reserve(range.end() - range.begin());
|
||||
vols.reserve(ctxt.number_tools());
|
||||
|
@ -4854,25 +4846,11 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
|
|||
}
|
||||
color_print_layer_to_glvolume.emplace_back(color_print_tool_to_glvolume[idx_tool]);
|
||||
}
|
||||
}
|
||||
else if (ctxt.color_by_color_print() && !ctxt.is_single_material_print) {
|
||||
vols.emplace_back(new_volume(ctxt.color_pause_or_custom_code()));
|
||||
}*/
|
||||
for (size_t i = 0; i < ctxt.number_tools(); ++i)
|
||||
vols.emplace_back(new_volume(ctxt.color_tool(i)));
|
||||
vols.emplace_back(new_volume(ctxt.color_pause_or_custom_code()));
|
||||
|
||||
for ( auto it = ctxt.color_print_values->begin(); it < ctxt.color_print_values->end(); it++) {
|
||||
if (it->gcode == "M600" && it->extruder != 0)
|
||||
{
|
||||
int cp_id = it - ctxt.color_print_values->begin() + 1;
|
||||
float koef = fabs(1- cp_id * 0.1);
|
||||
float color_f[4];
|
||||
memcpy(color_f, ctxt.color_tool(it->extruder - 1), sizeof(float) * 4);
|
||||
for (int i=0; i<3; i++)
|
||||
color_f[i] = clamp(0.0f, 1.0f, koef * color_f[i]);
|
||||
|
||||
vols.emplace_back(new_volume(color_f));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ctxt.color_by_tool()) {
|
||||
for (size_t i = 0; i < ctxt.number_tools(); ++i)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue