mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-14 04:55:55 +08:00
Label objects: use non-convex projection if it only contains one (Ex)Polygon, remove unused code, tidy includes
This commit is contained in:
parent
501cfb64f9
commit
f599ddca8f
@ -2340,9 +2340,8 @@ void GCodeGenerator::process_layer_single_object(
|
|||||||
const bool print_wipe_extrusions)
|
const bool print_wipe_extrusions)
|
||||||
{
|
{
|
||||||
bool first = true;
|
bool first = true;
|
||||||
int object_id = 0;
|
|
||||||
// Delay layer initialization as many layers may not print with all extruders.
|
// Delay layer initialization as many layers may not print with all extruders.
|
||||||
auto init_layer_delayed = [this, &print_instance, &layer_to_print, &first, &object_id, &gcode]() {
|
auto init_layer_delayed = [this, &print_instance, &layer_to_print, &first, &gcode]() {
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
const PrintObject &print_object = print_instance.print_object;
|
const PrintObject &print_object = print_instance.print_object;
|
||||||
@ -2358,14 +2357,7 @@ void GCodeGenerator::process_layer_single_object(
|
|||||||
m_avoid_crossing_perimeters.use_external_mp_once();
|
m_avoid_crossing_perimeters.use_external_mp_once();
|
||||||
m_last_obj_copy = this_object_copy;
|
m_last_obj_copy = this_object_copy;
|
||||||
this->set_origin(unscale(offset));
|
this->set_origin(unscale(offset));
|
||||||
if (this->config().gcode_label_objects != LabelObjectsStyle::Disabled) {
|
gcode += m_label_objects.start_object(print_instance.print_object.instances()[print_instance.instance_id], GCode::LabelObjects::IncludeName::No);
|
||||||
for (const PrintObject* po : print_object.print()->objects()) {
|
|
||||||
if (po == &print_object)
|
|
||||||
break;
|
|
||||||
++object_id;
|
|
||||||
}
|
|
||||||
gcode += m_label_objects.start_object(print_instance.print_object.instances()[print_instance.instance_id], GCode::LabelObjects::IncludeName::No);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,9 +1,43 @@
|
|||||||
#include "LabelObjects.hpp"
|
#include "LabelObjects.hpp"
|
||||||
|
|
||||||
|
#include "ClipperUtils.hpp"
|
||||||
|
#include "Model.hpp"
|
||||||
|
#include "Print.hpp"
|
||||||
|
#include "TriangleMeshSlicer.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace Slic3r::GCode {
|
namespace Slic3r::GCode {
|
||||||
|
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
Polygon instance_outline(const PrintInstance* pi)
|
||||||
|
{
|
||||||
|
ExPolygons outline;
|
||||||
|
const ModelObject* mo = pi->model_instance->get_object();
|
||||||
|
const ModelInstance* mi = pi->model_instance;
|
||||||
|
for (const ModelVolume *v : mo->volumes) {
|
||||||
|
Polygons vol_outline;
|
||||||
|
vol_outline = project_mesh(v->mesh().its,
|
||||||
|
mi->get_matrix() * v->get_matrix(),
|
||||||
|
[] {});
|
||||||
|
switch (v->type()) {
|
||||||
|
case ModelVolumeType::MODEL_PART: outline = union_ex(outline, vol_outline); break;
|
||||||
|
case ModelVolumeType::NEGATIVE_VOLUME: outline = diff_ex(outline, vol_outline); break;
|
||||||
|
default:;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The projection may contain multiple polygons, which is not supported by Klipper.
|
||||||
|
// When that happens, calculate and use a 2d convex hull instead.
|
||||||
|
if (outline.size() == 1u)
|
||||||
|
return outline.front().contour;
|
||||||
|
else
|
||||||
|
return pi->model_instance->get_object()->convex_hull_2d(pi->model_instance->get_matrix());
|
||||||
|
}
|
||||||
|
|
||||||
|
}; // anonymous namespace
|
||||||
|
|
||||||
|
|
||||||
void LabelObjects::init(const Print& print)
|
void LabelObjects::init(const Print& print)
|
||||||
{
|
{
|
||||||
@ -78,7 +112,7 @@ std::string LabelObjects::all_objects_header() const
|
|||||||
if (m_flavor == gcfKlipper) {
|
if (m_flavor == gcfKlipper) {
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
out += "EXCLUDE_OBJECT_DEFINE NAME=" + label.name;
|
out += "EXCLUDE_OBJECT_DEFINE NAME=" + label.name;
|
||||||
Polygon outline = print_instance->model_instance->get_object()->convex_hull_2d(print_instance->model_instance->get_matrix());
|
Polygon outline = instance_outline(print_instance);
|
||||||
assert(! outline.empty());
|
assert(! outline.empty());
|
||||||
outline.douglas_peucker(50000.f);
|
outline.douglas_peucker(50000.f);
|
||||||
Point center = outline.centroid();
|
Point center = outline.centroid();
|
||||||
@ -139,7 +173,7 @@ std::string LabelObjects::stop_object(const PrintInstance& print_instance) const
|
|||||||
std::string out;
|
std::string out;
|
||||||
if (m_label_objects_style == LabelObjectsStyle::Octoprint)
|
if (m_label_objects_style == LabelObjectsStyle::Octoprint)
|
||||||
out += std::string("; stop printing object ") + label.name + "\n";
|
out += std::string("; stop printing object ") + label.name + "\n";
|
||||||
else if (m_label_objects_style == LabelObjectsStyle::Firmware)
|
else if (m_label_objects_style == LabelObjectsStyle::Firmware) {
|
||||||
if (m_flavor == GCodeFlavor::gcfMarlinFirmware || m_flavor == GCodeFlavor::gcfMarlinLegacy || m_flavor == GCodeFlavor::gcfRepRapFirmware)
|
if (m_flavor == GCodeFlavor::gcfMarlinFirmware || m_flavor == GCodeFlavor::gcfMarlinLegacy || m_flavor == GCodeFlavor::gcfRepRapFirmware)
|
||||||
out += std::string("M486 S-1\n");
|
out += std::string("M486 S-1\n");
|
||||||
else if (m_flavor ==gcfKlipper)
|
else if (m_flavor ==gcfKlipper)
|
||||||
@ -147,6 +181,7 @@ std::string LabelObjects::stop_object(const PrintInstance& print_instance) const
|
|||||||
else {
|
else {
|
||||||
// Not supported by / implemented for the other firmware flavors.
|
// Not supported by / implemented for the other firmware flavors.
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#ifndef slic3r_GCode_LabelObjects_hpp_
|
#ifndef slic3r_GCode_LabelObjects_hpp_
|
||||||
#define slic3r_GCode_LabelObjects_hpp_
|
#define slic3r_GCode_LabelObjects_hpp_
|
||||||
|
|
||||||
#include "Print.hpp"
|
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
enum GCodeFlavor : unsigned char;
|
enum GCodeFlavor : unsigned char;
|
||||||
enum class LabelObjectsStyle;
|
enum class LabelObjectsStyle;
|
||||||
|
struct PrintInstance;
|
||||||
|
class Print;
|
||||||
|
|
||||||
|
|
||||||
namespace GCode {
|
namespace GCode {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user