Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Oct 7, 2021
2 parents 83158cc + 5d711f2 commit 1a48326
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 40 deletions.
4 changes: 2 additions & 2 deletions resources/ui_layout/extruder.ui
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ group:Retraction wipe
setting:idx:wipe_extra_perimeter
setting:idx:seam_gap
group:Retraction when tool is disabled (advanced settings for multi-extruder setups)
setting:idx:retract_length_toolchange
setting:idx:retract_restart_extra_toolchange
setting:label$Minimum retraction:idx:retract_length_toolchange
setting:label$Extra unretraction:idx:retract_restart_extra_toolchange
group:Preview
reset_to_filament_color
13 changes: 10 additions & 3 deletions src/libslic3r/Extruder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Tool::Tool(uint16_t id, GCodeConfig* config) :
Extruder::Extruder(uint16_t id, GCodeConfig* config) :
Tool(id, config)
{
// set extra_toolchange to be init for when it will be new current extruder
m_restart_extra_toolchange = retract_restart_extra_toolchange();

// cache values that are going to be called often
m_e_per_mm3 = this->extrusion_multiplier();
Expand Down Expand Up @@ -46,7 +48,7 @@ double Tool::extrude(double dE)
The restart_extra argument sets the extra length to be used for
unretraction. If we're actually performing a retraction, any restart_extra
value supplied will overwrite the previous one if any. */
double Tool::retract(double length, double restart_extra)
double Tool::retract(double length, double restart_extra, double restart_extra_toolchange)
{
// in case of relative E distances we always reset to 0 before any output
if (m_config->use_relative_e_distances)
Expand All @@ -56,17 +58,22 @@ double Tool::retract(double length, double restart_extra)
m_E -= to_retract;
m_absolute_E -= to_retract;
m_retracted += to_retract;
m_restart_extra = restart_extra;
if(!std::isnan(restart_extra))
m_restart_extra = restart_extra;
}
if (!std::isnan(restart_extra_toolchange))
m_restart_extra_toolchange = restart_extra_toolchange;
return to_retract;
}

double Tool::unretract()
{
double dE = m_retracted + m_restart_extra;
double dE = m_retracted + m_restart_extra + m_restart_extra_toolchange;
this->extrude(dE);
m_retracted = 0.;
m_restart_extra = 0.;
if(m_restart_extra_toolchange != 0)
m_restart_extra_toolchange = 0.;
return dE;
}

Expand Down
4 changes: 3 additions & 1 deletion src/libslic3r/Extruder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ class Tool
m_absolute_E = 0;
m_retracted = 0;
m_restart_extra = 0;
m_restart_extra_toolchange = 0; // note: can't call retract_restart_extra_toolchange(); because virtual inheritance doesn't work when only the tool is build (constructor)
}

uint16_t id() const { return m_id; }

virtual double extrude(double dE);
virtual double retract(double length, double restart_extra);
virtual double retract(double length, double restart_extra, double restart_extra_from_toolchange);
virtual double unretract();
double E() const { return m_E; }
void reset_E() { m_E = 0.; }
Expand Down Expand Up @@ -67,6 +68,7 @@ class Tool
double m_retracted;
// When retracted, this value stores the extra amount of priming on deretraction.
double m_restart_extra;
double m_restart_extra_toolchange;
double m_e_per_mm3;
};

Expand Down
18 changes: 11 additions & 7 deletions src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1218,19 +1218,20 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu
if (pos_dot != std::string::npos && pos_dot > 0)
object_name = object_name.substr(0, pos_dot);
//get bounding box for the instance
BoundingBoxf3 raw_bbox = print_object->model_object()->raw_mesh_bounding_box();
BoundingBoxf3 m_bounding_box = print_instance.model_instance->transform_bounding_box(raw_bbox);
//BoundingBoxf3 raw_bbox = print_object->model_object()->raw_mesh_bounding_box();
//BoundingBoxf3 bounding_box;// = print_instance.model_instance->transform_bounding_box(raw_bbox);
BoundingBoxf3 bounding_box = print_object->model_object()->instance_bounding_box(*print_instance.model_instance, false);
if (global_bounding_box.size().norm() == 0) {
global_bounding_box = m_bounding_box;
global_bounding_box = bounding_box;
} else {
global_bounding_box.merge(m_bounding_box);
global_bounding_box.merge(bounding_box);
}
if (this->config().gcode_label_objects) {
_write_format(file, "; object:{\"name\":\"%s\",\"id\":\"%s id:%d copy %d\",\"object_center\":[%f,%f,%f],\"boundingbox_center\":[%f,%f,%f],\"boundingbox_size\":[%f,%f,%f]}\n",
object_name.c_str(), print_object->model_object()->name.c_str(), this->m_ordered_objects.size() - 1, copy_id,
m_bounding_box.center().x(), m_bounding_box.center().y(), 0.,
m_bounding_box.center().x(), m_bounding_box.center().y(), m_bounding_box.center().z(),
m_bounding_box.size().x(), m_bounding_box.size().y(), m_bounding_box.size().z()
bounding_box.center().x(), bounding_box.center().y(), 0.,
bounding_box.center().x(), bounding_box.center().y(), bounding_box.center().z(),
bounding_box.size().x(), bounding_box.size().y(), bounding_box.size().z()
);
}
copy_id++;
Expand Down Expand Up @@ -1468,6 +1469,9 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu
m_writer.toolchange(initial_extruder_id);
}

