diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index dc12925ab1..791efaf835 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -2624,7 +2624,7 @@ void GCodeProcessor::process_G1(const std::array, 4>& axes if (volume_extruded_filament != 0.) m_used_filaments.increase_caches(volume_extruded_filament, m_extruder_id, area_filament_cross_section * m_parking_position, - area_filament_cross_section * m_extra_loading_move); + area_filament_cross_section * m_extra_loading_move); const EMoveType type = move_type(delta_pos); if (type == EMoveType::Extrude) { @@ -2638,9 +2638,16 @@ void GCodeProcessor::process_G1(const std::array, 4>& axes #endif // ENABLE_GCODE_VIEWER_DATA_CHECKING if (m_forced_height > 0.0f) + // use height coming from the gcode tags m_height = m_forced_height; - else if (m_layer_id == 0) - m_height = m_first_layer_height + m_z_offset; + else if (m_layer_id == 0) { // first layer + if (m_end_position[Z] > 0.0f) + // use the current (clamped) z, if greater than zero + m_height = std::min(m_end_position[Z], 2.0f); + else + // use the first layer height + m_height = m_first_layer_height + m_z_offset; + } else if (origin == G1DiscretizationOrigin::G1) { if (m_end_position[Z] > m_extruded_last_z + EPSILON && delta_pos[Z] == 0.0) m_height = m_end_position[Z] - m_extruded_last_z; @@ -2649,9 +2656,6 @@ void GCodeProcessor::process_G1(const std::array, 4>& axes if (m_height == 0.0f) m_height = DEFAULT_TOOLPATH_HEIGHT; - if (m_end_position[Z] == 0.0f || (m_extrusion_role == GCodeExtrusionRole::Custom && m_layer_id == 0)) - m_end_position[Z] = m_height; - if (origin == G1DiscretizationOrigin::G1) m_extruded_last_z = m_end_position[Z]; m_options_z_corrector.update(m_height); @@ -2661,6 +2665,7 @@ void GCodeProcessor::process_G1(const std::array, 4>& axes #endif // ENABLE_GCODE_VIEWER_DATA_CHECKING if (m_forced_width > 0.0f) + // use width coming from the gcode tags m_width = m_forced_width; else if (m_extrusion_role == GCodeExtrusionRole::ExternalPerimeter) // cross section: rectangle diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 14e73e0484..5cc55be5ff 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -2264,16 +2264,16 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) // layers zs/ranges const double* const last_z = m_layers.empty() ? nullptr : &m_layers.get_zs().back(); const double z = static_cast(move.position.z()); - if (last_z == nullptr || z < *last_z - EPSILON || *last_z + EPSILON < z) { + if (move.extrusion_role != GCodeExtrusionRole::Custom && + (last_z == nullptr || z < *last_z - EPSILON || *last_z + EPSILON < z)) { // start a new layer const size_t start_it = (m_layers.empty() && first_travel_s_id != 0) ? first_travel_s_id : last_travel_s_id; m_layers.append(z, { start_it, move_id }); } - else if (!move.internal_only) { + else if (!m_layers.empty() && !move.internal_only) // update last layer m_layers.get_ranges().back().last = move_id; - } - + // extruder ids m_extruder_ids.emplace_back(move.extruder_id); // roles