Update seam visualization to support scarf seams - WIP

This commit is contained in:
Martin Šach 2024-08-12 14:28:03 +02:00 committed by Lukas Matena
parent aa6132ebb6
commit bc34b60ac3
2 changed files with 19 additions and 24 deletions

View File

@ -2838,33 +2838,23 @@ void GCodeProcessor::process_G1(const std::array<std::optional<double>, 4>& axes
if (m_time_processor.machines[0].blocks.size() > TimeProcessor::Planner::refresh_threshold)
calculate_time(m_result, TimeProcessor::Planner::queue_size);
if (m_seams_detector.is_active()) {
// check for seam starting vertex
if (type == EMoveType::Extrude && m_extrusion_role == GCodeExtrusionRole::ExternalPerimeter && !m_seams_detector.has_first_vertex())
m_seams_detector.set_first_vertex(m_result.moves.back().position - m_extruder_offsets[m_extruder_id]);
// check for seam ending vertex and store the resulting move
else if ((type != EMoveType::Extrude || (m_extrusion_role != GCodeExtrusionRole::ExternalPerimeter && m_extrusion_role != GCodeExtrusionRole::OverhangPerimeter)) && m_seams_detector.has_first_vertex()) {
auto set_end_position = [this](const Vec3f& pos) {
m_end_position[X] = pos.x(); m_end_position[Y] = pos.y(); m_end_position[Z] = pos.z();
};
if (m_seams_detector.is_active() && (
type != EMoveType::Extrude
|| (
m_extrusion_role != GCodeExtrusionRole::ExternalPerimeter
&& m_extrusion_role != GCodeExtrusionRole::OverhangPerimeter
)
)) {
const Vec3f curr_pos(m_end_position[X], m_end_position[Y], m_end_position[Z]);
const Vec3f new_pos = m_result.moves.back().position - m_extruder_offsets[m_extruder_id];
const Vec3f curr_pos(m_end_position[X], m_end_position[Y], m_end_position[Z]);
const Vec3f new_pos = m_result.moves.back().position - m_extruder_offsets[m_extruder_id];
const std::optional<Vec3f> first_vertex = m_seams_detector.get_first_vertex();
// the threshold value = 0.0625f == 0.25 * 0.25 is arbitrary, we may find some smarter condition later
m_end_position = create_axis_coords(new_pos + m_z_offset * Vec3f::UnitZ());
store_move_vertex(EMoveType::Seam);
m_end_position = create_axis_coords(curr_pos);
if ((new_pos - *first_vertex).squaredNorm() < 0.0625f) {
set_end_position(0.5f * (new_pos + *first_vertex) + m_z_offset * Vec3f::UnitZ());
store_move_vertex(EMoveType::Seam);
set_end_position(curr_pos);
}
m_seams_detector.activate(false);
}
}
else if (type == EMoveType::Extrude && m_extrusion_role == GCodeExtrusionRole::ExternalPerimeter) {
m_seams_detector.activate(false);
} else if (type == EMoveType::Extrude && m_extrusion_role == GCodeExtrusionRole::ExternalPerimeter) {
m_seams_detector.activate(true);
m_seams_detector.set_first_vertex(m_result.moves.back().position - m_extruder_offsets[m_extruder_id]);
}
// store move

View File

@ -778,6 +778,11 @@ namespace Slic3r {
void update_estimated_statistics();
double extract_absolute_position_on_axis(Axis axis, const GCodeReader::GCodeLine& line, double area_filament_cross_section);
AxisCoords create_axis_coords(const Vec3f &vec) {
return AxisCoords{vec[0], vec[1], vec[2], 0};
}
};
} /* namespace Slic3r */