// ensure the first tool doesn't "extra_retract"
m_writer.unretract();

//write temps after custom gcodes to ensure the temperature are good. (after tool selection)
if ((initial_extruder_id != (uint16_t)-1) && !this->config().start_gcode_manual && print.config().first_layer_temperature.get_at(initial_extruder_id) != 0)
this->_print_first_layer_extruder_temperatures(file, print, start_gcode, initial_extruder_id, true);
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/GCode/SeamPlacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ Point SeamPlacer::get_seam(const Layer& layer, SeamPosition seam_position,
Point nearest = polygon.point_projection(xy_lambda);
Vec3d polygon_3dpoint{ unscaled(nearest.x()), unscaled(nearest.y()), (double)layer.print_z };
double test_lambda_dist = (polygon_3dpoint - test_lambda_pos).norm();
double sphere_radius = po->model_object()->instances.front()->transform_bounding_box(v->mesh().bounding_box(), true).size().x() / 2;
double sphere_radius = po->model_object()->instance_bounding_box(0, true).size().x() / 2;
//if (test_lambda_dist > sphere_radius)
// continue;

Expand Down
8 changes: 6 additions & 2 deletions src/libslic3r/GCodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,12 +601,14 @@ std::string GCodeWriter::retract(bool before_wipe)
return this->_retract(
factor * config_region->print_retract_length,
factor * m_tool->retract_restart_extra(),
NAN,
"retract"
);
}
return this->_retract(
factor * m_tool->retract_length(),
factor * m_tool->retract_restart_extra(),
NAN,
"retract"
);
}
Expand All @@ -617,12 +619,13 @@ std::string GCodeWriter::retract_for_toolchange(bool before_wipe)
assert(factor >= 0. && factor <= 1. + EPSILON);
return this->_retract(
factor * m_tool->retract_length_toolchange(),
NAN,
factor * m_tool->retract_restart_extra_toolchange(),
"retract for toolchange"
);
}

std::string GCodeWriter::_retract(double length, double restart_extra, const std::string &comment)
std::string GCodeWriter::_retract(double length, double restart_extra, double restart_extra_toolchange, const std::string &comment)
{
std::ostringstream gcode;

Expand All @@ -637,9 +640,10 @@ std::string GCodeWriter::_retract(double length, double restart_extra, const std
double area = d * d * PI/4;
length = length * area;
restart_extra = restart_extra * area;
restart_extra_toolchange = restart_extra_toolchange * area;
}

double dE = m_tool->retract(length, restart_extra);
double dE = m_tool->retract(length, restart_extra, restart_extra_toolchange);
assert(dE >= 0);
assert(dE < 10000000);
if (dE != 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/GCodeWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class GCodeWriter {
Vec3d m_pos = Vec3d::Zero();

std::string _travel_to_z(double z, const std::string &comment);
std::string _retract(double length, double restart_extra, const std::string &comment);
std::string _retract(double length, double restart_extra, double restart_extra_toolchange, const std::string &comment);

// if positive, it's set, and the next lift wil have this extra lift
double extra_lift = 0;
Expand Down
22 changes: 10 additions & 12 deletions src/libslic3r/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,10 +805,9 @@ const BoundingBoxf3& ModelObject::bounding_box() const
{
if (! m_bounding_box_valid) {
m_bounding_box_valid = true;
BoundingBoxf3 raw_bbox = this->raw_mesh_bounding_box();
m_bounding_box.reset();
for (const ModelInstance *i : this->instances)
m_bounding_box.merge(i->transform_bounding_box(raw_bbox));
for (size_t i = 0; i < instances.size(); ++i)
m_bounding_box.merge(instance_bounding_box(i, false));
}
return m_bounding_box;
}
Expand Down Expand Up @@ -927,16 +926,20 @@ const BoundingBoxf3& ModelObject::raw_bounding_box() const
return m_raw_bounding_box;
}

// This returns an accurate snug bounding box of the transformed object instance, without the translation applied.
// This returns an accurate snug bounding box of the transformed object instance, with or without the translation applied.
BoundingBoxf3 ModelObject::instance_bounding_box(size_t instance_idx, bool dont_translate) const
{
return instance_bounding_box(*this->instances[instance_idx], dont_translate);
}
BoundingBoxf3 ModelObject::instance_bounding_box(const ModelInstance & instance, bool dont_translate) const
{
BoundingBoxf3 bb;
const Transform3d& inst_matrix = this->instances[instance_idx]->get_transformation().get_matrix(dont_translate);
for (ModelVolume *v : this->volumes)
const Transform3d& inst_matrix = instance.get_transformation().get_matrix(dont_translate);
for (ModelVolume* v : this->volumes)
{
if (v->is_model_part())
bb.merge(v->mesh().transformed_bounding_box(inst_matrix * v->get_matrix()));
}
}
return bb;
}

Expand Down Expand Up @@ -1925,11 +1928,6 @@ BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh& mes
return bbox;
}

