Draw translucent filaments translucent in Preview (#16776)

This commit is contained in:
Ian Bassi authored and GitHub committed 2026-10-23 17:14:09 -03:00
1 parent 5869d227b4
commit 7319a2c54c
25 files changed
+1401 -191

No files matched your search

+49 -29
View File
@@ -126,6 +126,18 @@ namespace GUI {
// _u8L("Filament")
// };
// ORCA: a translucent filament swatch goes over the checkerboard of the sidebar's clear swatch
static void add_swatch(ImDrawList* draw_list, const ImVec2& min, const ImVec2& max, const ColorRGBA& color)
{
if (color.is_transparent()) {
for (int i = 0; i < 4; ++i)
for (int j = 0; j < 4; ++j)
draw_list->AddRectFilled(ImLerp(min, max, ImVec2(0.25f * i, 0.25f * j)), ImLerp(min, max, ImVec2(0.25f * (i + 1), 0.25f * (j + 1))),
(i + j) % 2 == 0 ? IM_COL32_WHITE : IM_COL32(217, 217, 217, 255));
}
draw_list->AddRectFilled(min, max, ImGuiWrapper::to_ImU32(color));
}
static std::string get_view_type_string(libvgcode::EViewType view_type)
{
if (view_type == libvgcode::EViewType::Summary)
@@ -1405,6 +1417,7 @@ void GCodeViewer::load_as_gcode(const GCodeProcessorResult& gcode_result, const
// ORCA: darken the layers the preview layer slider is not scrubbed to
m_viewer.set_dim_previous_layers(get_app_config()->get_bool("preview_dim_previous_layers"));
m_viewer.set_dim_previous_layers_brightness(0.01f * std::stoi(get_app_config()->get("preview_dim_previous_layers_brightness")));
m_viewer.set_translucent_filaments(get_app_config()->get_bool("preview_translucent_filaments"));
// avoid processing if called with the same gcode_result.
// On a belt printer the toolpath geometry fed to libvgcode also depends on the
@@ -1415,22 +1428,8 @@ void GCodeViewer::load_as_gcode(const GCodeProcessorResult& gcode_result, const
//BBS: add logs
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": the same id %1%, return directly, result %2% ") % m_last_result_id % (&gcode_result);
// collect tool colors
libvgcode::Palette tools_colors;
tools_colors.reserve(str_tool_colors.size());
for (const std::string& color : str_tool_colors) {
tools_colors.emplace_back(libvgcode::convert(color));
}
m_viewer.set_tool_colors(tools_colors);
// collect color print colors
libvgcode::Palette color_print_colors;
const std::vector<std::string>& str_colors = str_color_print_colors.empty() ? str_tool_colors : str_color_print_colors;
color_print_colors.reserve(str_colors.size());
for (const std::string& color : str_colors) {
color_print_colors.emplace_back(libvgcode::convert(color));
}
m_viewer.set_color_print_colors(color_print_colors);
m_viewer.set_tool_colors(libvgcode::convert_filament_colors(str_tool_colors));
m_viewer.set_color_print_colors(libvgcode::convert_filament_colors(str_color_print_colors.empty() ? str_tool_colors : str_color_print_colors));
return;
}
@@ -2212,7 +2211,13 @@ void GCodeViewer::render_scene(int canvas_width, int canvas_height)
return;
render_toolpaths();
// ORCA: the markers write depth, which would hide the translucent toolpaths behind them
if (!m_viewer.has_translucent_toolpaths())
render_markers(canvas_width, canvas_height);
}
void GCodeViewer::render_markers(int canvas_width, int canvas_height)
{
auto current = m_viewer.get_view_visible_range();
auto endpoints = m_viewer.get_view_full_range();
m_sequential_view.m_show_marker = m_sequential_view.m_show_marker || (current.back() != endpoints.back() && !m_no_render_path);
@@ -3236,6 +3241,25 @@ void GCodeViewer::load_shells(const Print& print, bool initialized, bool force_p
% m_shells.print_id % m_shells.print_modify_count % object_count %m_shells.volumes.volumes.size();
}
ColorRGBA GCodeViewer::shown_filament_color(ColorRGBA color) const
{
if (!m_viewer.is_translucent_filaments())
color.a(1.0f);
return color;
}
void GCodeViewer::render_translucent_toolpaths(int canvas_width, int canvas_height)
{
if (!m_viewer.has_translucent_toolpaths())
return;
const Camera& camera = wxGetApp().plater()->get_camera();
m_viewer.render_translucent(libvgcode::convert(static_cast<Matrix4f>(camera.get_view_matrix().matrix().cast<float>())),
libvgcode::convert(static_cast<Matrix4f>(camera.get_projection_matrix().matrix().cast<float>())));
glsafe(::glEnable(GL_DEPTH_TEST));
render_markers(canvas_width, canvas_height);
}
void GCodeViewer::render_toolpaths()
{
const Camera& camera = wxGetApp().plater()->get_camera();
@@ -3534,8 +3558,7 @@ void GCodeViewer::render_all_plates_stats(const std::vector<const GCodeProcessor
// render icon
ImVec2 pos = ImVec2(ImGui::GetCursorScreenPos().x + window_padding * 3, ImGui::GetCursorScreenPos().y);
draw_list->AddRectFilled({ pos.x + 1.0f * m_scale, pos.y + 3.0f * m_scale }, { pos.x + icon_size - 1.0f * m_scale, pos.y + icon_size + 1.0f * m_scale },
ImGuiWrapper::to_ImU32(color));
add_swatch(draw_list, { pos.x + 1.0f * m_scale, pos.y + 3.0f * m_scale }, { pos.x + icon_size - 1.0f * m_scale, pos.y + icon_size + 1.0f * m_scale }, color);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(20.0 * m_scale, 6.0 * m_scale));
@@ -4139,8 +4162,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
switch (type) {
default:
case EItemType::Rect: {
draw_list->AddRectFilled({ pos.x + 1.0f * m_scale, pos.y + 3.0f * m_scale }, { pos.x + icon_size - 1.0f * m_scale, pos.y + icon_size + 1.0f * m_scale },
ImGuiWrapper::to_ImU32(color));
add_swatch(draw_list, { pos.x + 1.0f * m_scale, pos.y + 3.0f * m_scale }, { pos.x + icon_size - 1.0f * m_scale, pos.y + icon_size + 1.0f * m_scale }, color);
break;
}
case EItemType::Circle: {
@@ -4932,7 +4954,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
for (uint8_t extruder_id : used_extruders_ids) {
const std::string weight_text = format_compact_weight(model_used_filaments_g[i], imperial_units);
::sprintf(buf, imperial_units ? "%.2f in %s" : "%.2f m %s", model_used_filaments_m[i], weight_text.c_str());
append_item(EItemType::Rect, libvgcode::convert(m_viewer.get_tool_colors()[extruder_id]), { { _u8L("Extruder") + " " + std::to_string(extruder_id + 1), offsets[0]}, {buf, offsets[1]} });
append_item(EItemType::Rect, shown_filament_color(libvgcode::convert(m_viewer.get_tool_colors()[extruder_id])), { { _u8L("Extruder") + " " + std::to_string(extruder_id + 1), offsets[0]}, {buf, offsets[1]} });
// append_item(EItemType::Rect, libvgcode::convert(m_viewer.get_tool_colors()[extruder_id]), _u8L("Extruder") + " " + std::to_string(extruder_id + 1),
// true, "", 0.0f, 0.0f, offsets, used_filaments_m[extruder_id], used_filaments_g[extruder_id]);
i++;
@@ -5028,7 +5050,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
}
float checkbox_pos = std::max(predictable_icon_pos, color_print_offsets[_u8L("Display")]); // ORCA prefer predictable_icon_pos when header not reacing end
append_item(EItemType::Rect, libvgcode::convert(tool_colors[extruder_idx]), columns_offsets, false, checkbox_pos/*ORCA*/, true, []() {});
append_item(EItemType::Rect, shown_filament_color(libvgcode::convert(tool_colors[extruder_idx])), columns_offsets, false, checkbox_pos/*ORCA*/, true, []() {});
}
i++;
}
@@ -5138,7 +5160,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
const size_t extruders_count = get_extruders_count();
std::vector<ColorRGBA> last_color(extruders_count);
for (size_t i = 0; i < extruders_count; ++i) {
last_color[i] = libvgcode::convert(m_viewer.get_tool_colors()[i]);
last_color[i] = shown_filament_color(libvgcode::convert(m_viewer.get_tool_colors()[i]));
}
int last_extruder_id = 1;
int color_change_idx = 0;
@@ -5160,6 +5182,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
items.push_back({ PartialTime::EType::Print, it->extruder, last_color[it->extruder - 1], ColorRGBA::BLACK(), time_rec.second, get_used_filament_from_volume(used_filaments[color_change_idx++], it->extruder - 1) });
ColorRGBA color;
decode_color(it->color, color);
color = shown_filament_color(color);
items.push_back({ PartialTime::EType::ColorChange, it->extruder, last_color[it->extruder - 1], color, time_rec.second });
last_color[it->extruder - 1] = color;
last_extruder_id = it->extruder;
@@ -5186,11 +5209,9 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
ImVec2 pos = ImGui::GetCursorScreenPos();
pos.x -= 0.5f * ImGui::GetStyle().ItemSpacing.x;
draw_list->AddRectFilled({ pos.x + 1.0f, pos.y + 1.0f }, { pos.x + icon_size - 1.0f, pos.y + icon_size - 1.0f },
ImGuiWrapper::to_ImU32(color1));
add_swatch(draw_list, { pos.x + 1.0f, pos.y + 1.0f }, { pos.x + icon_size - 1.0f, pos.y + icon_size - 1.0f }, color1);
pos.x += icon_size;
draw_list->AddRectFilled({ pos.x + 1.0f, pos.y + 1.0f }, { pos.x + icon_size - 1.0f, pos.y + icon_size - 1.0f },
ImGuiWrapper::to_ImU32(color2));
add_swatch(draw_list, { pos.x + 1.0f, pos.y + 1.0f }, { pos.x + icon_size - 1.0f, pos.y + icon_size - 1.0f }, color2);
ImGui::SameLine(offsets[0]);
imgui.text(short_time(get_time_dhms(times.second - times.first)));
@@ -5205,8 +5226,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
ImVec2 pos = ImGui::GetCursorScreenPos();
pos.x -= 0.5f * ImGui::GetStyle().ItemSpacing.x;
draw_list->AddRectFilled({ pos.x + 1.0f, pos.y + 1.0f }, { pos.x + icon_size - 1.0f, pos.y + icon_size - 1.0f },
ImGuiWrapper::to_ImU32(color));
add_swatch(draw_list, { pos.x + 1.0f, pos.y + 1.0f }, { pos.x + icon_size - 1.0f, pos.y + icon_size - 1.0f }, color);
ImGui::SameLine(offsets[0]);
imgui.text(short_time(get_time_dhms(times.second)));