Fix contour extrusion path logic and improve GCode extrusion handling

This commit is contained in:
Aleksandr Dobkin
2026-03-19 01:32:51 -07:00
parent 4314f5d804
commit 1cc82873f4
3 changed files with 24 additions and 23 deletions

View File

@@ -63,10 +63,14 @@ static bool contour_extrusion_path(LayerRegion *region, const sla::IndexedMesh &
int num_segments = int(std::ceil(length_mm / resolution_mm)); int num_segments = int(std::ceil(length_mm / resolution_mm));
Vec2d delta = line.vector(); Vec2d delta = line.vector();
for (int i = 0; i < num_segments+1; i++) { if (num_segments == 0) {
Vec2d p = p1d + delta*i/num_segments; continue;
}
coordf_t x = p.x(); for (int i = 0; i < num_segments + 1; i++) {
Vec2d p = p1d + delta * i / num_segments;
coordf_t x = p.x();
coordf_t y = p.y(); coordf_t y = p.y();
sla::IndexedMesh::hit_result hit_up = mesh.query_ray_hit({x, y, mesh_z}, {0.0, 0.0, 1.0}); sla::IndexedMesh::hit_result hit_up = mesh.query_ray_hit({x, y, mesh_z}, {0.0, 0.0, 1.0});
@@ -116,24 +120,22 @@ static bool contour_extrusion_path(LayerRegion *region, const sla::IndexedMesh &
was_contoured = true; was_contoured = true;
} }
Vec3d new_point = {p.x(), p.y(), d}; Vec3d new_point = {p.x(), p.y(), d};
if (contoured_points.size() > 2) { if (contoured_points.size() >= 2) {
double dist = Linef3::distance_to_infinite_squared( double dist = Linef3::distance_to_infinite_squared(new_point, contoured_points[contoured_points.size() - 2],
contoured_points[contoured_points.size() - 2], contoured_points[contoured_points.size() - 1]);
contoured_points[contoured_points.size() - 1], if (dist < EPSILON * EPSILON) {
new_point); contoured_points[contoured_points.size() - 1] = new_point;
if (dist < EPSILON) { continue;
contoured_points[contoured_points.size() - 1] = new_point; }
continue; }
}
}
contoured_points.push_back(new_point); contoured_points.push_back(new_point);
} }
} }
if (!was_contoured) { if (!was_contoured) {
return false; return false;
} }

View File

@@ -6760,10 +6760,8 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
if (z < 0.1) { if (z < 0.1) {
throw RuntimeError("GCode: very low z"); throw RuntimeError("GCode: very low z");
} }
gcode += m_writer.extrude_to_xyz( gcode += m_writer.extrude_to_xyz(Vec3d(dest2d.x(), dest2d.y(), z), e,
Vec3d(dest2d.x(), dest2d.y(), z), GCodeWriter::full_gcode_comment ? tempDescription : "");
e,
tempDescription + "; z_diff " + std::to_string(z_diff) + " " + ExtrusionEntity::role_to_string(path.role()) + "; eratio " + std::to_string(extrusion_ratio));
} else if (sloped == nullptr) { } else if (sloped == nullptr) {
// Normal extrusion // Normal extrusion

View File

@@ -732,7 +732,8 @@ void PrintObject::contour_z()
ModelInstance *inst = m_model_object->instances.front(); ModelInstance *inst = m_model_object->instances.front();
Point center_offset = this->center_offset(); Point center_offset = this->center_offset();
Geometry::Transformation trans = inst->get_transformation(); Geometry::Transformation trans = inst->get_transformation();
double z = trans.get_offset().z() - unscale<double>(this->height()) / 2;
double z = this->m_model_object->min_z();
trans.set_offset(Vec3d(-unscale<double>(center_offset.x()), -unscale<double>(center_offset.y()), 0)); trans.set_offset(Vec3d(-unscale<double>(center_offset.x()), -unscale<double>(center_offset.y()), 0));
mesh.transform(trans.get_matrix()); mesh.transform(trans.get_matrix());