From 76ce53f09563de6f89460efb0300a675193e0823 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 18 Jan 2022 15:53:59 +0100 Subject: [PATCH] Tech ENABLE_Z_OFFSET_CORRECTION - Correction of toolpaths zs when z offset is set --- src/libslic3r/GCode/GCodeProcessor.cpp | 23 +++++++++++++++++++++++ src/libslic3r/GCode/GCodeProcessor.hpp | 3 +++ src/libslic3r/Technologies.hpp | 2 ++ 3 files changed, 28 insertions(+) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index f54e38eec..3e7478c05 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -899,6 +899,12 @@ void GCodeProcessor::apply_config(const PrintConfig& config) if (spiral_vase != nullptr) m_spiral_vase_active = spiral_vase->value; #endif // ENABLE_SPIRAL_VASE_LAYERS + +#if ENABLE_Z_OFFSET_CORRECTION + const ConfigOptionFloat* z_offset = config.option("z_offset"); + if (z_offset != nullptr) + m_z_offset = z_offset->value; +#endif // ENABLE_Z_OFFSET_CORRECTION } void GCodeProcessor::apply_config(const DynamicPrintConfig& config) @@ -1148,6 +1154,12 @@ void GCodeProcessor::apply_config(const DynamicPrintConfig& config) if (spiral_vase != nullptr) m_spiral_vase_active = spiral_vase->value; #endif // ENABLE_SPIRAL_VASE_LAYERS + +#if ENABLE_Z_OFFSET_CORRECTION + const ConfigOptionFloat* z_offset = config.option("z_offset"); + if (z_offset != nullptr) + m_z_offset = z_offset->value; +#endif // ENABLE_Z_OFFSET_CORRECTION } void GCodeProcessor::enable_stealth_time_estimator(bool enabled) @@ -1178,6 +1190,9 @@ void GCodeProcessor::reset() m_forced_height = 0.0f; m_mm3_per_mm = 0.0f; m_fan_speed = 0.0f; +#if ENABLE_Z_OFFSET_CORRECTION + m_z_offset = 0.0f; +#endif // ENABLE_Z_OFFSET_CORRECTION m_extrusion_role = erNone; m_extruder_id = 0; @@ -2704,7 +2719,11 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line) // the threshold value = 0.0625f == 0.25 * 0.25 is arbitrary, we may find some smarter condition later if ((new_pos - *first_vertex).squaredNorm() < 0.0625f) { +#if ENABLE_Z_OFFSET_CORRECTION + set_end_position(0.5f * (new_pos + *first_vertex) + m_z_offset * Vec3f::UnitZ()); +#else set_end_position(0.5f * (new_pos + *first_vertex)); +#endif // ENABLE_Z_OFFSET_CORRECTION store_move_vertex(EMoveType::Seam); set_end_position(curr_pos); } @@ -3187,7 +3206,11 @@ void GCodeProcessor::store_move_vertex(EMoveType type) m_extrusion_role, m_extruder_id, m_cp_color.current, +#if ENABLE_Z_OFFSET_CORRECTION + Vec3f(m_end_position[X], m_end_position[Y], m_processing_start_custom_gcode ? m_first_layer_height : m_end_position[Z] - m_z_offset) + m_extruder_offsets[m_extruder_id], +#else Vec3f(m_end_position[X], m_end_position[Y], m_processing_start_custom_gcode ? m_first_layer_height : m_end_position[Z]) + m_extruder_offsets[m_extruder_id], +#endif // ENABLE_Z_OFFSET_CORRECTION m_end_position[E] - m_start_position[E], m_feedrate, m_width, diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 2b6ee9cea..5132825e5 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -521,6 +521,9 @@ namespace Slic3r { float m_forced_height; // mm float m_mm3_per_mm; float m_fan_speed; // percentage +#if ENABLE_Z_OFFSET_CORRECTION + float m_z_offset; // mm +#endif // ENABLE_Z_OFFSET_CORRECTION ExtrusionRole m_extrusion_role; unsigned char m_extruder_id; ExtruderColors m_extruder_colors; diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index f2dddca07..3f9dac82a 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -43,6 +43,8 @@ // Enable detection of layers for spiral vase prints #define ENABLE_SPIRAL_VASE_LAYERS (1 && ENABLE_2_4_1_RC) +// Enable correction of toolpaths when z offset is set +#define ENABLE_Z_OFFSET_CORRECTION (1 && ENABLE_2_4_1_RC) #endif // _prusaslicer_technologies_h_