WIP: MMU segmentation without top and bottom layers

This commit is contained in:
Lukáš Hejl 2021-04-19 07:04:50 +02:00
parent e3c33844d5
commit f49ceb1e0f
6 changed files with 1322 additions and 11 deletions

View file

@ -1567,7 +1567,12 @@ namespace Slic3r {
m_curr_object.geometry.custom_supports.push_back(get_attribute_value_string(attributes, num_attributes, CUSTOM_SUPPORTS_ATTR));
m_curr_object.geometry.custom_seam.push_back(get_attribute_value_string(attributes, num_attributes, CUSTOM_SEAM_ATTR));
m_curr_object.geometry.mmu_segmentation.push_back(get_attribute_value_string(attributes, num_attributes, MMU_SEGMENTATION_ATTR));
// m_curr_object.geometry.mmu_segmentation.push_back(get_attribute_value_string(attributes, num_attributes, MMU_SEGMENTATION_ATTR));
// FIXME Lukas H.: This is only for backward compatibility with older 3MF test files. Removes this when it is not necessary.
if(get_attribute_value_string(attributes, num_attributes, MMU_SEGMENTATION_ATTR) != "")
m_curr_object.geometry.mmu_segmentation.push_back(get_attribute_value_string(attributes, num_attributes, MMU_SEGMENTATION_ATTR));
else
m_curr_object.geometry.mmu_segmentation.push_back(get_attribute_value_string(attributes, num_attributes, "slic3rpe:mmu_painting"));
return true;
}

View file