BoundingBoxf3 ModelInstance::transform_bounding_box(const BoundingBoxf3 &bbox, bool dont_translate) const
{
return bbox.transformed(get_matrix(dont_translate));
}

Vec3d ModelInstance::transform_vector(const Vec3d& v, bool dont_translate) const
{
return get_matrix(dont_translate) * v;
Expand Down
3 changes: 1 addition & 2 deletions src/libslic3r/Model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ class ModelObject final : public ObjectBase
const BoundingBoxf3& raw_bounding_box() const;
// A snug bounding box around the transformed non-modifier object volumes.
BoundingBoxf3 instance_bounding_box(size_t instance_idx, bool dont_translate = false) const;
BoundingBoxf3 instance_bounding_box(const ModelInstance& instance, bool dont_translate = false) const;
// A snug bounding box of non-transformed (non-rotated, non-scaled, non-translated) sum of non-modifier object volumes.
const BoundingBoxf3& raw_mesh_bounding_box() const;
// A snug bounding box of non-transformed (non-rotated, non-scaled, non-translated) sum of all object volumes.
Expand Down Expand Up @@ -876,8 +877,6 @@ class ModelInstance final : public ObjectBase
void transform_mesh(TriangleMesh* mesh, bool dont_translate = false) const;
// Calculate a bounding box of a transformed mesh. To be called on an external mesh.
BoundingBoxf3 transform_mesh_bounding_box(const TriangleMesh& mesh, bool dont_translate = false) const;
// Transform an external bounding box.
BoundingBoxf3 transform_bounding_box(const BoundingBoxf3 &bbox, bool dont_translate = false) const;
// Transform an external vector.
Vec3d transform_vector(const Vec3d& v, bool dont_translate = false) const;
// To be called on an external polygon. It does not translate the polygon, only rotates and scales.
Expand Down
9 changes: 5 additions & 4 deletions src/libslic3r/PerimeterGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ void PerimeterGenerator::process()
last = diff_ex(last, unsupported_filtered);
//ExPolygons no_bridge = diff_ex(offset_ex(unbridgeable, ext_perimeter_width * 3 / 2), last);
//bridges_temp = diff_ex(bridges_temp, no_bridge);
unsupported_filtered = diff_ex(offset_ex(bridges_temp, ext_perimeter_width * 3 / 2), offset_ex(unbridgeable, ext_perimeter_width * 2, jtSquare));
coordf_t bridged_infill_margin = config->bridged_infill_margin.get_abs_value(ext_perimeter_width);
unsupported_filtered = diff_ex(offset_ex(bridges_temp, bridged_infill_margin), offset_ex(unbridgeable, ext_perimeter_width * 2, jtSquare));
unsupported_filtered = intersection_ex(unsupported_filtered, reference);
} else {
ExPolygons unbridgeable = intersection_ex(unsupported, diff_ex(unsupported_filtered, offset_ex(bridgeable_simplified, ext_perimeter_width / 2)));
Expand Down Expand Up @@ -425,9 +426,8 @@ void PerimeterGenerator::process()
}

//offset by perimeter spacing because the simplify may have reduced it a bit.
if (!bridgeable_simplified.empty())
bridgeable_simplified = offset_ex(bridgeable_simplified, double(perimeter_spacing) / 1.9);
if (!bridgeable_simplified.empty()) {
bridgeable_simplified = offset_ex(bridgeable_simplified, double(perimeter_spacing));
overhangs_unsupported = diff_ex(overhangs_unsupported, bridgeable_simplified, true);
}
}
Expand Down Expand Up @@ -742,8 +742,9 @@ void PerimeterGenerator::process()
fill_clip = offset_ex(last, double(ext_perimeter_spacing / 2) - scale_d(infill_spacing_unscaled / 2));
last = intersection_ex(inner_polygons, last);
//{
// static int isazfn = 0;
// std::stringstream stri;
// stri << this->layer->id() << "_1_"<< i <<"_only_one_peri"<< ".svg";
// stri << this->layer->id() << "_" << i << "_"<< isazfn++ <<"_only_one_peri"<< ".svg";
// SVG svg(stri.str());
// svg.draw(to_polylines(oldLast), "orange");
// svg.draw(to_polylines(fill_clip), "purple");
Expand Down
8 changes: 5 additions & 3 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ void PrintConfigDef::init_fff_params()
"\nIf using marlin, M220 B/R is used to save the speed override before the wipe tower print.");
def->sidetext = L("%");
def->min = 0;
def->max = 200;
def->max = 400;
def->mode = comExpert;
def->is_vector_extruder = true;
def->set_default_value(new ConfigOptionFloats { 0 });
Expand Down Expand Up @@ -3281,7 +3281,8 @@ void PrintConfigDef::init_fff_params()
def->full_label = L("Retraction Length (Toolchange)");
def->tooltip = L("When retraction is triggered before changing tool, filament is pulled back "
"by the specified amount (the length is measured on raw filament, before it enters "
"the extruder).");
"the extruder)."
"\nNote: This value will be unretracted when this extruder will load the next time.");
def->sidetext = L("mm (zero to disable)");
def->mode = comExpert;
def->min = 0;
Expand Down Expand Up @@ -3361,7 +3362,8 @@ void PrintConfigDef::init_fff_params()
def->label = L("Extra length on restart");
def->full_label = L("Extrat length on toolchange restart");
def->tooltip = L("When the retraction is compensated after changing tool, the extruder will push "
"this additional amount of filament.");
"this additional amount of filament"
" (but not on the first extruder after start, as it should already be loaded).");
def->sidetext = L("mm");
def->mode = comExpert;
def->is_vector_extruder = true;
Expand Down
15 changes: 13 additions & 2 deletions src/libslic3r/PrintObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,21 @@ namespace Slic3r {
diameter_max = std::max(diameter_max, dist);
diameter_sum += dist;
}
//also use center of lines to check it's not a rectangle
double diameter_line_min = std::numeric_limits<float>::max(), diameter_line_max = 0;
Lines hole_lines = hole.lines();
for (Line l : hole_lines) {
Point midline = (l.a + l.b) / 2;
double dist = center.distance_to(midline);
diameter_line_min = std::min(diameter_line_min, dist);
diameter_line_max = std::max(diameter_line_max, dist);
}


// SCALED_EPSILON was a bit too harsh. Now using a config, as some may want some harsh setting and some don't.
coord_t max_variation = std::max(SCALED_EPSILON, scale_(this->m_layers[layer_idx]->m_regions[region_idx]->region()->config().hole_to_polyhole_threshold.get_abs_value(unscaled(diameter_sum / hole.points.size()))));
bool twist = this->m_layers[layer_idx]->m_regions[region_idx]->region()->config().hole_to_polyhole_twisted.value;
if (diameter_max - diameter_min < max_variation * 2) {
if (diameter_max - diameter_min < max_variation * 2 && diameter_line_max - diameter_line_min < max_variation * 2) {
layerid2center[layer_idx].emplace_back(
std::tuple<Point, float, int, coord_t, bool>{center, diameter_max, layer->m_regions[region_idx]->region()->config().perimeter_extruder.value, max_variation, twist}, & hole);
}
Expand Down Expand Up @@ -814,7 +825,6 @@ namespace Slic3r {
}
} else if (
opt_key == "bottom_solid_min_thickness"
|| opt_key == "bridged_infill_margin"
|| opt_key == "ensure_vertical_shell_thickness"
|| opt_key == "fill_density"
|| opt_key == "interface_shells"
Expand Down Expand Up @@ -857,6 +867,7 @@ namespace Slic3r {
steps.emplace_back(posInfill);
} else if (
opt_key == "bridge_angle"
|| opt_key == "bridged_infill_margin"
|| opt_key == "extra_perimeters"
|| opt_key == "extra_perimeters_odd_layers"
|| opt_key == "external_infill_margin"
Expand Down
Loading

0 comments on commit 1a48326

Please sign in to comment.