@ -2081,8 +2081,10 @@ bool model_volume_list_changed(const ModelObject &model_object_old, const ModelO
bool model_custom_supports_data_changed(const ModelObject& mo, const ModelObject& mo_new) {
assert(! model_volume_list_changed(mo, mo_new, ModelVolumeType::MODEL_PART));
assert(mo.volumes.size() == mo_new.volumes.size());
for (size_t i=0; i<mo.volumes.size(); ++i) {
// FIXME Lukas H.: Because of adding another mesh modifiers when slicing, then assert triggered and possible crash. It requires changing the integration of MMU segmentation.
// assert(mo.volumes.size() == mo_new.volumes.size());
// for (size_t i=0; i<mo.volumes.size(); ++i) {
for (size_t i=0; i<std::min(mo.volumes.size(), mo_new.volumes.size()); ++i) {
if (! mo_new.volumes[i]->supported_facets.timestamp_matches(mo.volumes[i]->supported_facets))
return true;
}
@ -2091,8 +2093,10 @@ bool model_custom_supports_data_changed(const ModelObject& mo, const ModelObject
bool model_custom_seam_data_changed(const ModelObject& mo, const ModelObject& mo_new) {
assert(! model_volume_list_changed(mo, mo_new, ModelVolumeType::MODEL_PART));
assert(mo.volumes.size() == mo_new.volumes.size());
for (size_t i=0; i<mo.volumes.size(); ++i) {
// FIXME Lukas H.: Because of adding another mesh modifiers when slicing, then assert triggered and possible crash. It requires changing the integration of MMU segmentation.
// assert(mo.volumes.size() == mo_new.volumes.size());
// for (size_t i=0; i<mo.volumes.size(); ++i) {
for (size_t i=0; i<std::min(mo.volumes.size(), mo_new.volumes.size()); ++i) {
if (! mo_new.volumes[i]->seam_facets.timestamp_matches(mo.volumes[i]->seam_facets))
return true;
}
@ -2101,8 +2105,10 @@ bool model_custom_seam_data_changed(const ModelObject& mo, const ModelObject& mo
bool model_mmu_segmentation_data_changed(const ModelObject& mo, const ModelObject& mo_new) {
assert(! model_volume_list_changed(mo, mo_new, ModelVolumeType::MODEL_PART));
assert(mo.volumes.size() == mo_new.volumes.size());
for (size_t i=0; i<mo_new.volumes.size(); ++i) {
// FIXME Lukas H.: Because of adding another mesh modifiers when slicing, then assert triggered and possible crash. It requires changing the integration of MMU segmentation.
// assert(mo.volumes.size() == mo_new.volumes.size());
// for (size_t i=0; i<mo.volumes.size(); ++i) {
for (size_t i=0; i<std::min(mo.volumes.size(), mo_new.volumes.size()); ++i) {
if (! mo_new.volumes[i]->mmu_segmentation_facets.timestamp_matches(mo.volumes[i]->mmu_segmentation_facets))
return true;
}

View file

@ -487,6 +487,7 @@ enum class ModelVolumeType : int {
PARAMETER_MODIFIER,
SUPPORT_ENFORCER,
SUPPORT_BLOCKER,
MMU_SEGMENTATION
};
enum class EnforcerBlockerType : int8_t {
@ -600,6 +601,7 @@ public:
bool is_support_enforcer() const { return m_type == ModelVolumeType::SUPPORT_ENFORCER; }
bool is_support_blocker() const { return m_type == ModelVolumeType::SUPPORT_BLOCKER; }
bool is_support_modifier() const { return m_type == ModelVolumeType::SUPPORT_BLOCKER || m_type == ModelVolumeType::SUPPORT_ENFORCER; }
bool is_mmu_segmentation() const { return m_type == ModelVolumeType::MMU_SEGMENTATION; }
t_model_material_id material_id() const { return m_material_id; }
void set_material_id(t_model_material_id material_id);
ModelMaterial* material() const;
@ -681,6 +683,9 @@ public:
this->mmu_segmentation_facets.set_new_unique_id();
}
const std::vector<ExPolygons> &get_mmu_segmentation_expolygons() const { return m_mmu_segmentation_expolygons; }
void set_mmu_segmentation_expolygons(const std::vector<ExPolygons> &expoly) { m_mmu_segmentation_expolygons = expoly; }
protected:
friend class Print;
friend class SLAPrint;
@ -705,6 +710,8 @@ private:
// The convex hull of this model's mesh.
std::shared_ptr<const TriangleMesh> m_convex_hull;
Geometry::Transformation m_transformation;
// List of segmented regions (ExPolygons) indexed by extruder index
std::vector<ExPolygons> m_mmu_segmentation_expolygons;
// flag to optimize the checking if the volume is splittable
// -1 -> is unknown value (before first cheking)
@ -744,7 +751,8 @@ private:
ObjectBase(other),
name(other.name), source(other.source), m_mesh(other.m_mesh), m_convex_hull(other.m_convex_hull),
config(other.config), m_type(other.m_type), object(object), m_transformation(other.m_transformation),
supported_facets(other.supported_facets), seam_facets(other.seam_facets), mmu_segmentation_facets(other.mmu_segmentation_facets)
supported_facets(other.supported_facets), seam_facets(other.seam_facets), mmu_segmentation_facets(other.mmu_segmentation_facets),
m_mmu_segmentation_expolygons(other.m_mmu_segmentation_expolygons)
{
assert(this->id().valid());
assert(this->config.id().valid());

View file

@ -892,6 +892,15 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
}
} else if (model_custom_seam_data_changed(model_object, model_object_new)) {
update_apply_status(this->invalidate_step(psGCodeExport));
} else if (!print_diff.empty() || model_mmu_segmentation_data_changed(model_object, model_object_new)) {
this->call_cancel_callback();
update_apply_status(false);
update_apply_status(this->invalidate_all_steps());
auto range = print_object_status.equal_range(PrintObjectStatus(model_object.id()));
for (auto it = range.first; it != range.second; ++ it)
update_apply_status(it->print_object->invalidate_all_steps());
// FIXME Lukas H.: Temporary solution to force update regions after change regions size or repainting.
model_volume_list_update_supports(model_object, model_object_new);
}
if (! model_parts_differ && ! modifiers_differ) {
// Synchronize Object's config.

View file

@ -240,6 +240,8 @@ public:
// Helpers to project custom facets on slices
void project_and_append_custom_facets(bool seam, EnforcerBlockerType type, std::vector<ExPolygons>& expolys) const;
// Returns MMU segmentation based on painting in MMU segmentation gizmo
std::vector<std::vector<std::pair<ExPolygon, size_t>>> mmu_segmentation_by_painting();
private:
// to be called from Print only.
friend class Print;

File diff suppressed because it is too large Load diff